Skip to content

Commit e22ae7a

Browse files
authored
Merge pull request #7469 from douzzer/20240424-fix-ports-whitespace
20240424-fix-ports-whitespace
2 parents 039fd26 + e862c85 commit e22ae7a

35 files changed

Lines changed: 437 additions & 434 deletions

wolfcrypt/src/port/Espressif/esp32_mp.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
* See ESP32 Technical Reference Manual - RSA Accelerator Chapter
2424
*
2525
* esp_mp_exptmod() Large Number Modular Exponentiation Z = X^Y mod M
26-
* esp_mp_mulmod() Large Number Modular Multiplication Z = X × Y mod M
27-
* esp_mp_mul() Large Number Multiplication Z = X × Y
26+
* esp_mp_mulmod() Large Number Modular Multiplication Z = X * Y mod M
27+
* esp_mp_mul() Large Number Multiplication Z = X * Y
2828
*
2929
* The ESP32 RSA Accelerator supports operand lengths of:
30-
* N {512, 1024, 1536, 2048, 2560, 3072, 3584, 4096} bits. The bit length
30+
* N in {512, 1024, 1536, 2048, 2560, 3072, 3584, 4096} bits. The bit length
3131
* of arguments Z, X, Y , M, and r can be any one from the N set, but all
3232
* numbers in a calculation must be of the same length.
3333
*
34-
* The bit length of M is always 32.
34+
* The bit length of M' is always 32.
3535
*
3636
* Also, beware: "we have uint32_t == unsigned long for both Xtensa and RISC-V"
3737
* see https://github.com/espressif/esp-idf/issues/9511#issuecomment-1207342464
@@ -1285,8 +1285,8 @@ int esp_mp_mul(MATH_INT_T* X, MATH_INT_T* Y, MATH_INT_T* Z)
12851285
Zs = Xs + Ys;
12861286

12871287
/* RSA Accelerator only supports Large Number Multiplication
1288-
* with operand length N = 32 × x,
1289-
* where x {1, 2, 3, . . . , 64} */
1288+
* with operand length N = 32 * x,
1289+
* where x in {1, 2, 3, . . . , 64} */
12901290
if (Xs > 64 || Ys > 64) {
12911291
return MP_HW_FALLBACK; /* TODO add count metric on size fallback */
12921292
}
@@ -1334,7 +1334,7 @@ int esp_mp_mul(MATH_INT_T* X, MATH_INT_T* Y, MATH_INT_T* Z)
13341334

13351335
/* Y (left-extend)
13361336
* Accelerator supports large-number multiplication with only
1337-
* four operand lengths of N {512, 1024, 1536, 2048} */
1337+
* four operand lengths of N in {512, 1024, 1536, 2048} */
13381338
left_pad_offset = maxWords_sz << 2;
13391339
if (left_pad_offset <= 512 >> 3) {
13401340
left_pad_offset = 512 >> 3; /* 64 bytes (16 words) */
@@ -1583,10 +1583,10 @@ int esp_mp_mul(MATH_INT_T* X, MATH_INT_T* Y, MATH_INT_T* Z)
15831583
* 0 => no interrupt; 1 => interrupt on completion. */
15841584
DPORT_REG_WRITE(RSA_INT_ENA_REG, 0);
15851585
/* 2. Write number of words required for result. */
1586-
/* see 21.3.3 Write (/N16 1) to the RSA_MODE_REG register */
1586+
/* see 21.3.3 Write (/N16 - 1) to the RSA_MODE_REG register */
15871587
DPORT_REG_WRITE(RSA_MODE_REG, (hwWords_sz * 2 - 1));
15881588

1589-
/* 3. Write Xi and Yi for {0, 1, . . . , n 1} to memory blocks
1589+
/* 3. Write Xi and Yi for {0, 1, . . . , n - 1} to memory blocks
15901590
* RSA_X_MEM and RSA_Z_MEM
15911591
* Maximum is 64 words (64*8*4 = 2048 bits) */
15921592
esp_mpint_to_memblock(RSA_X_MEM,
@@ -1796,7 +1796,7 @@ int esp_mp_mul(MATH_INT_T* X, MATH_INT_T* Y, MATH_INT_T* Z)
17961796
*
17971797
* See 24.3.3 of the ESP32 Technical Reference Manual
17981798
*
1799-
* Z = X × Y mod M */
1799+
* Z = X * Y mod M */
18001800
int esp_mp_mulmod(MATH_INT_T* X, MATH_INT_T* Y, MATH_INT_T* M, MATH_INT_T* Z)
18011801
{
18021802
struct esp_mp_helper mph[1]; /* we'll save some values in this mp helper */
@@ -1839,7 +1839,7 @@ int esp_mp_mulmod(MATH_INT_T* X, MATH_INT_T* Y, MATH_INT_T* M, MATH_INT_T* Z)
18391839
/* do we have an even moduli? */
18401840
if ((M->dp[0] & 1) == 0) {
18411841
#ifndef NO_ESP_MP_MUL_EVEN_ALT_CALC
1842-
/* Z = X × Y mod M in mixed HW & SW*/
1842+
/* Z = X * Y mod M in mixed HW & SW*/
18431843
ret = esp_mp_mul(X, Y, tmpZ); /* HW X * Y */
18441844
if (ret == MP_OKAY) {
18451845
/* z = tmpZ mod M, 0 <= Z < M */
@@ -1973,13 +1973,13 @@ int esp_mp_mulmod(MATH_INT_T* X, MATH_INT_T* Y, MATH_INT_T* M, MATH_INT_T* Z)
19731973
* or until the RSA_INTR interrupt is generated.
19741974
* (Or until the INTER interrupt is generated.)
19751975
* 6. Write 1 to RSA_INTERRUPT_REG to clear the interrupt.
1976-
* 7. Write Yi (i [0, n) N) to RSA_X_MEM
1976+
* 7. Write Yi (i in [0, n) intersect N) to RSA_X_MEM
19771977
* Users need to write to the memory block only according to the length
19781978
* of the number. Data beyond this length is ignored.
19791979
* 8. Write 1 to RSA_MULT_START_REG
19801980
* 9. Wait for the second operation to be completed.
19811981
* Poll INTERRUPT_REG until it reads 1.
1982-
* 10. Read the Zi (i [0, n) N) from RSA_Z_MEM
1982+
* 10. Read the Zi (i in [0, n) intersect N) from RSA_Z_MEM
19831983
* 11. Write 1 to RSA_INTERUPT_REG to clear the interrupt.
19841984
*
19851985
* post: Release the HW engine
@@ -2500,15 +2500,15 @@ int esp_mp_mulmod(MATH_INT_T* X, MATH_INT_T* Y, MATH_INT_T* M, MATH_INT_T* Z)
25002500
* ESP32S3, Section 20.3.1, https://www.espressif.com/sites/default/files/documentation/esp32-s3_technical_reference_manual_en.pdf
25012501
*
25022502
* The operation is based on Montgomery multiplication. Aside from the
2503-
* arguments X, Y , and M, two additional ones are needed r and M
2503+
* arguments X, Y , and M, two additional ones are needed -r and M'
25042504
.* These arguments are calculated in advance by software.
25052505
.*
2506-
.* The RSA Accelerator supports operand lengths of N {512, 1024, 1536, 2048,
2507-
.* 2560, 3072, 3584, 4096} bits on the ESP32 and N [32, 4096] bits
2506+
.* The RSA Accelerator supports operand lengths of N in {512, 1024, 1536, 2048,
2507+
.* 2560, 3072, 3584, 4096} bits on the ESP32 and N in [32, 4096] bits
25082508
* on the ESP32s3.
25092509
.* The bit length of arguments Z, X, Y , M, and r can be any one from
25102510
* the N set, but all numbers in a calculation must be of the same length.
2511-
.* The bit length of M is always 32.
2511+
.* The bit length of M' is always 32.
25122512
.*
25132513
* Z = (X ^ Y) mod M : Espressif generic notation
25142514
* Y = (G ^ X) mod P : wolfSSL DH reference notation */

wolfcrypt/src/port/Renesas/renesas_common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static int gdevId = 7890; /* initial dev Id for Crypt Callback */
5959
defined(WOLFSSL_RENESAS_FSPSM_CRYPTONLY)
6060
FSPSM_ST *gCbCtx[MAX_FSPSM_CBINDEX];
6161
#elif defined(WOLFSSL_RENESAS_TSIP_TLS) || \
62-
defined(WOLFSSL_RENESAS_TSIP_CRYPTONLY)
62+
defined(WOLFSSL_RENESAS_TSIP_CRYPTONLY)
6363
#define FSPSM_ST TsipUserCtx;
6464
#define MAX_FSPSM_CBINDEX 5
6565
TsipUserCtx *gCbCtx[MAX_FSPSM_CBINDEX];

wolfcrypt/src/port/Renesas/renesas_fspsm_aes.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ typedef fsp_err_t (*aesGcmDecFinalFn)
7272

7373
#if defined(WOLFSSL_RENESAS_RSIP)
7474
/* wrapper for Gcm encrypt init */
75-
static fsp_err_t _R_RSIP_AES_GCM_EncryptInit(FSPSM_AESGCM_HANDLE* h,
75+
static fsp_err_t _R_RSIP_AES_GCM_EncryptInit(FSPSM_AESGCM_HANDLE* h,
7676
FSPSM_AES_PWKEY k, uint8_t* iv,
7777
uint32_t iv_l)
7878
{
@@ -81,8 +81,8 @@ static fsp_err_t _R_RSIP_AES_GCM_EncryptInit(FSPSM_AESGCM_HANDLE* h,
8181
(uint8_t* const)iv, iv_l);
8282
}
8383
/* wrapper for Gcm encrypt update */
84-
static fsp_err_t _R_RSIP_AES_GCM_EncryptUpdate(FSPSM_AESGCM_HANDLE* h,
85-
uint8_t* p_plain, uint8_t* p_cipher, uint32_t plain_length,
84+
static fsp_err_t _R_RSIP_AES_GCM_EncryptUpdate(FSPSM_AESGCM_HANDLE* h,
85+
uint8_t* p_plain, uint8_t* p_cipher, uint32_t plain_length,
8686
uint8_t* p_add, uint32_t add_len)
8787
{
8888
(void) h;
@@ -93,8 +93,8 @@ static fsp_err_t _R_RSIP_AES_GCM_EncryptUpdate(FSPSM_AESGCM_HANDLE* h,
9393
(uint32_t const) add_len);
9494
}
9595
/* wrapper for Gcm encrypt final */
96-
static fsp_err_t _R_RSIP_AES_GCM_EncryptFinal(FSPSM_AESGCM_HANDLE* h,
97-
uint8_t* p_cipher, uint32_t* c_len,
96+
static fsp_err_t _R_RSIP_AES_GCM_EncryptFinal(FSPSM_AESGCM_HANDLE* h,
97+
uint8_t* p_cipher, uint32_t* c_len,
9898
uint8_t* p_atag)
9999
{
100100
(void) h;
@@ -103,16 +103,16 @@ static fsp_err_t _R_RSIP_AES_GCM_EncryptFinal(FSPSM_AESGCM_HANDLE* h,
103103
(uint8_t* const) p_atag);
104104
}
105105
/* wrapper for Gcm decrypt init */
106-
static fsp_err_t _R_RSIP_AES_GCM_DecryptInit(FSPSM_AESGCM_HANDLE* h,
106+
static fsp_err_t _R_RSIP_AES_GCM_DecryptInit(FSPSM_AESGCM_HANDLE* h,
107107
FSPSM_AES_PWKEY k, uint8_t* iv, uint32_t iv_l)
108108
{
109109
(void) h;
110110
return R_RSIP_AES_GCM_DecryptInit(&gFSPSM_ctrl, (FSPSM_AES_PWKEY const)k,
111111
(uint8_t* const)iv, iv_l);
112112
}
113113
/* wrapper for Gcm decrypt update */
114-
static fsp_err_t _R_RSIP_AES_GCM_DecryptUpdate(FSPSM_AESGCM_HANDLE* h,
115-
uint8_t* p_cipher, uint8_t* p_plain, uint32_t c_length,
114+
static fsp_err_t _R_RSIP_AES_GCM_DecryptUpdate(FSPSM_AESGCM_HANDLE* h,
115+
uint8_t* p_cipher, uint8_t* p_plain, uint32_t c_length,
116116
uint8_t* p_add, uint32_t add_len)
117117
{
118118
(void) h;
@@ -123,8 +123,8 @@ static fsp_err_t _R_RSIP_AES_GCM_DecryptUpdate(FSPSM_AESGCM_HANDLE* h,
123123
(uint32_t const) add_len);
124124
}
125125
/* wrapper for Gcm decrypt final */
126-
static fsp_err_t _R_RSIP_AES_GCM_DecryptFinal(FSPSM_AESGCM_HANDLE* h,
127-
uint8_t* p_plain, uint32_t* plain_len,
126+
static fsp_err_t _R_RSIP_AES_GCM_DecryptFinal(FSPSM_AESGCM_HANDLE* h,
127+
uint8_t* p_plain, uint32_t* plain_len,
128128
uint8_t* p_atag, uint32_t atag_len)
129129
{
130130
(void) h;
@@ -241,7 +241,7 @@ WOLFSSL_LOCAL int wc_fspsm_AesGcmEncrypt(struct Aes* aes, byte* out,
241241
FSPSM_AES_PWKEY key_client_aes = NULL;
242242
FSPSM_AES_PWKEY key_server_aes = NULL;
243243
(void) key_server_aes;
244-
244+
245245
/* sanity check */
246246
if (aes == NULL || authTagSz > AES_BLOCK_SIZE || ivSz == 0 || ctx == NULL) {
247247
return BAD_FUNC_ARG;
@@ -282,7 +282,7 @@ WOLFSSL_LOCAL int wc_fspsm_AesGcmEncrypt(struct Aes* aes, byte* out,
282282
aTagBuf = XMALLOC(SCE_AES_GCM_AUTH_TAG_SIZE, aes->heap,
283283
DYNAMIC_TYPE_AES);
284284

285-
if ((sz > 0 && plainBuf == NULL) ||
285+
if ((sz > 0 && plainBuf == NULL) ||
286286
((sz + delta) > 0 && cipherBuf == NULL) || aTagBuf == NULL) {
287287
WOLFSSL_MSG("wc_fspsm_AesGcmEncrypt: buffer allocation failed");
288288
ret = -1;
@@ -293,7 +293,7 @@ WOLFSSL_LOCAL int wc_fspsm_AesGcmEncrypt(struct Aes* aes, byte* out,
293293
XMEMSET((void*)cipherBuf, 0, sz + delta);
294294
XMEMSET((void*)authTag, 0, authTagSz);
295295
}
296-
296+
297297
#if defined(WOLFSSL_RENESAS_FSPSM_TLS)
298298
if (ret == 0 &&
299299
info->keyflgs_tls.bits.session_key_set == 1) {
@@ -310,7 +310,7 @@ WOLFSSL_LOCAL int wc_fspsm_AesGcmEncrypt(struct Aes* aes, byte* out,
310310
XFREE(aTagBuf, aes->heap, DYNAMIC_TYPE_AES);
311311
return MEMORY_E;
312312
}
313-
313+
314314
ret = FSPSM_SESSIONKEY_GEN_FUNC(
315315
info->cipher,
316316
(uint32_t*)info->masterSecret,
@@ -514,7 +514,7 @@ WOLFSSL_LOCAL int wc_fspsm_AesGcmDecrypt(struct Aes* aes, byte* out,
514514
XFREE(aTagBuf, aes->heap, DYNAMIC_TYPE_AES);
515515
return MEMORY_E;
516516
}
517-
517+
518518
ret = FSPSM_SESSIONKEY_GEN_FUNC(
519519
info->cipher,
520520
(uint32_t*)info->masterSecret,
@@ -547,7 +547,7 @@ WOLFSSL_LOCAL int wc_fspsm_AesGcmDecrypt(struct Aes* aes, byte* out,
547547
ret = -1;
548548
}
549549
}
550-
550+
551551
if (ret == 0) {
552552
/* since key_index has iv and ivSz in it, no need to pass them init
553553
* func. Pass NULL and 0 as 3rd and 4th parameter respectively.
@@ -769,7 +769,7 @@ WOLFSSL_LOCAL void wc_fspsm_Aesfree(Aes* aes)
769769
}
770770
#else
771771
if (aes->ctx.wrapped_key) {
772-
/* aes ctx just points user created wrapped key
772+
/* aes ctx just points user created wrapped key
773773
* in the case of CryptOnly Mode
774774
* therefore, it just sets pointing to NULL.
775775
* user key should be freed by owner(user)
@@ -785,8 +785,8 @@ int wc_AesSetKey(Aes* aes, const byte* userKey, word32 keylen,
785785
{
786786
(void) userKey;
787787
(void) dir;
788-
789-
if (aes == NULL || userKey == NULL ||
788+
789+
if (aes == NULL || userKey == NULL ||
790790
!((keylen == 16) || (keylen == 32))) {
791791
return BAD_FUNC_ARG;
792792
}
@@ -806,7 +806,7 @@ int wc_AesSetKey(Aes* aes, const byte* userKey, word32 keylen,
806806
aes->ctx.wrapped_key = (FSPSM_AES_PWKEY)userKey;
807807
aes->keylen = (int)keylen;
808808
aes->ctx.keySize = keylen;
809-
809+
810810
return wc_AesSetIV(aes, iv);
811811
}
812812
#endif

0 commit comments

Comments
 (0)