(mbedtls) Try to make more code C89-compliant
This commit is contained in:
parent
ecaa250aad
commit
15277f9dbc
|
@ -97,35 +97,35 @@ int mbedtls_aesni_crypt_ecb( mbedtls_aes_context *ctx,
|
|||
const unsigned char input[16],
|
||||
unsigned char output[16] )
|
||||
{
|
||||
asm( "movdqu (%3), %%xmm0 \n\t" // load input
|
||||
"movdqu (%1), %%xmm1 \n\t" // load round key 0
|
||||
"pxor %%xmm1, %%xmm0 \n\t" // round 0
|
||||
"add $16, %1 \n\t" // point to next round key
|
||||
"subl $1, %0 \n\t" // normal rounds = nr - 1
|
||||
"test %2, %2 \n\t" // mode?
|
||||
"jz 2f \n\t" // 0 = decrypt
|
||||
asm( "movdqu (%3), %%xmm0 \n\t" /* load input */
|
||||
"movdqu (%1), %%xmm1 \n\t" /* load round key 0 */
|
||||
"pxor %%xmm1, %%xmm0 \n\t" /* round 0 */
|
||||
"add $16, %1 \n\t" /* point to next round key */
|
||||
"subl $1, %0 \n\t" /* normal rounds = nr - 1 */
|
||||
"test %2, %2 \n\t" /* mode? */
|
||||
"jz 2f \n\t" /* 0 = decrypt */
|
||||
|
||||
"1: \n\t" // encryption loop
|
||||
"movdqu (%1), %%xmm1 \n\t" // load round key
|
||||
AESENC xmm1_xmm0 "\n\t" // do round
|
||||
"add $16, %1 \n\t" // point to next round key
|
||||
"subl $1, %0 \n\t" // loop
|
||||
"1: \n\t" /* encryption loop */
|
||||
"movdqu (%1), %%xmm1 \n\t" /* load round key */
|
||||
AESENC xmm1_xmm0 "\n\t" /* do round */
|
||||
"add $16, %1 \n\t" /* point to next round key */
|
||||
"subl $1, %0 \n\t" /* loop */
|
||||
"jnz 1b \n\t"
|
||||
"movdqu (%1), %%xmm1 \n\t" // load round key
|
||||
AESENCLAST xmm1_xmm0 "\n\t" // last round
|
||||
"movdqu (%1), %%xmm1 \n\t" /* load round key */
|
||||
AESENCLAST xmm1_xmm0 "\n\t" /* last round */
|
||||
"jmp 3f \n\t"
|
||||
|
||||
"2: \n\t" // decryption loop
|
||||
"2: \n\t" /* decryption loop */
|
||||
"movdqu (%1), %%xmm1 \n\t"
|
||||
AESDEC xmm1_xmm0 "\n\t" // do round
|
||||
AESDEC xmm1_xmm0 "\n\t" /* do round */
|
||||
"add $16, %1 \n\t"
|
||||
"subl $1, %0 \n\t"
|
||||
"jnz 2b \n\t"
|
||||
"movdqu (%1), %%xmm1 \n\t" // load round key
|
||||
AESDECLAST xmm1_xmm0 "\n\t" // last round
|
||||
"movdqu (%1), %%xmm1 \n\t" /* load round key */
|
||||
AESDECLAST xmm1_xmm0 "\n\t" /* last round */
|
||||
|
||||
"3: \n\t"
|
||||
"movdqu %%xmm0, (%4) \n\t" // export output
|
||||
"movdqu %%xmm0, (%4) \n\t" /* export output */
|
||||
:
|
||||
: "r" (ctx->nr), "r" (ctx->rk), "r" (mode), "r" (input), "r" (output)
|
||||
: "memory", "cc", "xmm0", "xmm1" );
|
||||
|
@ -152,44 +152,44 @@ void mbedtls_aesni_gcm_mult( unsigned char c[16],
|
|||
bb[i] = b[15 - i];
|
||||
}
|
||||
|
||||
asm( "movdqu (%0), %%xmm0 \n\t" // a1:a0
|
||||
"movdqu (%1), %%xmm1 \n\t" // b1:b0
|
||||
asm( "movdqu (%0), %%xmm0 \n\t" /* a1:a0 */
|
||||
"movdqu (%1), %%xmm1 \n\t" /* b1:b0 */
|
||||
|
||||
/*
|
||||
* Caryless multiplication xmm2:xmm1 = xmm0 * xmm1
|
||||
* using [CLMUL-WP] algorithm 1 (p. 13).
|
||||
*/
|
||||
"movdqa %%xmm1, %%xmm2 \n\t" // copy of b1:b0
|
||||
"movdqa %%xmm1, %%xmm3 \n\t" // same
|
||||
"movdqa %%xmm1, %%xmm4 \n\t" // same
|
||||
PCLMULQDQ xmm0_xmm1 ",0x00 \n\t" // a0*b0 = c1:c0
|
||||
PCLMULQDQ xmm0_xmm2 ",0x11 \n\t" // a1*b1 = d1:d0
|
||||
PCLMULQDQ xmm0_xmm3 ",0x10 \n\t" // a0*b1 = e1:e0
|
||||
PCLMULQDQ xmm0_xmm4 ",0x01 \n\t" // a1*b0 = f1:f0
|
||||
"pxor %%xmm3, %%xmm4 \n\t" // e1+f1:e0+f0
|
||||
"movdqa %%xmm4, %%xmm3 \n\t" // same
|
||||
"psrldq $8, %%xmm4 \n\t" // 0:e1+f1
|
||||
"pslldq $8, %%xmm3 \n\t" // e0+f0:0
|
||||
"pxor %%xmm4, %%xmm2 \n\t" // d1:d0+e1+f1
|
||||
"pxor %%xmm3, %%xmm1 \n\t" // c1+e0+f1:c0
|
||||
"movdqa %%xmm1, %%xmm2 \n\t" /* copy of b1:b0 */
|
||||
"movdqa %%xmm1, %%xmm3 \n\t" /* same */
|
||||
"movdqa %%xmm1, %%xmm4 \n\t" /* same */
|
||||
PCLMULQDQ xmm0_xmm1 ",0x00 \n\t" /* a0*b0 = c1:c0 */
|
||||
PCLMULQDQ xmm0_xmm2 ",0x11 \n\t" /* a1*b1 = d1:d0 */
|
||||
PCLMULQDQ xmm0_xmm3 ",0x10 \n\t" /* a0*b1 = e1:e0 */
|
||||
PCLMULQDQ xmm0_xmm4 ",0x01 \n\t" /* a1*b0 = f1:f0 */
|
||||
"pxor %%xmm3, %%xmm4 \n\t" /* e1+f1:e0+f0 */
|
||||
"movdqa %%xmm4, %%xmm3 \n\t" /* same */
|
||||
"psrldq $8, %%xmm4 \n\t" /* 0:e1+f1 */
|
||||
"pslldq $8, %%xmm3 \n\t" /* e0+f0:0 */
|
||||
"pxor %%xmm4, %%xmm2 \n\t" /* d1:d0+e1+f1 */
|
||||
"pxor %%xmm3, %%xmm1 \n\t" /* c1+e0+f1:c0 */
|
||||
|
||||
/*
|
||||
* Now shift the result one bit to the left,
|
||||
* taking advantage of [CLMUL-WP] eq 27 (p. 20)
|
||||
*/
|
||||
"movdqa %%xmm1, %%xmm3 \n\t" // r1:r0
|
||||
"movdqa %%xmm2, %%xmm4 \n\t" // r3:r2
|
||||
"psllq $1, %%xmm1 \n\t" // r1<<1:r0<<1
|
||||
"psllq $1, %%xmm2 \n\t" // r3<<1:r2<<1
|
||||
"psrlq $63, %%xmm3 \n\t" // r1>>63:r0>>63
|
||||
"psrlq $63, %%xmm4 \n\t" // r3>>63:r2>>63
|
||||
"movdqa %%xmm3, %%xmm5 \n\t" // r1>>63:r0>>63
|
||||
"pslldq $8, %%xmm3 \n\t" // r0>>63:0
|
||||
"pslldq $8, %%xmm4 \n\t" // r2>>63:0
|
||||
"psrldq $8, %%xmm5 \n\t" // 0:r1>>63
|
||||
"por %%xmm3, %%xmm1 \n\t" // r1<<1|r0>>63:r0<<1
|
||||
"por %%xmm4, %%xmm2 \n\t" // r3<<1|r2>>62:r2<<1
|
||||
"por %%xmm5, %%xmm2 \n\t" // r3<<1|r2>>62:r2<<1|r1>>63
|
||||
"movdqa %%xmm1, %%xmm3 \n\t" /* r1:r0 */
|
||||
"movdqa %%xmm2, %%xmm4 \n\t" /* r3:r2 */
|
||||
"psllq $1, %%xmm1 \n\t" /* r1<<1:r0<<1 */
|
||||
"psllq $1, %%xmm2 \n\t" /* r3<<1:r2<<1 */
|
||||
"psrlq $63, %%xmm3 \n\t" /* r1>>63:r0>>63 */
|
||||
"psrlq $63, %%xmm4 \n\t" /* r3>>63:r2>>63 */
|
||||
"movdqa %%xmm3, %%xmm5 \n\t" /* r1>>63:r0>>63 */
|
||||
"pslldq $8, %%xmm3 \n\t" /* r0>>63:0 */
|
||||
"pslldq $8, %%xmm4 \n\t" /* r2>>63:0 */
|
||||
"psrldq $8, %%xmm5 \n\t" /* 0:r1>>63 */
|
||||
"por %%xmm3, %%xmm1 \n\t" /* r1<<1|r0>>63:r0<<1 */
|
||||
"por %%xmm4, %%xmm2 \n\t" /* r3<<1|r2>>62:r2<<1 */
|
||||
"por %%xmm5, %%xmm2 \n\t" /* r3<<1|r2>>62:r2<<1|r1>>63 */
|
||||
|
||||
/*
|
||||
* Now reduce modulo the GCM polynomial x^128 + x^7 + x^2 + x + 1
|
||||
|
@ -197,44 +197,44 @@ void mbedtls_aesni_gcm_mult( unsigned char c[16],
|
|||
* Currently xmm2:xmm1 holds x3:x2:x1:x0 (already shifted).
|
||||
*/
|
||||
/* Step 2 (1) */
|
||||
"movdqa %%xmm1, %%xmm3 \n\t" // x1:x0
|
||||
"movdqa %%xmm1, %%xmm4 \n\t" // same
|
||||
"movdqa %%xmm1, %%xmm5 \n\t" // same
|
||||
"psllq $63, %%xmm3 \n\t" // x1<<63:x0<<63 = stuff:a
|
||||
"psllq $62, %%xmm4 \n\t" // x1<<62:x0<<62 = stuff:b
|
||||
"psllq $57, %%xmm5 \n\t" // x1<<57:x0<<57 = stuff:c
|
||||
"movdqa %%xmm1, %%xmm3 \n\t" /* x1:x0 */
|
||||
"movdqa %%xmm1, %%xmm4 \n\t" /* same */
|
||||
"movdqa %%xmm1, %%xmm5 \n\t" /* same */
|
||||
"psllq $63, %%xmm3 \n\t" /* x1<<63:x0<<63 = stuff:a */
|
||||
"psllq $62, %%xmm4 \n\t" /* x1<<62:x0<<62 = stuff:b */
|
||||
"psllq $57, %%xmm5 \n\t" /* x1<<57:x0<<57 = stuff:c */
|
||||
|
||||
/* Step 2 (2) */
|
||||
"pxor %%xmm4, %%xmm3 \n\t" // stuff:a+b
|
||||
"pxor %%xmm5, %%xmm3 \n\t" // stuff:a+b+c
|
||||
"pslldq $8, %%xmm3 \n\t" // a+b+c:0
|
||||
"pxor %%xmm3, %%xmm1 \n\t" // x1+a+b+c:x0 = d:x0
|
||||
"pxor %%xmm4, %%xmm3 \n\t" /* stuff:a+b */
|
||||
"pxor %%xmm5, %%xmm3 \n\t" /* stuff:a+b+c */
|
||||
"pslldq $8, %%xmm3 \n\t" /* a+b+c:0 */
|
||||
"pxor %%xmm3, %%xmm1 \n\t" /* x1+a+b+c:x0 = d:x0 */
|
||||
|
||||
/* Steps 3 and 4 */
|
||||
"movdqa %%xmm1,%%xmm0 \n\t" // d:x0
|
||||
"movdqa %%xmm1,%%xmm4 \n\t" // same
|
||||
"movdqa %%xmm1,%%xmm5 \n\t" // same
|
||||
"psrlq $1, %%xmm0 \n\t" // e1:x0>>1 = e1:e0'
|
||||
"psrlq $2, %%xmm4 \n\t" // f1:x0>>2 = f1:f0'
|
||||
"psrlq $7, %%xmm5 \n\t" // g1:x0>>7 = g1:g0'
|
||||
"pxor %%xmm4, %%xmm0 \n\t" // e1+f1:e0'+f0'
|
||||
"pxor %%xmm5, %%xmm0 \n\t" // e1+f1+g1:e0'+f0'+g0'
|
||||
// e0'+f0'+g0' is almost e0+f0+g0, ex\tcept for some missing
|
||||
// bits carried from d. Now get those\t bits back in.
|
||||
"movdqa %%xmm1,%%xmm3 \n\t" // d:x0
|
||||
"movdqa %%xmm1,%%xmm4 \n\t" // same
|
||||
"movdqa %%xmm1,%%xmm5 \n\t" // same
|
||||
"psllq $63, %%xmm3 \n\t" // d<<63:stuff
|
||||
"psllq $62, %%xmm4 \n\t" // d<<62:stuff
|
||||
"psllq $57, %%xmm5 \n\t" // d<<57:stuff
|
||||
"pxor %%xmm4, %%xmm3 \n\t" // d<<63+d<<62:stuff
|
||||
"pxor %%xmm5, %%xmm3 \n\t" // missing bits of d:stuff
|
||||
"psrldq $8, %%xmm3 \n\t" // 0:missing bits of d
|
||||
"pxor %%xmm3, %%xmm0 \n\t" // e1+f1+g1:e0+f0+g0
|
||||
"pxor %%xmm1, %%xmm0 \n\t" // h1:h0
|
||||
"pxor %%xmm2, %%xmm0 \n\t" // x3+h1:x2+h0
|
||||
"movdqa %%xmm1,%%xmm0 \n\t" /* d:x0 */
|
||||
"movdqa %%xmm1,%%xmm4 \n\t" /* same */
|
||||
"movdqa %%xmm1,%%xmm5 \n\t" /* same */
|
||||
"psrlq $1, %%xmm0 \n\t" /* e1:x0>>1 = e1:e0' */
|
||||
"psrlq $2, %%xmm4 \n\t" /* f1:x0>>2 = f1:f0' */
|
||||
"psrlq $7, %%xmm5 \n\t" /* g1:x0>>7 = g1:g0' */
|
||||
"pxor %%xmm4, %%xmm0 \n\t" /* e1+f1:e0'+f0' */
|
||||
"pxor %%xmm5, %%xmm0 \n\t" /* e1+f1+g1:e0'+f0'+g0' */
|
||||
/* e0'+f0'+g0' is almost e0+f0+g0, ex\tcept for some missing
|
||||
* bits carried from d. Now get those\t bits back in. */
|
||||
"movdqa %%xmm1,%%xmm3 \n\t" /* d:x0 */
|
||||
"movdqa %%xmm1,%%xmm4 \n\t" /* same */
|
||||
"movdqa %%xmm1,%%xmm5 \n\t" /* same */
|
||||
"psllq $63, %%xmm3 \n\t" /* d<<63:stuff */
|
||||
"psllq $62, %%xmm4 \n\t" /* d<<62:stuff */
|
||||
"psllq $57, %%xmm5 \n\t" /* d<<57:stuff */
|
||||
"pxor %%xmm4, %%xmm3 \n\t" /* d<<63+d<<62:stuff */
|
||||
"pxor %%xmm5, %%xmm3 \n\t" /* missing bits of d:stuff */
|
||||
"psrldq $8, %%xmm3 \n\t" /* 0:missing bits of d */
|
||||
"pxor %%xmm3, %%xmm0 \n\t" /* e1+f1+g1:e0+f0+g0 */
|
||||
"pxor %%xmm1, %%xmm0 \n\t" /* h1:h0 */
|
||||
"pxor %%xmm2, %%xmm0 \n\t" /* x3+h1:x2+h0 */
|
||||
|
||||
"movdqu %%xmm0, (%2) \n\t" // done
|
||||
"movdqu %%xmm0, (%2) \n\t" /* done */
|
||||
:
|
||||
: "r" (aa), "r" (bb), "r" (cc)
|
||||
: "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5" );
|
||||
|
@ -274,9 +274,9 @@ void mbedtls_aesni_inverse_key( unsigned char *invkey,
|
|||
static void aesni_setkey_enc_128( unsigned char *rk,
|
||||
const unsigned char *key )
|
||||
{
|
||||
asm( "movdqu (%1), %%xmm0 \n\t" // copy the original key
|
||||
"movdqu %%xmm0, (%0) \n\t" // as round key 0
|
||||
"jmp 2f \n\t" // skip auxiliary routine
|
||||
asm( "movdqu (%1), %%xmm0 \n\t" /* copy the original key */
|
||||
"movdqu %%xmm0, (%0) \n\t" /* as round key 0 */
|
||||
"jmp 2f \n\t" /* skip auxiliary routine */
|
||||
|
||||
/*
|
||||
* Finish generating the next round key.
|
||||
|
@ -289,16 +289,16 @@ static void aesni_setkey_enc_128( unsigned char *rk,
|
|||
* and those are written to the round key buffer.
|
||||
*/
|
||||
"1: \n\t"
|
||||
"pshufd $0xff, %%xmm1, %%xmm1 \n\t" // X:X:X:X
|
||||
"pxor %%xmm0, %%xmm1 \n\t" // X+r3:X+r2:X+r1:r4
|
||||
"pslldq $4, %%xmm0 \n\t" // r2:r1:r0:0
|
||||
"pxor %%xmm0, %%xmm1 \n\t" // X+r3+r2:X+r2+r1:r5:r4
|
||||
"pslldq $4, %%xmm0 \n\t" // etc
|
||||
"pshufd $0xff, %%xmm1, %%xmm1 \n\t" /* X:X:X:X */
|
||||
"pxor %%xmm0, %%xmm1 \n\t" /* X+r3:X+r2:X+r1:r4 */
|
||||
"pslldq $4, %%xmm0 \n\t" /* r2:r1:r0:0 */
|
||||
"pxor %%xmm0, %%xmm1 \n\t" /* X+r3+r2:X+r2+r1:r5:r4 */
|
||||
"pslldq $4, %%xmm0 \n\t" /* etc */
|
||||
"pxor %%xmm0, %%xmm1 \n\t"
|
||||
"pslldq $4, %%xmm0 \n\t"
|
||||
"pxor %%xmm1, %%xmm0 \n\t" // update xmm0 for next time!
|
||||
"add $16, %0 \n\t" // point to next round key
|
||||
"movdqu %%xmm0, (%0) \n\t" // write it
|
||||
"pxor %%xmm1, %%xmm0 \n\t" /* update xmm0 for next time! */
|
||||
"add $16, %0 \n\t" /* point to next round key */
|
||||
"movdqu %%xmm0, (%0) \n\t" /* write it */
|
||||
"ret \n\t"
|
||||
|
||||
/* Main "loop" */
|
||||
|
@ -324,13 +324,13 @@ static void aesni_setkey_enc_128( unsigned char *rk,
|
|||
static void aesni_setkey_enc_192( unsigned char *rk,
|
||||
const unsigned char *key )
|
||||
{
|
||||
asm( "movdqu (%1), %%xmm0 \n\t" // copy original round key
|
||||
asm( "movdqu (%1), %%xmm0 \n\t" /* copy original round key */
|
||||
"movdqu %%xmm0, (%0) \n\t"
|
||||
"add $16, %0 \n\t"
|
||||
"movq 16(%1), %%xmm1 \n\t"
|
||||
"movq %%xmm1, (%0) \n\t"
|
||||
"add $8, %0 \n\t"
|
||||
"jmp 2f \n\t" // skip auxiliary routine
|
||||
"jmp 2f \n\t" /* skip auxiliary routine */
|
||||
|
||||
/*
|
||||
* Finish generating the next 6 quarter-keys.
|
||||
|
@ -342,20 +342,20 @@ static void aesni_setkey_enc_192( unsigned char *rk,
|
|||
* and those are written to the round key buffer.
|
||||
*/
|
||||
"1: \n\t"
|
||||
"pshufd $0x55, %%xmm2, %%xmm2 \n\t" // X:X:X:X
|
||||
"pxor %%xmm0, %%xmm2 \n\t" // X+r3:X+r2:X+r1:r4
|
||||
"pslldq $4, %%xmm0 \n\t" // etc
|
||||
"pshufd $0x55, %%xmm2, %%xmm2 \n\t" /* X:X:X:X */
|
||||
"pxor %%xmm0, %%xmm2 \n\t" /* X+r3:X+r2:X+r1:r4q */
|
||||
"pslldq $4, %%xmm0 \n\t" /* etc */
|
||||
"pxor %%xmm0, %%xmm2 \n\t"
|
||||
"pslldq $4, %%xmm0 \n\t"
|
||||
"pxor %%xmm0, %%xmm2 \n\t"
|
||||
"pslldq $4, %%xmm0 \n\t"
|
||||
"pxor %%xmm2, %%xmm0 \n\t" // update xmm0 = r9:r8:r7:r6
|
||||
"pxor %%xmm2, %%xmm0 \n\t" /* update xmm0 = r9:r8:r7:r6 */
|
||||
"movdqu %%xmm0, (%0) \n\t"
|
||||
"add $16, %0 \n\t"
|
||||
"pshufd $0xff, %%xmm0, %%xmm2 \n\t" // r9:r9:r9:r9
|
||||
"pxor %%xmm1, %%xmm2 \n\t" // stuff:stuff:r9+r5:r10
|
||||
"pslldq $4, %%xmm1 \n\t" // r2:r1:r0:0
|
||||
"pxor %%xmm2, %%xmm1 \n\t" // xmm1 = stuff:stuff:r11:r10
|
||||
"pshufd $0xff, %%xmm0, %%xmm2 \n\t" /* r9:r9:r9:r9 */
|
||||
"pxor %%xmm1, %%xmm2 \n\t" /* stuff:stuff:r9+r5:r10 */
|
||||
"pslldq $4, %%xmm1 \n\t" /* r2:r1:r0:0 */
|
||||
"pxor %%xmm2, %%xmm1 \n\t" /* xmm1 = stuff:stuff:r11:r10 */
|
||||
"movq %%xmm1, (%0) \n\t"
|
||||
"add $8, %0 \n\t"
|
||||
"ret \n\t"
|
||||
|
@ -386,7 +386,7 @@ static void aesni_setkey_enc_256( unsigned char *rk,
|
|||
"add $16, %0 \n\t"
|
||||
"movdqu 16(%1), %%xmm1 \n\t"
|
||||
"movdqu %%xmm1, (%0) \n\t"
|
||||
"jmp 2f \n\t" // skip auxiliary routine
|
||||
"jmp 2f \n\t" /* skip auxiliary routine */
|
||||
|
||||
/*
|
||||
* Finish generating the next two round keys.
|
||||
|
|
|
@ -130,8 +130,7 @@ int mbedtls_asn1_write_mpi( unsigned char **p, unsigned char *start, const mbedt
|
|||
int ret;
|
||||
size_t len = 0;
|
||||
|
||||
// Write the MPI
|
||||
//
|
||||
/* Write the MPI */
|
||||
len = mbedtls_mpi_size( X );
|
||||
|
||||
if( *p < start || (size_t)( *p - start ) < len )
|
||||
|
@ -140,9 +139,9 @@ int mbedtls_asn1_write_mpi( unsigned char **p, unsigned char *start, const mbedt
|
|||
(*p) -= len;
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_write_binary( X, *p, len ) );
|
||||
|
||||
// DER format assumes 2s complement for numbers, so the leftmost bit
|
||||
// should be 0 for positive numbers and 1 for negative numbers.
|
||||
//
|
||||
/* DER format assumes 2s complement for numbers, so the leftmost bit
|
||||
* should be 0 for positive numbers and 1 for negative numbers.
|
||||
*/
|
||||
if( X->s ==1 && **p & 0x80 )
|
||||
{
|
||||
if( *p - start < 1 )
|
||||
|
@ -167,8 +166,7 @@ int mbedtls_asn1_write_null( unsigned char **p, unsigned char *start )
|
|||
int ret;
|
||||
size_t len = 0;
|
||||
|
||||
// Write NULL
|
||||
//
|
||||
/* Write NULL */
|
||||
MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( p, start, 0) );
|
||||
MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( p, start, MBEDTLS_ASN1_NULL ) );
|
||||
|
||||
|
@ -232,10 +230,10 @@ int mbedtls_asn1_write_int( unsigned char **p, unsigned char *start, int val )
|
|||
int ret;
|
||||
size_t len = 0;
|
||||
|
||||
// TODO negative values and values larger than 128
|
||||
// DER format assumes 2s complement for numbers, so the leftmost bit
|
||||
// should be 0 for positive numbers and 1 for negative numbers.
|
||||
//
|
||||
/* TODO negative values and values larger than 128
|
||||
* DER format assumes 2s complement for numbers, so the leftmost bit
|
||||
* should be 0 for positive numbers and 1 for negative numbers.
|
||||
*/
|
||||
if( *p - start < 1 )
|
||||
return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL );
|
||||
|
||||
|
@ -295,8 +293,7 @@ int mbedtls_asn1_write_bitstring( unsigned char **p, unsigned char *start,
|
|||
|
||||
size = ( bits / 8 ) + ( ( bits % 8 ) ? 1 : 0 );
|
||||
|
||||
// Calculate byte length
|
||||
//
|
||||
/* Calculate byte length */
|
||||
if( *p < start || (size_t)( *p - start ) < size + 1 )
|
||||
return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL );
|
||||
|
||||
|
@ -304,8 +301,7 @@ int mbedtls_asn1_write_bitstring( unsigned char **p, unsigned char *start,
|
|||
(*p) -= size;
|
||||
memcpy( *p, buf, size );
|
||||
|
||||
// Write unused bits
|
||||
//
|
||||
/* Write unused bits */
|
||||
*--(*p) = (unsigned char) (size * 8 - bits);
|
||||
|
||||
MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( p, start, len ) );
|
||||
|
@ -337,8 +333,7 @@ mbedtls_asn1_named_data *mbedtls_asn1_store_named_data( mbedtls_asn1_named_data
|
|||
|
||||
if( ( cur = mbedtls_asn1_find_named_data( *head, oid, oid_len ) ) == NULL )
|
||||
{
|
||||
// Add new entry if not present yet based on OID
|
||||
//
|
||||
/* Add new entry if not present yet based on OID */
|
||||
cur = (mbedtls_asn1_named_data*)mbedtls_calloc( 1,
|
||||
sizeof(mbedtls_asn1_named_data) );
|
||||
if( cur == NULL )
|
||||
|
|
|
@ -43,11 +43,6 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
|
||||
!defined(inline) && !defined(__cplusplus)
|
||||
#define inline __inline
|
||||
#endif
|
||||
|
||||
#define DEBUG_BUF_SIZE 512
|
||||
|
||||
static int debug_threshold = 0;
|
||||
|
@ -60,7 +55,7 @@ void mbedtls_debug_set_threshold( int threshold )
|
|||
/*
|
||||
* All calls to f_dbg must be made via this function
|
||||
*/
|
||||
static inline void debug_send_line( const mbedtls_ssl_context *ssl, int level,
|
||||
static void debug_send_line( const mbedtls_ssl_context *ssl, int level,
|
||||
const char *file, int line,
|
||||
const char *str )
|
||||
{
|
||||
|
|
|
@ -107,7 +107,7 @@ typedef enum
|
|||
{
|
||||
ECP_TYPE_NONE = 0,
|
||||
ECP_TYPE_SHORT_WEIERSTRASS, /* y^2 = x^3 + a x + b */
|
||||
ECP_TYPE_MONTGOMERY, /* y^2 = x^3 + a x^2 + x */
|
||||
ECP_TYPE_MONTGOMERY /* y^2 = x^3 + a x^2 + x */
|
||||
} ecp_curve_type;
|
||||
|
||||
/*
|
||||
|
@ -256,15 +256,14 @@ const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_name( const char *name
|
|||
/*
|
||||
* Get the type of a curve
|
||||
*/
|
||||
static inline ecp_curve_type ecp_get_type( const mbedtls_ecp_group *grp )
|
||||
static ecp_curve_type ecp_get_type( const mbedtls_ecp_group *grp )
|
||||
{
|
||||
if( grp->G.X.p == NULL )
|
||||
return( ECP_TYPE_NONE );
|
||||
|
||||
if( grp->G.Y.p == NULL )
|
||||
return( ECP_TYPE_MONTGOMERY );
|
||||
else
|
||||
return( ECP_TYPE_SHORT_WEIERSTRASS );
|
||||
return( ECP_TYPE_SHORT_WEIERSTRASS );
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -33,11 +33,6 @@
|
|||
|
||||
#if !defined(MBEDTLS_ECP_ALT)
|
||||
|
||||
#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
|
||||
!defined(inline) && !defined(__cplusplus)
|
||||
#define inline __inline
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Conversion macros for embedded constants:
|
||||
* build lists of mbedtls_mpi_uint's from lists of unsigned char's grouped by 8, 4 or 2
|
||||
|
@ -553,7 +548,7 @@ static const mbedtls_mpi_uint brainpoolP512r1_n[] = {
|
|||
* Create an MPI from embedded constants
|
||||
* (assumes len is an exact multiple of sizeof mbedtls_mpi_uint)
|
||||
*/
|
||||
static inline void ecp_mpi_load( mbedtls_mpi *X, const mbedtls_mpi_uint *p, size_t len )
|
||||
static void ecp_mpi_load( mbedtls_mpi *X, const mbedtls_mpi_uint *p, size_t len )
|
||||
{
|
||||
X->s = 1;
|
||||
X->n = len / sizeof( mbedtls_mpi_uint );
|
||||
|
@ -563,7 +558,7 @@ static inline void ecp_mpi_load( mbedtls_mpi *X, const mbedtls_mpi_uint *p, size
|
|||
/*
|
||||
* Set an MPI to static value 1
|
||||
*/
|
||||
static inline void ecp_mpi_set1( mbedtls_mpi *X )
|
||||
static void ecp_mpi_set1( mbedtls_mpi *X )
|
||||
{
|
||||
static mbedtls_mpi_uint one[] = { 1 };
|
||||
X->s = 1;
|
||||
|
@ -798,7 +793,7 @@ int mbedtls_ecp_group_load( mbedtls_ecp_group *grp, mbedtls_ecp_group_id id )
|
|||
*/
|
||||
|
||||
/* Add 64-bit chunks (dst += src) and update carry */
|
||||
static inline void add64( mbedtls_mpi_uint *dst, mbedtls_mpi_uint *src, mbedtls_mpi_uint *carry )
|
||||
static void add64( mbedtls_mpi_uint *dst, mbedtls_mpi_uint *src, mbedtls_mpi_uint *carry )
|
||||
{
|
||||
unsigned char i;
|
||||
mbedtls_mpi_uint c = 0;
|
||||
|
@ -811,7 +806,7 @@ static inline void add64( mbedtls_mpi_uint *dst, mbedtls_mpi_uint *src, mbedtls_
|
|||
}
|
||||
|
||||
/* Add carry to a 64-bit chunk and update carry */
|
||||
static inline void carry64( mbedtls_mpi_uint *dst, mbedtls_mpi_uint *carry )
|
||||
static void carry64( mbedtls_mpi_uint *dst, mbedtls_mpi_uint *carry )
|
||||
{
|
||||
unsigned char i;
|
||||
for( i = 0; i < 8 / sizeof( mbedtls_mpi_uint ); i++, dst++ )
|
||||
|
@ -842,9 +837,9 @@ static int ecp_mod_p192( mbedtls_mpi *N )
|
|||
p = N->p;
|
||||
end = p + N->n;
|
||||
|
||||
ADD( 3 ); ADD( 5 ); NEXT; // A0 += A3 + A5
|
||||
ADD( 3 ); ADD( 4 ); ADD( 5 ); NEXT; // A1 += A3 + A4 + A5
|
||||
ADD( 4 ); ADD( 5 ); LAST; // A2 += A4 + A5
|
||||
ADD( 3 ); ADD( 5 ); NEXT; /* A0 += A3 + A5 */
|
||||
ADD( 3 ); ADD( 4 ); ADD( 5 ); NEXT; /* A1 += A3 + A4 + A5 */
|
||||
ADD( 4 ); ADD( 5 ); LAST; /* A2 += A4 + A5 */
|
||||
|
||||
cleanup:
|
||||
return( ret );
|
||||
|
@ -902,13 +897,13 @@ cleanup:
|
|||
/*
|
||||
* Helpers for addition and subtraction of chunks, with signed carry.
|
||||
*/
|
||||
static inline void add32( uint32_t *dst, uint32_t src, signed char *carry )
|
||||
static void add32( uint32_t *dst, uint32_t src, signed char *carry )
|
||||
{
|
||||
*dst += src;
|
||||
*carry += ( *dst < src );
|
||||
}
|
||||
|
||||
static inline void sub32( uint32_t *dst, uint32_t src, signed char *carry )
|
||||
static void sub32( uint32_t *dst, uint32_t src, signed char *carry )
|
||||
{
|
||||
*carry -= ( *dst < src );
|
||||
*dst -= src;
|
||||
|
@ -955,7 +950,7 @@ static inline void sub32( uint32_t *dst, uint32_t src, signed char *carry )
|
|||
* If the result is negative, we get it in the form
|
||||
* c * 2^(bits + 32) + N, with c negative and N positive shorter than 'bits'
|
||||
*/
|
||||
static inline int fix_negative( mbedtls_mpi *N, signed char c, mbedtls_mpi *C, size_t bits )
|
||||
static int fix_negative( mbedtls_mpi *N, signed char c, mbedtls_mpi *C, size_t bits )
|
||||
{
|
||||
int ret;
|
||||
|
||||
|
@ -986,13 +981,13 @@ static int ecp_mod_p224( mbedtls_mpi *N )
|
|||
{
|
||||
INIT( 224 );
|
||||
|
||||
SUB( 7 ); SUB( 11 ); NEXT; // A0 += -A7 - A11
|
||||
SUB( 8 ); SUB( 12 ); NEXT; // A1 += -A8 - A12
|
||||
SUB( 9 ); SUB( 13 ); NEXT; // A2 += -A9 - A13
|
||||
SUB( 10 ); ADD( 7 ); ADD( 11 ); NEXT; // A3 += -A10 + A7 + A11
|
||||
SUB( 11 ); ADD( 8 ); ADD( 12 ); NEXT; // A4 += -A11 + A8 + A12
|
||||
SUB( 12 ); ADD( 9 ); ADD( 13 ); NEXT; // A5 += -A12 + A9 + A13
|
||||
SUB( 13 ); ADD( 10 ); LAST; // A6 += -A13 + A10
|
||||
SUB( 7 ); SUB( 11 ); NEXT; /* A0 += -A7 - A11 */
|
||||
SUB( 8 ); SUB( 12 ); NEXT; /* A1 += -A8 - A12 */
|
||||
SUB( 9 ); SUB( 13 ); NEXT; /* A2 += -A9 - A13 */
|
||||
SUB( 10 ); ADD( 7 ); ADD( 11 ); NEXT; /* A3 += -A10 + A7 + A11 */
|
||||
SUB( 11 ); ADD( 8 ); ADD( 12 ); NEXT; /* A4 += -A11 + A8 + A12 */
|
||||
SUB( 12 ); ADD( 9 ); ADD( 13 ); NEXT; /* A5 += -A12 + A9 + A13 */
|
||||
SUB( 13 ); ADD( 10 ); LAST; /* A6 += -A13 + A10 */
|
||||
|
||||
cleanup:
|
||||
return( ret );
|
||||
|
@ -1008,28 +1003,28 @@ static int ecp_mod_p256( mbedtls_mpi *N )
|
|||
INIT( 256 );
|
||||
|
||||
ADD( 8 ); ADD( 9 );
|
||||
SUB( 11 ); SUB( 12 ); SUB( 13 ); SUB( 14 ); NEXT; // A0
|
||||
SUB( 11 ); SUB( 12 ); SUB( 13 ); SUB( 14 ); NEXT; /* A0 */
|
||||
|
||||
ADD( 9 ); ADD( 10 );
|
||||
SUB( 12 ); SUB( 13 ); SUB( 14 ); SUB( 15 ); NEXT; // A1
|
||||
SUB( 12 ); SUB( 13 ); SUB( 14 ); SUB( 15 ); NEXT; /* A1 */
|
||||
|
||||
ADD( 10 ); ADD( 11 );
|
||||
SUB( 13 ); SUB( 14 ); SUB( 15 ); NEXT; // A2
|
||||
SUB( 13 ); SUB( 14 ); SUB( 15 ); NEXT; /* A2 */
|
||||
|
||||
ADD( 11 ); ADD( 11 ); ADD( 12 ); ADD( 12 ); ADD( 13 );
|
||||
SUB( 15 ); SUB( 8 ); SUB( 9 ); NEXT; // A3
|
||||
SUB( 15 ); SUB( 8 ); SUB( 9 ); NEXT; /* A3 */
|
||||
|
||||
ADD( 12 ); ADD( 12 ); ADD( 13 ); ADD( 13 ); ADD( 14 );
|
||||
SUB( 9 ); SUB( 10 ); NEXT; // A4
|
||||
SUB( 9 ); SUB( 10 ); NEXT; /* A4 */
|
||||
|
||||
ADD( 13 ); ADD( 13 ); ADD( 14 ); ADD( 14 ); ADD( 15 );
|
||||
SUB( 10 ); SUB( 11 ); NEXT; // A5
|
||||
SUB( 10 ); SUB( 11 ); NEXT; /* A5 */
|
||||
|
||||
ADD( 14 ); ADD( 14 ); ADD( 15 ); ADD( 15 ); ADD( 14 ); ADD( 13 );
|
||||
SUB( 8 ); SUB( 9 ); NEXT; // A6
|
||||
SUB( 8 ); SUB( 9 ); NEXT; /* A6 */
|
||||
|
||||
ADD( 15 ); ADD( 15 ); ADD( 15 ); ADD( 8 );
|
||||
SUB( 10 ); SUB( 11 ); SUB( 12 ); SUB( 13 ); LAST; // A7
|
||||
SUB( 10 ); SUB( 11 ); SUB( 12 ); SUB( 13 ); LAST; /* A7 */
|
||||
|
||||
cleanup:
|
||||
return( ret );
|
||||
|
@ -1045,40 +1040,40 @@ static int ecp_mod_p384( mbedtls_mpi *N )
|
|||
INIT( 384 );
|
||||
|
||||
ADD( 12 ); ADD( 21 ); ADD( 20 );
|
||||
SUB( 23 ); NEXT; // A0
|
||||
SUB( 23 ); NEXT; /* A0 */
|
||||
|
||||
ADD( 13 ); ADD( 22 ); ADD( 23 );
|
||||
SUB( 12 ); SUB( 20 ); NEXT; // A2
|
||||
SUB( 12 ); SUB( 20 ); NEXT; /* A2 */
|
||||
|
||||
ADD( 14 ); ADD( 23 );
|
||||
SUB( 13 ); SUB( 21 ); NEXT; // A2
|
||||
SUB( 13 ); SUB( 21 ); NEXT; /* A2 */
|
||||
|
||||
ADD( 15 ); ADD( 12 ); ADD( 20 ); ADD( 21 );
|
||||
SUB( 14 ); SUB( 22 ); SUB( 23 ); NEXT; // A3
|
||||
SUB( 14 ); SUB( 22 ); SUB( 23 ); NEXT; /* A3 */
|
||||
|
||||
ADD( 21 ); ADD( 21 ); ADD( 16 ); ADD( 13 ); ADD( 12 ); ADD( 20 ); ADD( 22 );
|
||||
SUB( 15 ); SUB( 23 ); SUB( 23 ); NEXT; // A4
|
||||
SUB( 15 ); SUB( 23 ); SUB( 23 ); NEXT; /* A4 */
|
||||
|
||||
ADD( 22 ); ADD( 22 ); ADD( 17 ); ADD( 14 ); ADD( 13 ); ADD( 21 ); ADD( 23 );
|
||||
SUB( 16 ); NEXT; // A5
|
||||
SUB( 16 ); NEXT; /* A5 */
|
||||
|
||||
ADD( 23 ); ADD( 23 ); ADD( 18 ); ADD( 15 ); ADD( 14 ); ADD( 22 );
|
||||
SUB( 17 ); NEXT; // A6
|
||||
SUB( 17 ); NEXT; /* A6 */
|
||||
|
||||
ADD( 19 ); ADD( 16 ); ADD( 15 ); ADD( 23 );
|
||||
SUB( 18 ); NEXT; // A7
|
||||
SUB( 18 ); NEXT; /* A7 */
|
||||
|
||||
ADD( 20 ); ADD( 17 ); ADD( 16 );
|
||||
SUB( 19 ); NEXT; // A8
|
||||
SUB( 19 ); NEXT; /* A8 */
|
||||
|
||||
ADD( 21 ); ADD( 18 ); ADD( 17 );
|
||||
SUB( 20 ); NEXT; // A9
|
||||
SUB( 20 ); NEXT; /* A9 */
|
||||
|
||||
ADD( 22 ); ADD( 19 ); ADD( 18 );
|
||||
SUB( 21 ); NEXT; // A10
|
||||
SUB( 21 ); NEXT; /* A10 */
|
||||
|
||||
ADD( 23 ); ADD( 20 ); ADD( 19 );
|
||||
SUB( 22 ); LAST; // A11
|
||||
SUB( 22 ); LAST; /* A11 */
|
||||
|
||||
cleanup:
|
||||
return( ret );
|
||||
|
@ -1207,9 +1202,9 @@ cleanup:
|
|||
* Write N as A0 + 2^224 A1, return A0 + R * A1.
|
||||
* Actually do two passes, since R is big.
|
||||
*/
|
||||
#define P_KOBLITZ_MAX ( 256 / 8 / sizeof( mbedtls_mpi_uint ) ) // Max limbs in P
|
||||
#define P_KOBLITZ_R ( 8 / sizeof( mbedtls_mpi_uint ) ) // Limbs in R
|
||||
static inline int ecp_mod_koblitz( mbedtls_mpi *N, mbedtls_mpi_uint *Rp, size_t p_limbs,
|
||||
#define P_KOBLITZ_MAX ( 256 / 8 / sizeof( mbedtls_mpi_uint ) ) /* Max limbs in P */
|
||||
#define P_KOBLITZ_R ( 8 / sizeof( mbedtls_mpi_uint ) ) /* Limbs in R */
|
||||
static int ecp_mod_koblitz( mbedtls_mpi *N, mbedtls_mpi_uint *Rp, size_t p_limbs,
|
||||
size_t adjust, size_t shift, mbedtls_mpi_uint mask )
|
||||
{
|
||||
int ret;
|
||||
|
|
|
@ -167,9 +167,9 @@ void mbedtls_strerror( int ret, char *buf, size_t buflen )
|
|||
{
|
||||
use_ret = ret & 0xFF80;
|
||||
|
||||
// High level error codes
|
||||
//
|
||||
// BEGIN generated code
|
||||
/* High level error codes
|
||||
*
|
||||
* BEGIN generated code */
|
||||
#if defined(MBEDTLS_CIPHER_C)
|
||||
if( use_ret == -(MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE) )
|
||||
mbedtls_snprintf( buf, buflen, "CIPHER - The selected feature is not available" );
|
||||
|
@ -481,7 +481,7 @@ void mbedtls_strerror( int ret, char *buf, size_t buflen )
|
|||
if( use_ret == -(MBEDTLS_ERR_X509_BUFFER_TOO_SMALL) )
|
||||
mbedtls_snprintf( buf, buflen, "X509 - Destination buffer is too small" );
|
||||
#endif /* MBEDTLS_X509_USE_C || MBEDTLS_X509_CREATE_C */
|
||||
// END generated code
|
||||
/* END generated code */
|
||||
|
||||
if( strlen( buf ) == 0 )
|
||||
mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
|
||||
|
@ -492,9 +492,8 @@ void mbedtls_strerror( int ret, char *buf, size_t buflen )
|
|||
if( use_ret == 0 )
|
||||
return;
|
||||
|
||||
// If high level code is present, make a concatenation between both
|
||||
// error strings.
|
||||
//
|
||||
/* If high level code is present, make a concatenation between both
|
||||
* error strings. */
|
||||
len = strlen( buf );
|
||||
|
||||
if( len > 0 )
|
||||
|
@ -508,9 +507,10 @@ void mbedtls_strerror( int ret, char *buf, size_t buflen )
|
|||
buflen -= len + 3;
|
||||
}
|
||||
|
||||
// Low level error codes
|
||||
//
|
||||
// BEGIN generated code
|
||||
/* Low level error codes
|
||||
*
|
||||
* BEGIN generated code
|
||||
*/
|
||||
#if defined(MBEDTLS_AES_C)
|
||||
if( use_ret == -(MBEDTLS_ERR_AES_INVALID_KEY_LENGTH) )
|
||||
mbedtls_snprintf( buf, buflen, "AES - Invalid key length" );
|
||||
|
@ -679,7 +679,7 @@ void mbedtls_strerror( int ret, char *buf, size_t buflen )
|
|||
if( use_ret == -(MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH) )
|
||||
mbedtls_snprintf( buf, buflen, "XTEA - The data input has an invalid length" );
|
||||
#endif /* MBEDTLS_XTEA_C */
|
||||
// END generated code
|
||||
/* END generated code */
|
||||
|
||||
if( strlen( buf ) != 0 )
|
||||
return;
|
||||
|
|
|
@ -32,8 +32,7 @@
|
|||
#include <stddef.h>
|
||||
|
||||
#if !defined(MBEDTLS_ARC4_ALT)
|
||||
// Regular implementation
|
||||
//
|
||||
/* Regular implementation */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -43,8 +43,7 @@
|
|||
#define MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH -0x0018 /**< Invalid data input length. */
|
||||
|
||||
#if !defined(MBEDTLS_BLOWFISH_ALT)
|
||||
// Regular implementation
|
||||
//
|
||||
/* Regular implementation */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -39,8 +39,7 @@
|
|||
#define MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH -0x0026 /**< Invalid data input length. */
|
||||
|
||||
#if !defined(MBEDTLS_CAMELLIA_ALT)
|
||||
// Regular implementation
|
||||
//
|
||||
/* Regular implementation */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -40,8 +40,7 @@
|
|||
#define MBEDTLS_DES_KEY_SIZE 8
|
||||
|
||||
#if !defined(MBEDTLS_DES_ALT)
|
||||
// Regular implementation
|
||||
//
|
||||
/* Regular implementation */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -33,8 +33,7 @@
|
|||
#include <stdint.h>
|
||||
|
||||
#if !defined(MBEDTLS_MD5_ALT)
|
||||
// Regular implementation
|
||||
//
|
||||
/* Regular implementation */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -33,8 +33,7 @@
|
|||
#include <stdint.h>
|
||||
|
||||
#if !defined(MBEDTLS_RIPEMD160_ALT)
|
||||
// Regular implementation
|
||||
//
|
||||
/* Regular implementation */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -33,8 +33,7 @@
|
|||
#include <stdint.h>
|
||||
|
||||
#if !defined(MBEDTLS_SHA1_ALT)
|
||||
// Regular implementation
|
||||
//
|
||||
/* Regular implementation */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -33,8 +33,7 @@
|
|||
#include <stdint.h>
|
||||
|
||||
#if !defined(MBEDTLS_SHA256_ALT)
|
||||
// Regular implementation
|
||||
//
|
||||
/* Regular implementation */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -30,8 +30,7 @@
|
|||
#endif
|
||||
|
||||
#if !defined(MBEDTLS_TIMING_ALT)
|
||||
// Regular implementation
|
||||
//
|
||||
/* Regular implementation */
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
|
|
@ -38,8 +38,7 @@
|
|||
#define MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH -0x0028 /**< The data input has an invalid length. */
|
||||
|
||||
#if !defined(MBEDTLS_XTEA_ALT)
|
||||
// Regular implementation
|
||||
//
|
||||
/* Regular implementation */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -158,7 +158,7 @@ int mbedtls_pk_can_do( const mbedtls_pk_context *ctx, mbedtls_pk_type_t type )
|
|||
/*
|
||||
* Helper for mbedtls_pk_sign and mbedtls_pk_verify
|
||||
*/
|
||||
static inline int pk_hashlen_helper( mbedtls_md_type_t md_alg, size_t *hash_len )
|
||||
static int pk_hashlen_helper( mbedtls_md_type_t md_alg, size_t *hash_len )
|
||||
{
|
||||
const mbedtls_md_info_t *md_info;
|
||||
|
||||
|
|
|
@ -261,7 +261,7 @@ int mbedtls_pkcs12_derivation( unsigned char *data, size_t datalen,
|
|||
const mbedtls_md_info_t *md_info;
|
||||
mbedtls_md_context_t md_ctx;
|
||||
|
||||
// This version only allows max of 64 bytes of password or salt
|
||||
/* This version only allows max of 64 bytes of password or salt */
|
||||
if( datalen > 128 || pwdlen > 64 || saltlen > 64 )
|
||||
return( MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA );
|
||||
|
||||
|
@ -288,7 +288,7 @@ int mbedtls_pkcs12_derivation( unsigned char *data, size_t datalen,
|
|||
p = data;
|
||||
while( datalen > 0 )
|
||||
{
|
||||
// Calculate hash( diversifier || salt_block || pwd_block )
|
||||
/* Calculate hash( diversifier || salt_block || pwd_block ) */
|
||||
if( ( ret = mbedtls_md_starts( &md_ctx ) ) != 0 )
|
||||
goto exit;
|
||||
|
||||
|
@ -304,7 +304,7 @@ int mbedtls_pkcs12_derivation( unsigned char *data, size_t datalen,
|
|||
if( ( ret = mbedtls_md_finish( &md_ctx, hash_output ) ) != 0 )
|
||||
goto exit;
|
||||
|
||||
// Perform remaining ( iterations - 1 ) recursive hash calculations
|
||||
/* Perform remaining ( iterations - 1 ) recursive hash calculations */
|
||||
for( i = 1; i < (size_t) iterations; i++ )
|
||||
{
|
||||
if( ( ret = mbedtls_md( md_info, hash_output, hlen, hash_output ) ) != 0 )
|
||||
|
@ -319,15 +319,15 @@ int mbedtls_pkcs12_derivation( unsigned char *data, size_t datalen,
|
|||
if( datalen == 0 )
|
||||
break;
|
||||
|
||||
// Concatenating copies of hash_output into hash_block (B)
|
||||
/* Concatenating copies of hash_output into hash_block (B) */
|
||||
pkcs12_fill_buffer( hash_block, v, hash_output, hlen );
|
||||
|
||||
// B += 1
|
||||
/* B += 1 */
|
||||
for( i = v; i > 0; i-- )
|
||||
if( ++hash_block[i - 1] != 0 )
|
||||
break;
|
||||
|
||||
// salt_block += B
|
||||
/* salt_block += B */
|
||||
c = 0;
|
||||
for( i = v; i > 0; i-- )
|
||||
{
|
||||
|
@ -336,7 +336,7 @@ int mbedtls_pkcs12_derivation( unsigned char *data, size_t datalen,
|
|||
salt_block[i - 1] = j & 0xFF;
|
||||
}
|
||||
|
||||
// pwd_block += B
|
||||
/* pwd_block += B */
|
||||
c = 0;
|
||||
for( i = v; i > 0; i-- )
|
||||
{
|
||||
|
|
|
@ -142,8 +142,7 @@ int mbedtls_pkcs5_pbes2( const mbedtls_asn1_buf *pbe_params, int mode,
|
|||
if( ( ret = mbedtls_asn1_get_alg( &p, end, &kdf_alg_oid, &kdf_alg_params ) ) != 0 )
|
||||
return( MBEDTLS_ERR_PKCS5_INVALID_FORMAT + ret );
|
||||
|
||||
// Only PBKDF2 supported at the moment
|
||||
//
|
||||
/* Only PBKDF2 supported at the moment */
|
||||
if( MBEDTLS_OID_CMP( MBEDTLS_OID_PKCS5_PBKDF2, &kdf_alg_oid ) != 0 )
|
||||
return( MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE );
|
||||
|
||||
|
@ -236,8 +235,7 @@ int mbedtls_pkcs5_pbkdf2_hmac( mbedtls_md_context_t *ctx, const unsigned char *p
|
|||
|
||||
while( key_length )
|
||||
{
|
||||
// U1 ends up in work
|
||||
//
|
||||
/* U1 ends up in work */
|
||||
if( ( ret = mbedtls_md_hmac_starts( ctx, password, plen ) ) != 0 )
|
||||
return( ret );
|
||||
|
||||
|
@ -254,8 +252,7 @@ int mbedtls_pkcs5_pbkdf2_hmac( mbedtls_md_context_t *ctx, const unsigned char *p
|
|||
|
||||
for( i = 1; i < iteration_count; i++ )
|
||||
{
|
||||
// U2 ends up in md1
|
||||
//
|
||||
/* U2 ends up in md1 */
|
||||
if( ( ret = mbedtls_md_hmac_starts( ctx, password, plen ) ) != 0 )
|
||||
return( ret );
|
||||
|
||||
|
@ -265,8 +262,7 @@ int mbedtls_pkcs5_pbkdf2_hmac( mbedtls_md_context_t *ctx, const unsigned char *p
|
|||
if( ( ret = mbedtls_md_hmac_finish( ctx, md1 ) ) != 0 )
|
||||
return( ret );
|
||||
|
||||
// U1 xor U2
|
||||
//
|
||||
/* U1 xor U2 */
|
||||
for( j = 0; j < md_size; j++ )
|
||||
work[j] ^= md1[j];
|
||||
}
|
||||
|
|
|
@ -1013,9 +1013,9 @@ static int pk_parse_key_pkcs8_encrypted_der(
|
|||
return( ret );
|
||||
}
|
||||
|
||||
// Best guess for password mismatch when using RC4. If first tag is
|
||||
// not MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE
|
||||
//
|
||||
/* Best guess for password mismatch when using RC4. If first tag is
|
||||
* not MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE
|
||||
*/
|
||||
if( *buf != ( MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) )
|
||||
return( MBEDTLS_ERR_PK_PASSWORD_MISMATCH );
|
||||
|
||||
|
|
|
@ -698,7 +698,7 @@ int mbedtls_rsa_rsaes_pkcs1_v15_encrypt( mbedtls_rsa_context *ctx,
|
|||
if( mode == MBEDTLS_RSA_PRIVATE && ctx->padding != MBEDTLS_RSA_PKCS_V15 )
|
||||
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
|
||||
|
||||
// We don't check p_rng because it won't be dereferenced here
|
||||
/* We don't check p_rng because it won't be dereferenced here */
|
||||
if( f_rng == NULL || input == NULL || output == NULL )
|
||||
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
|
||||
|
||||
|
@ -816,7 +816,7 @@ int mbedtls_rsa_rsaes_oaep_decrypt( mbedtls_rsa_context *ctx,
|
|||
|
||||
hlen = mbedtls_md_get_size( md_info );
|
||||
|
||||
// checking for integer underflow
|
||||
/* checking for integer underflow */
|
||||
if( 2 * hlen + 2 > ilen )
|
||||
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
|
||||
|
||||
|
|
|
@ -199,8 +199,7 @@ static int x509_write_name( unsigned char **p, unsigned char *start,
|
|||
int ret;
|
||||
size_t len = 0;
|
||||
|
||||
// Write PrintableString for all except MBEDTLS_OID_PKCS9_EMAIL
|
||||
//
|
||||
/* Write PrintableString for all except MBEDTLS_OID_PKCS9_EMAIL */
|
||||
if( MBEDTLS_OID_SIZE( MBEDTLS_OID_PKCS9_EMAIL ) == oid_len &&
|
||||
memcmp( oid, MBEDTLS_OID_PKCS9_EMAIL, oid_len ) == 0 )
|
||||
{
|
||||
|
@ -215,8 +214,7 @@ static int x509_write_name( unsigned char **p, unsigned char *start,
|
|||
name_len ) );
|
||||
}
|
||||
|
||||
// Write OID
|
||||
//
|
||||
/* Write OID */
|
||||
MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_oid( p, start, oid, oid_len ) );
|
||||
|
||||
MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( p, start, len ) );
|
||||
|
@ -275,8 +273,7 @@ int mbedtls_x509_write_sig( unsigned char **p, unsigned char *start,
|
|||
MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( p, start, len ) );
|
||||
MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( p, start, MBEDTLS_ASN1_BIT_STRING ) );
|
||||
|
||||
// Write OID
|
||||
//
|
||||
/* Write OID */
|
||||
MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_algorithm_identifier( p, start, oid,
|
||||
oid_len, 0 ) );
|
||||
|
||||
|
|
|
@ -499,8 +499,8 @@ int mbedtls_x509_crl_parse( mbedtls_x509_crl *chain, const unsigned char *buf, s
|
|||
{
|
||||
mbedtls_pem_init( &pem );
|
||||
|
||||
// Avoid calling mbedtls_pem_read_buffer() on non-null-terminated
|
||||
// string
|
||||
/* Avoid calling mbedtls_pem_read_buffer() on non-null-terminated
|
||||
* string */
|
||||
if( buflen == 0 || buf[buflen - 1] != '\0' )
|
||||
ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT;
|
||||
else
|
||||
|
|
|
@ -676,7 +676,7 @@ static int x509_crt_parse_der_core( mbedtls_x509_crt *crt, const unsigned char *
|
|||
if( crt == NULL || buf == NULL )
|
||||
return( MBEDTLS_ERR_X509_BAD_INPUT_DATA );
|
||||
|
||||
// Use the original buffer until we figure out actual length
|
||||
/* Use the original buffer until we figure out actual length */
|
||||
p = (unsigned char*) buf;
|
||||
len = buflen;
|
||||
end = p + len;
|
||||
|
@ -702,7 +702,7 @@ static int x509_crt_parse_der_core( mbedtls_x509_crt *crt, const unsigned char *
|
|||
}
|
||||
crt_end = p + len;
|
||||
|
||||
// Create and populate a new buffer for the raw field
|
||||
/* Create and populate a new buffer for the raw field */
|
||||
crt->raw.len = crt_end - buf;
|
||||
crt->raw.p = p = mbedtls_calloc( 1, crt->raw.len );
|
||||
if( p == NULL )
|
||||
|
@ -710,7 +710,7 @@ static int x509_crt_parse_der_core( mbedtls_x509_crt *crt, const unsigned char *
|
|||
|
||||
memcpy( p, buf, crt->raw.len );
|
||||
|
||||
// Direct pointers to the new buffer
|
||||
/* Direct pointers to the new buffer */
|
||||
p += crt->raw.len - len;
|
||||
end = crt_end = p + len;
|
||||
|
||||
|
@ -1199,8 +1199,7 @@ cleanup:
|
|||
if( !S_ISREG( sb.st_mode ) )
|
||||
continue;
|
||||
|
||||
// Ignore parse errors
|
||||
//
|
||||
/* Ignore parse errors */
|
||||
t_ret = mbedtls_x509_crt_parse_file( chain, entry_name );
|
||||
if( t_ret < 0 )
|
||||
ret++;
|
||||
|
|
Loading…
Reference in New Issue