@@ -365,7 +365,6 @@ L$enc_sbox:
pxor %xmm11,%xmm7
pshufd $78,%xmm3,%xmm1
pxor %xmm12,%xmm8

pxor %xmm10,%xmm2
pxor %xmm14,%xmm6
pxor %xmm13,%xmm5
@@ -798,148 +797,86 @@ L$dec_sbox:
decl %r10d
jl L$dec_done

pshufd $147,%xmm4,%xmm14
movdqa %xmm5,%xmm9
pxor %xmm6,%xmm4
pxor %xmm6,%xmm5
pshufd $147,%xmm15,%xmm7
movdqa %xmm6,%xmm12
pxor %xmm15,%xmm6
pxor %xmm0,%xmm15
pshufd $147,%xmm0,%xmm8
pxor %xmm5,%xmm0
pxor %xmm2,%xmm15
pxor %xmm3,%xmm0
pshufd $147,%xmm3,%xmm10
pxor %xmm15,%xmm5
pxor %xmm4,%xmm3
pxor %xmm2,%xmm4
pshufd $147,%xmm2,%xmm13
movdqa %xmm1,%xmm11
pxor %xmm1,%xmm2
pxor %xmm3,%xmm1
pxor %xmm4,%xmm3
pxor %xmm12,%xmm2
pxor %xmm9,%xmm3
pxor %xmm11,%xmm3
pshufd $147,%xmm12,%xmm12

pxor %xmm4,%xmm6
pxor %xmm7,%xmm4
pxor %xmm8,%xmm6
pshufd $147,%xmm9,%xmm9
pxor %xmm12,%xmm4
pxor %xmm13,%xmm6
pxor %xmm14,%xmm4
pshufd $147,%xmm11,%xmm11
pxor %xmm13,%xmm14
pxor %xmm4,%xmm6

pshufd $78,%xmm15,%xmm7
pshufd $78,%xmm2,%xmm13
pxor %xmm15,%xmm7
pshufd $78,%xmm4,%xmm14
pxor %xmm2,%xmm13
pshufd $78,%xmm0,%xmm8
pxor %xmm4,%xmm14
pshufd $78,%xmm5,%xmm9
pxor %xmm0,%xmm8
pshufd $78,%xmm3,%xmm10
pxor %xmm5,%xmm9
pxor %xmm13,%xmm15
pxor %xmm13,%xmm0
pshufd $78,%xmm1,%xmm11
pxor %xmm3,%xmm10
pxor %xmm7,%xmm5
pshufd $147,%xmm7,%xmm7
pxor %xmm8,%xmm15
pxor %xmm8,%xmm0
pxor %xmm9,%xmm15
pshufd $147,%xmm8,%xmm8
pxor %xmm9,%xmm5
pxor %xmm9,%xmm3
pxor %xmm14,%xmm15
pshufd $147,%xmm9,%xmm9
pxor %xmm10,%xmm5
pxor %xmm10,%xmm1
pxor %xmm10,%xmm0
pshufd $147,%xmm10,%xmm10
pxor %xmm11,%xmm2
pxor %xmm11,%xmm3
pxor %xmm14,%xmm2
pxor %xmm12,%xmm5
pxor %xmm11,%xmm0
pxor %xmm12,%xmm14

pxor %xmm14,%xmm3
pshufd $147,%xmm11,%xmm11
pxor %xmm14,%xmm1
pxor %xmm8,%xmm3
pshufd $78,%xmm6,%xmm12
pxor %xmm1,%xmm11
pxor %xmm14,%xmm0
pxor %xmm9,%xmm1
pxor %xmm6,%xmm12

pxor %xmm12,%xmm14
pshufd $147,%xmm12,%xmm12
pxor %xmm13,%xmm14


pxor %xmm2,%xmm0
pxor %xmm14,%xmm5
pxor %xmm13,%xmm3
pxor %xmm13,%xmm1
pxor %xmm10,%xmm6
pxor %xmm11,%xmm2
pshufd $147,%xmm13,%xmm13
pxor %xmm7,%xmm15
pxor %xmm12,%xmm2
pxor %xmm9,%xmm15
pshufd $147,%xmm14,%xmm14

pxor %xmm6,%xmm5
pxor %xmm8,%xmm6
pxor %xmm7,%xmm4
pxor %xmm7,%xmm5
pxor %xmm12,%xmm6
pxor %xmm12,%xmm4
pxor %xmm14,%xmm1
pxor %xmm14,%xmm6
pshufd $147,%xmm7,%xmm7
pxor %xmm13,%xmm4
pxor %xmm6,%xmm5
pxor %xmm12,%xmm4
pshufd $147,%xmm15,%xmm7
pshufd $147,%xmm0,%xmm8
pxor %xmm7,%xmm15
pshufd $147,%xmm5,%xmm9
pxor %xmm8,%xmm0
pshufd $147,%xmm8,%xmm8

pxor %xmm14,%xmm2
pxor %xmm9,%xmm0
pxor %xmm9,%xmm3
pshufd $147,%xmm9,%xmm9
pxor %xmm13,%xmm15
pxor %xmm10,%xmm13
pxor %xmm2,%xmm0
pxor %xmm13,%xmm5

pxor %xmm13,%xmm1
pxor %xmm12,%xmm3
pshufd $147,%xmm3,%xmm10
pxor %xmm9,%xmm5
pshufd $147,%xmm1,%xmm11
pxor %xmm10,%xmm3
pshufd $147,%xmm6,%xmm12
pxor %xmm11,%xmm1
pshufd $147,%xmm11,%xmm11
pxor %xmm13,%xmm3
pxor %xmm14,%xmm1
pxor %xmm10,%xmm13

pshufd $147,%xmm12,%xmm12
pshufd $147,%xmm13,%xmm13
pshufd $147,%xmm14,%xmm14
pshufd $147,%xmm10,%xmm10

pshufd $147,%xmm2,%xmm13
pxor %xmm12,%xmm6
pshufd $147,%xmm4,%xmm14
pxor %xmm13,%xmm2
pxor %xmm14,%xmm4

pxor %xmm6,%xmm0
pxor %xmm6,%xmm8
pxor %xmm12,%xmm7
pxor %xmm12,%xmm8
pxor %xmm7,%xmm5
pxor %xmm15,%xmm8
pxor %xmm4,%xmm7
pxor %xmm13,%xmm8
pxor %xmm14,%xmm13
pxor %xmm4,%xmm8
pshufd $78,%xmm15,%xmm15
pxor %xmm0,%xmm9
pshufd $78,%xmm0,%xmm0
pxor %xmm1,%xmm12
pxor %xmm7,%xmm15
pxor %xmm6,%xmm13
pxor %xmm8,%xmm0
pxor %xmm11,%xmm2
pxor %xmm0,%xmm11
pxor %xmm10,%xmm1
pxor %xmm5,%xmm10
pxor %xmm9,%xmm3
pxor %xmm15,%xmm9
pxor %xmm14,%xmm10
pxor %xmm3,%xmm12
pxor %xmm13,%xmm9
pxor %xmm13,%xmm12
pxor %xmm1,%xmm13
pxor %xmm3,%xmm11
pshufd $78,%xmm1,%xmm7
pxor %xmm2,%xmm14

movdqa %xmm7,%xmm15
movdqa %xmm8,%xmm0
movdqa %xmm9,%xmm1
movdqa %xmm10,%xmm2
movdqa %xmm11,%xmm3
movdqa %xmm12,%xmm4
pshufd $78,%xmm6,%xmm8
pxor %xmm5,%xmm10
pshufd $78,%xmm3,%xmm1
pxor %xmm4,%xmm10
pshufd $78,%xmm4,%xmm6
pxor %xmm4,%xmm11
pshufd $78,%xmm2,%xmm3
pxor %xmm11,%xmm7
pshufd $78,%xmm5,%xmm2
pxor %xmm12,%xmm8
pxor %xmm1,%xmm10
pxor %xmm14,%xmm6
pxor %xmm3,%xmm13
movdqa %xmm7,%xmm3
pxor %xmm9,%xmm2
movdqa %xmm13,%xmm5
movdqa %xmm14,%xmm6
movdqa %xmm8,%xmm4
movdqa %xmm2,%xmm1
movdqa %xmm10,%xmm2
movdqa -16(%r11),%xmm7
jnz L$dec_loop
movdqa -32(%r11),%xmm7
@@ -1395,8 +1395,8 @@ $L$cbc_picked_te::
jb $L$cbc_slow_prologue
test rdx,15
jnz $L$cbc_slow_prologue


bt r10d,28
jc $L$cbc_slow_prologue


lea r15,QWORD PTR[((-88-248))+rsp]
@@ -365,7 +365,6 @@ $L$enc_sbox::
pxor xmm7,xmm11
pshufd xmm1,xmm3,04Eh
pxor xmm8,xmm12

pxor xmm2,xmm10
pxor xmm6,xmm14
pxor xmm5,xmm13
@@ -798,148 +797,86 @@ $L$dec_sbox::
dec r10d
jl $L$dec_done

pshufd xmm14,xmm4,093h
movdqa xmm9,xmm5
pxor xmm4,xmm6
pxor xmm5,xmm6
pshufd xmm7,xmm15,093h
movdqa xmm12,xmm6
pxor xmm6,xmm15
pxor xmm15,xmm0
pshufd xmm8,xmm0,093h
pxor xmm0,xmm5
pxor xmm15,xmm2
pxor xmm0,xmm3
pshufd xmm10,xmm3,093h
pxor xmm5,xmm15
pxor xmm3,xmm4
pxor xmm4,xmm2
pshufd xmm13,xmm2,093h
movdqa xmm11,xmm1
pxor xmm2,xmm1
pxor xmm1,xmm3
pxor xmm3,xmm4
pxor xmm2,xmm12
pxor xmm3,xmm9
pxor xmm3,xmm11
pshufd xmm12,xmm12,093h

pxor xmm6,xmm4
pxor xmm4,xmm7
pxor xmm6,xmm8
pshufd xmm9,xmm9,093h
pxor xmm4,xmm12
pxor xmm6,xmm13
pxor xmm4,xmm14
pshufd xmm11,xmm11,093h
pxor xmm14,xmm13
pxor xmm6,xmm4

pshufd xmm7,xmm15,04Eh
pshufd xmm13,xmm2,04Eh
pxor xmm7,xmm15
pshufd xmm14,xmm4,04Eh
pxor xmm13,xmm2
pshufd xmm8,xmm0,04Eh
pxor xmm14,xmm4
pshufd xmm9,xmm5,04Eh
pxor xmm8,xmm0
pshufd xmm10,xmm3,04Eh
pxor xmm9,xmm5
pxor xmm15,xmm13
pxor xmm0,xmm13
pshufd xmm11,xmm1,04Eh
pxor xmm10,xmm3
pxor xmm5,xmm7
pshufd xmm7,xmm7,093h
pxor xmm15,xmm8
pxor xmm0,xmm8
pxor xmm15,xmm9
pshufd xmm8,xmm8,093h
pxor xmm5,xmm9
pxor xmm3,xmm9
pxor xmm15,xmm14
pshufd xmm9,xmm9,093h
pxor xmm5,xmm10
pxor xmm1,xmm10
pxor xmm0,xmm10
pshufd xmm10,xmm10,093h
pxor xmm2,xmm11
pxor xmm3,xmm11
pxor xmm2,xmm14
pxor xmm5,xmm12
pxor xmm0,xmm11
pxor xmm14,xmm12

pxor xmm3,xmm14
pshufd xmm11,xmm11,093h
pxor xmm1,xmm14
pxor xmm3,xmm8
pshufd xmm12,xmm6,04Eh
pxor xmm11,xmm1
pxor xmm0,xmm14
pxor xmm1,xmm9
pxor xmm12,xmm6

pxor xmm14,xmm12
pshufd xmm12,xmm12,093h
pxor xmm14,xmm13


pxor xmm0,xmm2
pxor xmm5,xmm14
pxor xmm3,xmm13
pxor xmm1,xmm13
pxor xmm6,xmm10
pxor xmm2,xmm11
pshufd xmm13,xmm13,093h
pxor xmm15,xmm7
pxor xmm2,xmm12
pxor xmm15,xmm9
pshufd xmm14,xmm14,093h

pxor xmm5,xmm6
pxor xmm6,xmm8
pxor xmm4,xmm7
pxor xmm5,xmm7
pxor xmm6,xmm12
pxor xmm4,xmm12
pxor xmm1,xmm14
pxor xmm6,xmm14
pshufd xmm7,xmm7,093h
pxor xmm4,xmm13
pxor xmm5,xmm6
pxor xmm4,xmm12
pshufd xmm7,xmm15,093h
pshufd xmm8,xmm0,093h
pxor xmm15,xmm7
pshufd xmm9,xmm5,093h
pxor xmm0,xmm8
pshufd xmm8,xmm8,093h

pxor xmm2,xmm14
pxor xmm0,xmm9
pxor xmm3,xmm9
pshufd xmm9,xmm9,093h
pxor xmm15,xmm13
pxor xmm13,xmm10
pxor xmm0,xmm2
pxor xmm5,xmm13

pxor xmm1,xmm13
pxor xmm3,xmm12
pshufd xmm10,xmm3,093h
pxor xmm5,xmm9
pshufd xmm11,xmm1,093h
pxor xmm3,xmm10
pshufd xmm12,xmm6,093h
pxor xmm1,xmm11
pshufd xmm11,xmm11,093h
pxor xmm3,xmm13
pxor xmm1,xmm14
pxor xmm13,xmm10

pshufd xmm12,xmm12,093h
pshufd xmm13,xmm13,093h
pshufd xmm14,xmm14,093h
pshufd xmm10,xmm10,093h

pshufd xmm13,xmm2,093h
pxor xmm6,xmm12
pshufd xmm14,xmm4,093h
pxor xmm2,xmm13
pxor xmm4,xmm14

pxor xmm0,xmm6
pxor xmm8,xmm6
pxor xmm7,xmm12
pxor xmm8,xmm12
pxor xmm5,xmm7
pxor xmm8,xmm15
pxor xmm7,xmm4
pxor xmm8,xmm13
pxor xmm13,xmm14
pxor xmm8,xmm4
pshufd xmm15,xmm15,04Eh
pxor xmm9,xmm0
pshufd xmm0,xmm0,04Eh
pxor xmm12,xmm1
pxor xmm15,xmm7
pxor xmm13,xmm6
pxor xmm0,xmm8
pxor xmm2,xmm11
pxor xmm11,xmm0
pxor xmm1,xmm10
pxor xmm10,xmm5
pxor xmm3,xmm9
pxor xmm9,xmm15
pxor xmm10,xmm14
pxor xmm12,xmm3
pxor xmm9,xmm13
pxor xmm12,xmm13
pxor xmm13,xmm1
pxor xmm11,xmm3
pshufd xmm7,xmm1,04Eh
pxor xmm14,xmm2

movdqa xmm15,xmm7
movdqa xmm0,xmm8
movdqa xmm1,xmm9
movdqa xmm2,xmm10
movdqa xmm3,xmm11
movdqa xmm4,xmm12
pshufd xmm8,xmm6,04Eh
pxor xmm10,xmm5
pshufd xmm1,xmm3,04Eh
pxor xmm10,xmm4
pshufd xmm6,xmm4,04Eh
pxor xmm11,xmm4
pshufd xmm3,xmm2,04Eh
pxor xmm7,xmm11
pshufd xmm2,xmm5,04Eh
pxor xmm8,xmm12
pxor xmm10,xmm1
pxor xmm6,xmm14
pxor xmm13,xmm3
movdqa xmm3,xmm7
pxor xmm2,xmm9
movdqa xmm5,xmm13
movdqa xmm6,xmm14
movdqa xmm4,xmm8
movdqa xmm1,xmm2
movdqa xmm2,xmm10
movdqa xmm7,XMMWORD PTR[((-16))+r11]
jnz $L$dec_loop
movdqa xmm7,XMMWORD PTR[((-32))+r11]
@@ -1640,7 +1577,7 @@ $L$xts_enc_prologue::
push r15
lea rsp,QWORD PTR[((-72))+rsp]
mov r10,QWORD PTR[160+rsp]
mov r11d,DWORD PTR[168+rsp]
mov r11,QWORD PTR[168+rsp]
lea rsp,QWORD PTR[((-160))+rsp]
movaps XMMWORD PTR[64+rsp],xmm6
movaps XMMWORD PTR[80+rsp],xmm7
@@ -2120,7 +2057,7 @@ $L$xts_dec_prologue::
push r15
lea rsp,QWORD PTR[((-72))+rsp]
mov r10,QWORD PTR[160+rsp]
mov r11d,DWORD PTR[168+rsp]
mov r11,QWORD PTR[168+rsp]
lea rsp,QWORD PTR[((-160))+rsp]
movaps XMMWORD PTR[64+rsp],xmm6
movaps XMMWORD PTR[80+rsp],xmm7
@@ -827,8 +827,8 @@ $L$gather::
lea rcx,QWORD PTR[8+rcx]
sub rdx,1
jnz $L$gather
movaps XMMWORD PTR[rsp],xmm6
movaps XMMWORD PTR[16+rsp],xmm7
movaps xmm6,XMMWORD PTR[rsp]
movaps xmm7,XMMWORD PTR[16+rsp]
lea rsp,QWORD PTR[40+rsp]
DB 0F3h,0C3h ;repret
$L$SEH_end_bn_gather5::
@@ -2252,6 +2252,8 @@ AES_cbc_encrypt:
jb .L015slow_way
testl $15,%ecx
jnz .L015slow_way
btl $28,(%eax)
jc .L015slow_way
leal -324(%esp),%esi
andl $-64,%esi
movl %ebp,%eax
@@ -61,6 +61,7 @@ OPENSSL_ia32_cpuid:
movzbl %cl,%esi
incl %esi
movl $1,%eax
xorl %ecx,%ecx
.byte 0x0f,0xa2
btl $28,%edx
jnc .L002generic
@@ -82,6 +83,7 @@ OPENSSL_ia32_cpuid:
andl $4095,%edi
.L003nocacheinfo:
movl $1,%eax
xorl %ecx,%ecx
.byte 0x0f,0xa2
andl $3220176895,%edx
cmpl $0,%ebp
@@ -2219,6 +2219,8 @@ L014picked_te:
jb L015slow_way
testl $15,%ecx
jnz L015slow_way
btl $28,(%eax)
jc L015slow_way
leal -324(%esp),%esi
andl $-64,%esi
movl %ebp,%eax
@@ -60,6 +60,7 @@ L_OPENSSL_ia32_cpuid_begin:
movzbl %cl,%esi
incl %esi
movl $1,%eax
xorl %ecx,%ecx
.byte 0x0f,0xa2
btl $28,%edx
jnc L002generic
@@ -81,6 +82,7 @@ L001intel:
andl $4095,%edi
L003nocacheinfo:
movl $1,%eax
xorl %ecx,%ecx
.byte 0x0f,0xa2
andl $3220176895,%edx
cmpl $0,%ebp
@@ -2241,6 +2241,8 @@ $L014picked_te:
jb $L015slow_way
test ecx,15
jnz $L015slow_way
bt DWORD PTR [eax],28
jc $L015slow_way
lea esi,DWORD PTR [esp-324]
and esi,-64
mov eax,ebp
@@ -2,7 +2,7 @@ TITLE bf-686.asm
IF @Version LT 800
ECHO MASM version 8.00 or later is strongly recommended.
ENDIF
.686
.486
.MODEL FLAT
OPTION DOTNAME
IF @Version LT 800
@@ -2,7 +2,7 @@ TITLE ../openssl/crypto/bn/asm/x86-mont.asm
IF @Version LT 800
ECHO MASM version 8.00 or later is strongly recommended.
ENDIF
.686
.486
.MODEL FLAT
OPTION DOTNAME
IF @Version LT 800
@@ -2,7 +2,7 @@ TITLE ../openssl/crypto/bn/asm/x86.asm
IF @Version LT 800
ECHO MASM version 8.00 or later is strongly recommended.
ENDIF
.686
.486
.MODEL FLAT
OPTION DOTNAME
IF @Version LT 800
@@ -2,7 +2,7 @@ TITLE cmll-586.asm
IF @Version LT 800
ECHO MASM version 8.00 or later is strongly recommended.
ENDIF
.686
.486
.MODEL FLAT
OPTION DOTNAME
IF @Version LT 800
@@ -2,7 +2,7 @@ TITLE cast-586.asm
IF @Version LT 800
ECHO MASM version 8.00 or later is strongly recommended.
ENDIF
.686
.486
.MODEL FLAT
OPTION DOTNAME
IF @Version LT 800
@@ -2,7 +2,7 @@ TITLE crypt586.asm
IF @Version LT 800
ECHO MASM version 8.00 or later is strongly recommended.
ENDIF
.686
.486
.MODEL FLAT
OPTION DOTNAME
IF @Version LT 800
@@ -2,7 +2,7 @@ TITLE des-586.asm
IF @Version LT 800
ECHO MASM version 8.00 or later is strongly recommended.
ENDIF
.686
.486
.MODEL FLAT
OPTION DOTNAME
IF @Version LT 800
@@ -2,7 +2,7 @@ TITLE ../openssl/crypto/md5/asm/md5-586.asm
IF @Version LT 800
ECHO MASM version 8.00 or later is strongly recommended.
ENDIF
.686
.486
.MODEL FLAT
OPTION DOTNAME
IF @Version LT 800
@@ -2,7 +2,7 @@ TITLE rc5-586.asm
IF @Version LT 800
ECHO MASM version 8.00 or later is strongly recommended.
ENDIF
.686
.486
.MODEL FLAT
OPTION DOTNAME
IF @Version LT 800
@@ -2,7 +2,7 @@ TITLE ../openssl/crypto/ripemd/asm/rmd-586.asm
IF @Version LT 800
ECHO MASM version 8.00 or later is strongly recommended.
ENDIF
.686
.486
.MODEL FLAT
OPTION DOTNAME
IF @Version LT 800
@@ -2,7 +2,7 @@ TITLE sha1-586.asm
IF @Version LT 800
ECHO MASM version 8.00 or later is strongly recommended.
ENDIF
.686
.486
.MODEL FLAT
OPTION DOTNAME
IF @Version LT 800
@@ -2,7 +2,7 @@ TITLE sha512-586.asm
IF @Version LT 800
ECHO MASM version 8.00 or later is strongly recommended.
ENDIF
.686
.486
.MODEL FLAT
OPTION DOTNAME
IF @Version LT 800
@@ -2,7 +2,7 @@ TITLE sha512-586.asm
IF @Version LT 800
ECHO MASM version 8.00 or later is strongly recommended.
ENDIF
.686
.486
.MODEL FLAT
OPTION DOTNAME
IF @Version LT 800
@@ -2,7 +2,7 @@ TITLE x86cpuid.asm
IF @Version LT 800
ECHO MASM version 8.00 or later is strongly recommended.
ENDIF
.686
.486
.MODEL FLAT
OPTION DOTNAME
IF @Version LT 800
@@ -69,6 +69,7 @@ $L_OPENSSL_ia32_cpuid_begin::
movzx esi,cl
inc esi
mov eax,1
xor ecx,ecx
cpuid
bt edx,28
jnc $L002generic
@@ -90,6 +91,7 @@ $L001intel:
and edi,4095
$L003nocacheinfo:
mov eax,1
xor ecx,ecx
cpuid
and edx,3220176895
cmp ebp,0
@@ -2,9 +2,31 @@
OpenSSL CHANGES
_______________

Changes between 1.0.1e and 1.0.1f [6 Jan 2014]

*) Fix for TLS record tampering bug. A carefully crafted invalid
handshake could crash OpenSSL with a NULL pointer exception.
Thanks to Anton Johansson for reporting this issues.
(CVE-2013-4353)

*) Keep original DTLS digest and encryption contexts in retransmission
structures so we can use the previous session parameters if they need
to be resent. (CVE-2013-6450)
[Steve Henson]

*) Add option SSL_OP_SAFARI_ECDHE_ECDSA_BUG (part of SSL_OP_ALL) which
avoids preferring ECDHE-ECDSA ciphers when the client appears to be
Safari on OS X. Safari on OS X 10.8..10.8.3 advertises support for
several ECDHE-ECDSA ciphers, but fails to negotiate them. The bug
is fixed in OS X 10.8.4, but Apple have ruled out both hot fixing
10.8..10.8.3 and forcing users to upgrade to 10.8.4 or newer.
[Rob Stradling, Adam Langley]

Changes between 1.0.1d and 1.0.1e [11 Feb 2013]

*)
*) Correct fix for CVE-2013-0169. The original didn't work on AES-NI
supporting platforms or when small records were transferred.
[Andy Polyakov, Steve Henson]

Changes between 1.0.1c and 1.0.1d [5 Feb 2013]

@@ -404,6 +426,63 @@
Add command line options to s_client/s_server.
[Steve Henson]

Changes between 1.0.0j and 1.0.0k [5 Feb 2013]

*) Make the decoding of SSLv3, TLS and DTLS CBC records constant time.

This addresses the flaw in CBC record processing discovered by
Nadhem Alfardan and Kenny Paterson. Details of this attack can be found
at: http://www.isg.rhul.ac.uk/tls/

Thanks go to Nadhem Alfardan and Kenny Paterson of the Information
Security Group at Royal Holloway, University of London
(www.isg.rhul.ac.uk) for discovering this flaw and Adam Langley and
Emilia K�sper for the initial patch.
(CVE-2013-0169)
[Emilia K�sper, Adam Langley, Ben Laurie, Andy Polyakov, Steve Henson]

*) Return an error when checking OCSP signatures when key is NULL.
This fixes a DoS attack. (CVE-2013-0166)
[Steve Henson]

*) Call OCSP Stapling callback after ciphersuite has been chosen, so
the right response is stapled. Also change SSL_get_certificate()
so it returns the certificate actually sent.
See http://rt.openssl.org/Ticket/Display.html?id=2836.
(This is a backport)
[Rob Stradling <rob.stradling@comodo.com>]

*) Fix possible deadlock when decoding public keys.
[Steve Henson]

Changes between 1.0.0i and 1.0.0j [10 May 2012]

[NB: OpenSSL 1.0.0i and later 1.0.0 patch levels were released after
OpenSSL 1.0.1.]

*) Sanity check record length before skipping explicit IV in DTLS
to fix DoS attack.

Thanks to Codenomicon for discovering this issue using Fuzz-o-Matic
fuzzing as a service testing platform.
(CVE-2012-2333)
[Steve Henson]

*) Initialise tkeylen properly when encrypting CMS messages.
Thanks to Solar Designer of Openwall for reporting this issue.
[Steve Henson]

Changes between 1.0.0h and 1.0.0i [19 Apr 2012]

*) Check for potentially exploitable overflows in asn1_d2i_read_bio
BUF_mem_grow and BUF_mem_grow_clean. Refuse attempts to shrink buffer
in CRYPTO_realloc_clean.

Thanks to Tavis Ormandy, Google Security Team, for discovering this
issue and to Adam Langley <agl@chromium.org> for fixing it.
(CVE-2012-2110)
[Adam Langley (Google), Tavis Ormandy, Google Security Team]

Changes between 1.0.0g and 1.0.0h [12 Mar 2012]

*) Fix MMA (Bleichenbacher's attack on PKCS #1 v1.5 RSA padding) weakness
@@ -1394,14 +1473,94 @@
*) Change 'Configure' script to enable Camellia by default.
[NTT]

Changes between 0.9.8x and 0.9.8y [5 Feb 2013]

*) Make the decoding of SSLv3, TLS and DTLS CBC records constant time.

This addresses the flaw in CBC record processing discovered by
Nadhem Alfardan and Kenny Paterson. Details of this attack can be found
at: http://www.isg.rhul.ac.uk/tls/

Thanks go to Nadhem Alfardan and Kenny Paterson of the Information
Security Group at Royal Holloway, University of London
(www.isg.rhul.ac.uk) for discovering this flaw and Adam Langley and
Emilia K�sper for the initial patch.
(CVE-2013-0169)
[Emilia K�sper, Adam Langley, Ben Laurie, Andy Polyakov, Steve Henson]

*) Return an error when checking OCSP signatures when key is NULL.
This fixes a DoS attack. (CVE-2013-0166)
[Steve Henson]

*) Call OCSP Stapling callback after ciphersuite has been chosen, so
the right response is stapled. Also change SSL_get_certificate()
so it returns the certificate actually sent.
See http://rt.openssl.org/Ticket/Display.html?id=2836.
(This is a backport)
[Rob Stradling <rob.stradling@comodo.com>]

*) Fix possible deadlock when decoding public keys.
[Steve Henson]

Changes between 0.9.8w and 0.9.8x [10 May 2012]

*) Sanity check record length before skipping explicit IV in DTLS
to fix DoS attack.

Thanks to Codenomicon for discovering this issue using Fuzz-o-Matic
fuzzing as a service testing platform.
(CVE-2012-2333)
[Steve Henson]

*) Initialise tkeylen properly when encrypting CMS messages.
Thanks to Solar Designer of Openwall for reporting this issue.
[Steve Henson]

Changes between 0.9.8v and 0.9.8w [23 Apr 2012]

*) The fix for CVE-2012-2110 did not take into account that the
'len' argument to BUF_MEM_grow and BUF_MEM_grow_clean is an
int in OpenSSL 0.9.8, making it still vulnerable. Fix by
rejecting negative len parameter. (CVE-2012-2131)
[Tomas Hoger <thoger@redhat.com>]

Changes between 0.9.8u and 0.9.8v [19 Apr 2012]

*) Check for potentially exploitable overflows in asn1_d2i_read_bio
BUF_mem_grow and BUF_mem_grow_clean. Refuse attempts to shrink buffer
in CRYPTO_realloc_clean.

Thanks to Tavis Ormandy, Google Security Team, for discovering this
issue and to Adam Langley <agl@chromium.org> for fixing it.
(CVE-2012-2110)
[Adam Langley (Google), Tavis Ormandy, Google Security Team]

Changes between 0.9.8t and 0.9.8u [12 Mar 2012]

*) Fix MMA (Bleichenbacher's attack on PKCS #1 v1.5 RSA padding) weakness
in CMS and PKCS7 code. When RSA decryption fails use a random key for
content decryption and always return the same error. Note: this attack
needs on average 2^20 messages so it only affects automated senders. The
old behaviour can be reenabled in the CMS code by setting the
CMS_DEBUG_DECRYPT flag: this is useful for debugging and testing where
an MMA defence is not necessary.
Thanks to Ivan Nestlerode <inestlerode@us.ibm.com> for discovering
this issue. (CVE-2012-0884)
[Steve Henson]

*) Fix CVE-2011-4619: make sure we really are receiving a
client hello before rejecting multiple SGC restarts. Thanks to
Ivan Nestlerode <inestlerode@us.ibm.com> for discovering this bug.
[Steve Henson]

Changes between 0.9.8s and 0.9.8t [18 Jan 2012]

*) Fix for DTLS DoS issue introduced by fix for CVE-2011-4109.
Thanks to Antonio Martin, Enterprise Secure Access Research and
Development, Cisco Systems, Inc. for discovering this bug and
preparing a fix. (CVE-2012-0050)
[Antonio Martin]

Changes between 0.9.8r and 0.9.8s [4 Jan 2012]

*) Nadhem Alfardan and Kenny Paterson have discovered an extension
@@ -178,7 +178,7 @@ my %table=(
"debug-ben-no-opt", "gcc: -Wall -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -DDEBUG_SAFESTACK -DCRYPTO_MDEBUG -Werror -DL_ENDIAN -DTERMIOS -Wall -g3::(unknown)::::::",
"debug-ben-strict", "gcc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG -DCONST_STRICT -O2 -Wall -Wshadow -Werror -Wpointer-arith -Wcast-qual -Wwrite-strings -pipe::(unknown)::::::",
"debug-rse","cc:-DTERMIOS -DL_ENDIAN -pipe -O -g -ggdb3 -Wall::(unknown):::BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_elf_asm}",
"debug-bodo", "gcc:$gcc_devteam_warn -DBN_DEBUG -DBN_DEBUG_RAND -DCONF_DEBUG -DBIO_PAIR_DEBUG -m64 -DL_ENDIAN -DTERMIO -g -DMD32_REG_T=int::-D_REENTRANT::-ldl:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:${x86_64_asm}:elf:dlfcn:linux-shared:-fPIC:-m64:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR):::64",
"debug-bodo", "gcc:$gcc_devteam_warn -Wno-error=overlength-strings -DBN_DEBUG -DBN_DEBUG_RAND -DCONF_DEBUG -DBIO_PAIR_DEBUG -m64 -DL_ENDIAN -DTERMIO -g -DMD32_REG_T=int::-D_REENTRANT::-ldl:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:${x86_64_asm}:elf:dlfcn:linux-shared:-fPIC:-m64:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR):::64",
"debug-ulf", "gcc:-DTERMIOS -DL_ENDIAN -march=i486 -Wall -DBN_DEBUG -DBN_DEBUG_RAND -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG -DOPENSSL_NO_ASM -g -Wformat -Wshadow -Wmissing-prototypes -Wmissing-declarations:::CYGWIN32:::${no_asm}:win32:cygwin-shared:::.dll",
"debug-steve64", "gcc:$gcc_devteam_warn -m64 -DL_ENDIAN -DTERMIO -DCONF_DEBUG -DDEBUG_SAFESTACK -Wno-overlength-strings -g::-D_REENTRANT::-ldl:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:${x86_64_asm}:elf:dlfcn:linux-shared:-fPIC:-m64:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
"debug-steve32", "gcc:$gcc_devteam_warn -m32 -DL_ENDIAN -DCONF_DEBUG -DDEBUG_SAFESTACK -g -pipe::-D_REENTRANT::-rdynamic -ldl:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_elf_asm}:dlfcn:linux-shared:-fPIC:-m32:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
@@ -4,7 +4,7 @@
## Makefile for OpenSSL
##

VERSION=1.0.1e
VERSION=1.0.1f
MAJOR=1
MINOR=0.1
SHLIB_VERSION_NUMBER=1.0.0
@@ -304,7 +304,8 @@ libcrypto$(SHLIB_EXT): libcrypto.a fips_premain_dso$(EXE_EXT)
FIPSLD_CC="$(CC)"; CC=$(FIPSDIR)/bin/fipsld; \
export CC FIPSLD_CC FIPSLD_LIBCRYPTO; \
fi; \
$(MAKE) -e SHLIBDIRS=crypto build-shared; \
$(MAKE) -e SHLIBDIRS=crypto CC=$${CC:-$(CC)} build-shared; \
touch -c fips_premain_dso$(EXE_EXT); \
else \
echo "There's no support for shared libraries on this platform" >&2; \
exit 1; \
@@ -302,7 +302,8 @@ libcrypto$(SHLIB_EXT): libcrypto.a fips_premain_dso$(EXE_EXT)
FIPSLD_CC="$(CC)"; CC=$(FIPSDIR)/bin/fipsld; \
export CC FIPSLD_CC FIPSLD_LIBCRYPTO; \
fi; \
$(MAKE) -e SHLIBDIRS=crypto build-shared; \
$(MAKE) -e SHLIBDIRS=crypto CC=$${CC:-$(CC)} build-shared; \
touch -c fips_premain_dso$(EXE_EXT); \
else \
echo "There's no support for shared libraries on this platform" >&2; \
exit 1; \

Large diffs are not rendered by default.

@@ -1,5 +1,5 @@

OpenSSL 1.0.1e 11 Feb 2013
OpenSSL 1.0.1f 6 Jan 2014

Copyright (c) 1998-2011 The OpenSSL Project
Copyright (c) 1995-1998 Eric A. Young, Tim J. Hudson
@@ -577,14 +577,15 @@ openssl.o: ../include/openssl/objects.h ../include/openssl/ocsp.h
openssl.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
openssl.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
openssl.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
openssl.o: ../include/openssl/pqueue.h ../include/openssl/safestack.h
openssl.o: ../include/openssl/sha.h ../include/openssl/srtp.h
openssl.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
openssl.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h
openssl.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
openssl.o: ../include/openssl/tls1.h ../include/openssl/txt_db.h
openssl.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
openssl.o: ../include/openssl/x509v3.h apps.h openssl.c progs.h s_apps.h
openssl.o: ../include/openssl/pqueue.h ../include/openssl/rand.h
openssl.o: ../include/openssl/safestack.h ../include/openssl/sha.h
openssl.o: ../include/openssl/srtp.h ../include/openssl/ssl.h
openssl.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h
openssl.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
openssl.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
openssl.o: ../include/openssl/txt_db.h ../include/openssl/x509.h
openssl.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h
openssl.o: openssl.c progs.h s_apps.h
passwd.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
passwd.o: ../include/openssl/buffer.h ../include/openssl/conf.h
passwd.o: ../include/openssl/crypto.h ../include/openssl/des.h
@@ -188,6 +188,7 @@ extern BIO *bio_err;
do { CONF_modules_unload(1); destroy_ui_method(); \
OBJ_cleanup(); EVP_cleanup(); ENGINE_cleanup(); \
CRYPTO_cleanup_all_ex_data(); ERR_remove_thread_state(NULL); \
RAND_cleanup(); \
ERR_free_strings(); zlib_cleanup();} while(0)
# else
# define apps_startup() \
@@ -198,6 +199,7 @@ extern BIO *bio_err;
do { CONF_modules_unload(1); destroy_ui_method(); \
OBJ_cleanup(); EVP_cleanup(); \
CRYPTO_cleanup_all_ex_data(); ERR_remove_thread_state(NULL); \
RAND_cleanup(); \
ERR_free_strings(); zlib_cleanup(); } while(0)
# endif
#endif
@@ -117,6 +117,7 @@
#include "apps.h"
#include <openssl/bio.h>
#include <openssl/crypto.h>
#include <openssl/rand.h>
#include <openssl/lhash.h>
#include <openssl/conf.h>
#include <openssl/x509.h>
@@ -112,7 +112,7 @@ int MAIN(int argc, char **argv)
int maciter = PKCS12_DEFAULT_ITER;
int twopass = 0;
int keytype = 0;
int cert_pbe = NID_pbe_WithSHA1And40BitRC2_CBC;
int cert_pbe;
int key_pbe = NID_pbe_WithSHA1And3_Key_TripleDES_CBC;
int ret = 1;
int macver = 1;
@@ -130,6 +130,13 @@ int MAIN(int argc, char **argv)

apps_startup();

#ifdef OPENSSL_FIPS
if (FIPS_mode())
cert_pbe = NID_pbe_WithSHA1And3_Key_TripleDES_CBC;
else
#endif
cert_pbe = NID_pbe_WithSHA1And40BitRC2_CBC;

enc = EVP_des_ede3_cbc();
if (bio_err == NULL ) bio_err = BIO_new_fp (stderr, BIO_NOCLOSE);

@@ -178,13 +178,6 @@ typedef unsigned int u_int;
#include <fcntl.h>
#endif

/* Use Windows API with STD_INPUT_HANDLE when checking for input?
Don't look at OPENSSL_SYS_MSDOS for this, since it is always defined if
OPENSSL_SYS_WINDOWS is defined */
#if defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_WINCE) && defined(STD_INPUT_HANDLE)
#define OPENSSL_USE_STD_INPUT_HANDLE
#endif

#undef PROG
#define PROG s_client_main

@@ -1611,10 +1604,10 @@ SSL_set_tlsext_status_ids(con, ids);
tv.tv_usec = 0;
i=select(width,(void *)&readfds,(void *)&writefds,
NULL,&tv);
#if defined(OPENSSL_USE_STD_INPUT_HANDLE)
if(!i && (!((_kbhit()) || (WAIT_OBJECT_0 == WaitForSingleObject(GetStdHandle(STD_INPUT_HANDLE), 0))) || !read_tty) ) continue;
#else
#if defined(OPENSSL_SYS_WINCE) || defined(OPENSSL_SYS_MSDOS)
if(!i && (!_kbhit() || !read_tty) ) continue;
#else
if(!i && (!((_kbhit()) || (WAIT_OBJECT_0 == WaitForSingleObject(GetStdHandle(STD_INPUT_HANDLE), 0))) || !read_tty) ) continue;
#endif
} else i=select(width,(void *)&readfds,(void *)&writefds,
NULL,timeoutp);
@@ -1819,10 +1812,10 @@ printf("read=%d pending=%d peek=%d\n",k,SSL_pending(con),SSL_peek(con,zbuf,10240
}

#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS)
#if defined(OPENSSL_USE_STD_INPUT_HANDLE)
else if ((_kbhit()) || (WAIT_OBJECT_0 == WaitForSingleObject(GetStdHandle(STD_INPUT_HANDLE), 0)))
#else
#if defined(OPENSSL_SYS_WINCE) || defined(OPENSSL_SYS_MSDOS)
else if (_kbhit())
#else
else if ((_kbhit()) || (WAIT_OBJECT_0 == WaitForSingleObject(GetStdHandle(STD_INPUT_HANDLE), 0)))
#endif
#elif defined (OPENSSL_SYS_NETWARE)
else if (_kbhit())
@@ -739,7 +739,7 @@ case "$GUESSOS" in
libc=/usr/lib/libc.so
else # OpenBSD
# ld searches for highest libc.so.* and so do we
libc=`(ls /usr/lib/libc.so.* | tail -1) 2>/dev/null`
libc=`(ls /usr/lib/libc.so.* /lib/libc.so.* | tail -1) 2>/dev/null`
fi
case "`(file -L $libc) 2>/dev/null`" in
*ELF*) OUT="BSD-x86-elf" ;;
@@ -77,7 +77,9 @@ ia64cpuid.s: ia64cpuid.S; $(CC) $(CFLAGS) -E ia64cpuid.S > $@
ppccpuid.s: ppccpuid.pl; $(PERL) ppccpuid.pl $(PERLASM_SCHEME) $@
pariscid.s: pariscid.pl; $(PERL) pariscid.pl $(PERLASM_SCHEME) $@
alphacpuid.s: alphacpuid.pl
$(PERL) $< | $(CC) -E - | tee $@ > /dev/null
(preproc=/tmp/$$$$.$@; trap "rm $$preproc" INT; \
$(PERL) alphacpuid.pl > $$preproc && \
$(CC) -E $$preproc > $@ && rm $$preproc)

testapps:
[ -z "$(THIS)" ] || ( if echo $(SDIRS) | fgrep ' des '; \
@@ -2054,8 +2054,8 @@ ()
&test ($s2,15);
&jnz (&label("slow_way"));
if (!$x86only) {
#&bt (&DWP(0,$s0),28); # check for hyper-threading bit
#&jc (&label("slow_way"));
&bt (&DWP(0,$s0),28); # check for hyper-threading bit
&jc (&label("slow_way"));
}
# pre-allocate aligned stack frame...
&lea ($acc,&DWP(-80-244,"esp"));
@@ -1015,7 +1015,8 @@
$SIZE_T==4 ? sprintf("extru%s,%d,8,",$1,31-$2)
: sprintf("extrd,u%s,%d,8,",$1,63-$2)/e;

s/,\*/,/ if ($SIZE_T==4);
s/,\*/,/ if ($SIZE_T==4);
s/\bbv\b(.*\(%r2\))/bve$1/ if ($SIZE_T==8);
print $_,"\n";
}
close STDOUT;
@@ -1684,8 +1684,8 @@ ()
jb .Lcbc_slow_prologue
test \$15,%rdx
jnz .Lcbc_slow_prologue
#bt \$28,%r10d
#jc .Lcbc_slow_prologue
bt \$28,%r10d
jc .Lcbc_slow_prologue
# allocate aligned stack frame...
lea -88-248(%rsp),$key
@@ -83,9 +83,9 @@
# Add decryption procedure. Performance in CPU cycles spent to decrypt
# one byte out of 4096-byte buffer with 128-bit key is:
#
# Core 2 11.0
# Nehalem 9.16
# Atom 20.9
# Core 2 9.83
# Nehalem 7.74
# Atom 19.0
#
# November 2011.
#
@@ -456,6 +456,7 @@ sub MixColumns {
# modified to emit output in order suitable for feeding back to aesenc[last]
my @x=@_[0..7];
my @t=@_[8..15];
my $inv=@_[16]; # optional
$code.=<<___;
pshufd \$0x93, @x[0], @t[0] # x0 <<< 32
pshufd \$0x93, @x[1], @t[1]
@@ -497,17 +498,29 @@ sub MixColumns {
pxor @t[4], @t[0]
pshufd \$0x4E, @x[2], @x[6]
pxor @t[5], @t[1]
___
$code.=<<___ if (!$inv);
pxor @t[3], @x[4]
pxor @t[7], @x[5]
pxor @t[6], @x[3]
movdqa @t[0], @x[2]
pxor @t[2], @x[6]
movdqa @t[1], @x[7]
___
$code.=<<___ if ($inv);
pxor @x[4], @t[3]
pxor @t[7], @x[5]
pxor @x[3], @t[6]
movdqa @t[0], @x[3]
pxor @t[2], @x[6]
movdqa @t[6], @x[2]
movdqa @t[1], @x[7]
movdqa @x[6], @x[4]
movdqa @t[3], @x[6]
___
}

sub InvMixColumns {
sub InvMixColumns_orig {
my @x=@_[0..7];
my @t=@_[8..15];

@@ -661,6 +674,54 @@ sub InvMixColumns {
___
}

sub InvMixColumns {
my @x=@_[0..7];
my @t=@_[8..15];

# Thanks to Jussi Kivilinna for providing pointer to
#
# | 0e 0b 0d 09 | | 02 03 01 01 | | 05 00 04 00 |
# | 09 0e 0b 0d | = | 01 02 03 01 | x | 00 05 00 04 |
# | 0d 09 0e 0b | | 01 01 02 03 | | 04 00 05 00 |
# | 0b 0d 09 0e | | 03 01 01 02 | | 00 04 00 05 |

$code.=<<___;
# multiplication by 0x05-0x00-0x04-0x00
pshufd \$0x4E, @x[0], @t[0]
pshufd \$0x4E, @x[6], @t[6]
pxor @x[0], @t[0]
pshufd \$0x4E, @x[7], @t[7]
pxor @x[6], @t[6]
pshufd \$0x4E, @x[1], @t[1]
pxor @x[7], @t[7]
pshufd \$0x4E, @x[2], @t[2]
pxor @x[1], @t[1]
pshufd \$0x4E, @x[3], @t[3]
pxor @x[2], @t[2]
pxor @t[6], @x[0]
pxor @t[6], @x[1]
pshufd \$0x4E, @x[4], @t[4]
pxor @x[3], @t[3]
pxor @t[0], @x[2]
pxor @t[1], @x[3]
pshufd \$0x4E, @x[5], @t[5]
pxor @x[4], @t[4]
pxor @t[7], @x[1]
pxor @t[2], @x[4]
pxor @x[5], @t[5]
pxor @t[7], @x[2]
pxor @t[6], @x[3]
pxor @t[6], @x[4]
pxor @t[3], @x[5]
pxor @t[4], @x[6]
pxor @t[7], @x[4]
pxor @t[7], @x[5]
pxor @t[5], @x[7]
___
&MixColumns (@x,@t,1); # flipped 2<->3 and 4<->6
}

sub aesenc { # not used
my @b=@_[0..7];
my @t=@_[8..15];
@@ -2028,6 +2089,8 @@ sub bitslice_key {
# const unsigned char iv[16]);
#
my ($twmask,$twres,$twtmp)=@XMM[13..15];
$arg6=~s/d$//;

$code.=<<___;
.globl bsaes_xts_encrypt
.type bsaes_xts_encrypt,\@abi-omnipotent
@@ -23,7 +23,7 @@ unsigned int _armv7_tick(void);

unsigned int OPENSSL_rdtsc(void)
{
if (OPENSSL_armcap_P|ARMV7_TICK)
if (OPENSSL_armcap_P & ARMV7_TICK)
return _armv7_tick();
else
return 0;
@@ -116,7 +116,7 @@ int i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp)
int pad=0,ret,i,neg;
unsigned char *p,*n,pb=0;

if ((a == NULL) || (a->data == NULL)) return(0);
if (a == NULL) return(0);
neg=a->type & V_ASN1_NEG;
if (a->length == 0)
ret=1;
@@ -566,7 +566,6 @@ int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in)
mbflag = tag2nbyte[type];
if(mbflag == -1) return -1;
mbflag |= MBSTRING_FLAG;
memset(&stmp, 0, sizeof(stmp));
stmp.data = NULL;
stmp.length = 0;
ret = ASN1_mbstring_copy(&str, in->data, in->length, mbflag, B_ASN1_UTF8STRING);
@@ -906,8 +906,8 @@ BIO *BIO_new_dgram_sctp(int fd, int close_flag)
memset(authchunks, 0, sizeof(sockopt_len));
ret = getsockopt(fd, IPPROTO_SCTP, SCTP_LOCAL_AUTH_CHUNKS, authchunks, &sockopt_len);
OPENSSL_assert(ret >= 0);
for (p = (unsigned char*) authchunks + sizeof(sctp_assoc_t);

for (p = (unsigned char*) authchunks->gauth_chunks;
p < (unsigned char*) authchunks + sockopt_len;
p += sizeof(uint8_t))
{
@@ -1197,7 +1197,7 @@ static int dgram_sctp_read(BIO *b, char *out, int outl)
ii = getsockopt(b->num, IPPROTO_SCTP, SCTP_PEER_AUTH_CHUNKS, authchunks, &optlen);
OPENSSL_assert(ii >= 0);

for (p = (unsigned char*) authchunks + sizeof(sctp_assoc_t);
for (p = (unsigned char*) authchunks->gauth_chunks;
p < (unsigned char*) authchunks + optlen;
p += sizeof(uint8_t))
{
@@ -125,7 +125,9 @@ ppc-mont.s: asm/ppc-mont.pl;$(PERL) asm/ppc-mont.pl $(PERLASM_SCHEME) $@
ppc64-mont.s: asm/ppc64-mont.pl;$(PERL) asm/ppc64-mont.pl $(PERLASM_SCHEME) $@

alpha-mont.s: asm/alpha-mont.pl
$(PERL) $< | $(CC) -E - | tee $@ > /dev/null
(preproc=/tmp/$$$$.$@; trap "rm $$preproc" INT; \
$(PERL) asm/alpha-mont.pl > $$preproc && \
$(CC) -E $$preproc > $@ && rm $$preproc)

# GNU make "catch all"
%-mont.s: asm/%-mont.pl; $(PERL) $< $(PERLASM_SCHEME) $@
@@ -133,7 +133,7 @@
bnez $at,1f
li $t0,0
slt $at,$num,17 # on in-order CPU
bnezl $at,bn_mul_mont_internal
bnez $at,bn_mul_mont_internal
nop
1: jr $ra
li $a0,0
@@ -140,10 +140,10 @@
.set reorder
li $minus4,-4
and $ta0,$a2,$minus4
$LD $t0,0($a1)
beqz $ta0,.L_bn_mul_add_words_tail
.L_bn_mul_add_words_loop:
$LD $t0,0($a1)
$MULTU $t0,$a3
$LD $t1,0($a0)
$LD $t2,$BNSZ($a1)
@@ -200,10 +200,9 @@
$ADDU $v0,$ta2
sltu $at,$ta3,$at
$ST $ta3,-$BNSZ($a0)
$ADDU $v0,$at
.set noreorder
bgtzl $ta0,.L_bn_mul_add_words_loop
$LD $t0,0($a1)
bgtz $ta0,.L_bn_mul_add_words_loop
$ADDU $v0,$at
beqz $a2,.L_bn_mul_add_words_return
nop
@@ -300,10 +299,10 @@
.set reorder
li $minus4,-4
and $ta0,$a2,$minus4
$LD $t0,0($a1)
beqz $ta0,.L_bn_mul_words_tail
.L_bn_mul_words_loop:
$LD $t0,0($a1)
$MULTU $t0,$a3
$LD $t2,$BNSZ($a1)
$LD $ta0,2*$BNSZ($a1)
@@ -341,10 +340,9 @@
$ADDU $v0,$at
sltu $ta3,$v0,$at
$ST $v0,-$BNSZ($a0)
$ADDU $v0,$ta3,$ta2
.set noreorder
bgtzl $ta0,.L_bn_mul_words_loop
$LD $t0,0($a1)
bgtz $ta0,.L_bn_mul_words_loop
$ADDU $v0,$ta3,$ta2
beqz $a2,.L_bn_mul_words_return
nop
@@ -429,10 +427,10 @@
.set reorder
li $minus4,-4
and $ta0,$a2,$minus4
$LD $t0,0($a1)
beqz $ta0,.L_bn_sqr_words_tail
.L_bn_sqr_words_loop:
$LD $t0,0($a1)
$MULTU $t0,$t0
$LD $t2,$BNSZ($a1)
$LD $ta0,2*$BNSZ($a1)
@@ -463,11 +461,10 @@
mflo $ta3
mfhi $ta2
$ST $ta3,-2*$BNSZ($a0)
$ST $ta2,-$BNSZ($a0)
.set noreorder
bgtzl $ta0,.L_bn_sqr_words_loop
$LD $t0,0($a1)
bgtz $ta0,.L_bn_sqr_words_loop
$ST $ta2,-$BNSZ($a0)
beqz $a2,.L_bn_sqr_words_return
nop
@@ -547,10 +544,10 @@
.set reorder
li $minus4,-4
and $at,$a3,$minus4
$LD $t0,0($a1)
beqz $at,.L_bn_add_words_tail
.L_bn_add_words_loop:
$LD $t0,0($a1)
$LD $ta0,0($a2)
subu $a3,4
$LD $t1,$BNSZ($a1)
@@ -589,11 +586,10 @@
$ADDU $t3,$ta3,$v0
sltu $v0,$t3,$ta3
$ST $t3,-$BNSZ($a0)
$ADDU $v0,$t9
.set noreorder
bgtzl $at,.L_bn_add_words_loop
$LD $t0,0($a1)
bgtz $at,.L_bn_add_words_loop
$ADDU $v0,$t9
beqz $a3,.L_bn_add_words_return
nop
@@ -679,10 +675,10 @@
.set reorder
li $minus4,-4
and $at,$a3,$minus4
$LD $t0,0($a1)
beqz $at,.L_bn_sub_words_tail
.L_bn_sub_words_loop:
$LD $t0,0($a1)
$LD $ta0,0($a2)
subu $a3,4
$LD $t1,$BNSZ($a1)
@@ -722,11 +718,10 @@
$SUBU $t3,$ta3,$v0
sgtu $v0,$t3,$ta3
$ST $t3,-$BNSZ($a0)
$ADDU $v0,$t9
.set noreorder
bgtzl $at,.L_bn_sub_words_loop
$LD $t0,0($a1)
bgtz $at,.L_bn_sub_words_loop
$ADDU $v0,$t9
beqz $a3,.L_bn_sub_words_return
nop
@@ -840,8 +835,9 @@
sltu $ta0,$a1,$a2
or $t8,$ta0
.set noreorder
beqzl $at,.L_bn_div_3_words_inner_loop
beqz $at,.L_bn_div_3_words_inner_loop
$SUBU $v0,1
$ADDU $v0,1
.set reorder
.L_bn_div_3_words_inner_loop_done:
.set noreorder
@@ -902,7 +898,8 @@
and $t2,$a0
$SRL $at,$a1,$t1
.set noreorder
bnezl $t2,.+8
beqz $t2,.+12
nop
break 6 # signal overflow
.set reorder
$SLL $a0,$t9
@@ -917,7 +914,8 @@
$SRL $DH,$a2,4*$BNSZ # bits
sgeu $at,$a0,$a2
.set noreorder
bnezl $at,.+8
beqz $at,.+12
nop
$SUBU $a0,$a2
.set reorder
@@ -40,7 +40,7 @@
# of arithmetic operations, most notably multiplications. It requires
# more memory references, most notably to tp[num], but this doesn't
# seem to exhaust memory port capacity. And indeed, dedicated PA-RISC
# 2.0 code path, provides virtually same performance as pa-risc2[W].s:
# 2.0 code path provides virtually same performance as pa-risc2[W].s:
# it's ~10% better for shortest key length and ~10% worse for longest
# one.
#
@@ -988,6 +988,8 @@ sub assemble {
# assemble 2.0 instructions in 32-bit mode...
s/^\s+([a-z]+)([\S]*)\s+([\S]*)/&assemble($1,$2,$3)/e if ($BN_SZ==4);

s/\bbv\b/bve/gm if ($SIZE_T==8);

print $_,"\n";
}
close STDOUT;
@@ -31,7 +31,8 @@
( $xlate="${dir}../../perlasm/x86_64-xlate.pl" and -f $xlate) or
die "can't locate x86_64-xlate.pl";

open STDOUT,"| \"$^X\" $xlate $flavour $output";
open OUT,"| \"$^X\" $xlate $flavour $output";
*STDOUT=*OUT;

($lo,$hi)=("%rax","%rdx"); $a=$lo;
($i0,$i1)=("%rsi","%rdi");
@@ -901,8 +901,8 @@
jnz .Lgather
___
$code.=<<___ if ($win64);
movaps %xmm6,(%rsp)
movaps %xmm7,0x10(%rsp)
movaps (%rsp),%xmm6
movaps 0x10(%rsp),%xmm7
lea 0x28(%rsp),%rsp
___
$code.=<<___;
@@ -286,26 +286,25 @@ const BIGNUM *BN_get0_nist_prime_521(void)
}


static void nist_cp_bn_0(BN_ULONG *buf, BN_ULONG *a, int top, int max)
static void nist_cp_bn_0(BN_ULONG *dst, const BN_ULONG *src, int top, int max)
{
int i;
BN_ULONG *_tmp1 = (buf), *_tmp2 = (a);

#ifdef BN_DEBUG
OPENSSL_assert(top <= max);
#endif
for (i = (top); i != 0; i--)
*_tmp1++ = *_tmp2++;
for (i = (max) - (top); i != 0; i--)
*_tmp1++ = (BN_ULONG) 0;
for (i = 0; i < top; i++)
dst[i] = src[i];
for (; i < max; i++)
dst[i] = 0;
}

static void nist_cp_bn(BN_ULONG *buf, BN_ULONG *a, int top)
static void nist_cp_bn(BN_ULONG *dst, const BN_ULONG *src, int top)
{
int i;
BN_ULONG *_tmp1 = (buf), *_tmp2 = (a);
for (i = (top); i != 0; i--)
*_tmp1++ = *_tmp2++;

for (i = 0; i < top; i++)
dst[i] = src[i];
}

#if BN_BITS2 == 64
@@ -451,8 +450,9 @@ int BN_nist_mod_192(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
*/
mask = 0-(PTR_SIZE_INT)bn_sub_words(c_d,r_d,_nist_p_192[0],BN_NIST_192_TOP);
mask &= 0-(PTR_SIZE_INT)carry;
res = c_d;
res = (BN_ULONG *)
(((PTR_SIZE_INT)c_d&~mask) | ((PTR_SIZE_INT)r_d&mask));
(((PTR_SIZE_INT)res&~mask) | ((PTR_SIZE_INT)r_d&mask));
nist_cp_bn(r_d, res, BN_NIST_192_TOP);
r->top = BN_NIST_192_TOP;
bn_correct_top(r);
@@ -479,8 +479,11 @@ int BN_nist_mod_224(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
int top = a->top, i;
int carry;
BN_ULONG *r_d, *a_d = a->d;
BN_ULONG buf[BN_NIST_224_TOP],
c_d[BN_NIST_224_TOP],
union {
BN_ULONG bn[BN_NIST_224_TOP];
unsigned int ui[BN_NIST_224_TOP*sizeof(BN_ULONG)/sizeof(unsigned int)];
} buf;
BN_ULONG c_d[BN_NIST_224_TOP],
*res;
PTR_SIZE_INT mask;
union { bn_addsub_f f; PTR_SIZE_INT p; } u;
@@ -519,18 +522,18 @@ int BN_nist_mod_224(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
/* copy upper 256 bits of 448 bit number ... */
nist_cp_bn_0(c_d, a_d + (BN_NIST_224_TOP-1), top - (BN_NIST_224_TOP-1), BN_NIST_224_TOP);
/* ... and right shift by 32 to obtain upper 224 bits */
nist_set_224(buf, c_d, 14, 13, 12, 11, 10, 9, 8);
nist_set_224(buf.bn, c_d, 14, 13, 12, 11, 10, 9, 8);
/* truncate lower part to 224 bits too */
r_d[BN_NIST_224_TOP-1] &= BN_MASK2l;
#else
nist_cp_bn_0(buf, a_d + BN_NIST_224_TOP, top - BN_NIST_224_TOP, BN_NIST_224_TOP);
nist_cp_bn_0(buf.bn, a_d + BN_NIST_224_TOP, top - BN_NIST_224_TOP, BN_NIST_224_TOP);
#endif

#if defined(NIST_INT64) && BN_BITS2!=64
{
NIST_INT64 acc; /* accumulator */
unsigned int *rp=(unsigned int *)r_d;
const unsigned int *bp=(const unsigned int *)buf;
const unsigned int *bp=(const unsigned int *)buf.ui;

acc = rp[0]; acc -= bp[7-7];
acc -= bp[11-7]; rp[0] = (unsigned int)acc; acc >>= 32;
@@ -565,13 +568,13 @@ int BN_nist_mod_224(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
{
BN_ULONG t_d[BN_NIST_224_TOP];

nist_set_224(t_d, buf, 10, 9, 8, 7, 0, 0, 0);
nist_set_224(t_d, buf.bn, 10, 9, 8, 7, 0, 0, 0);
carry = (int)bn_add_words(r_d, r_d, t_d, BN_NIST_224_TOP);
nist_set_224(t_d, buf, 0, 13, 12, 11, 0, 0, 0);
nist_set_224(t_d, buf.bn, 0, 13, 12, 11, 0, 0, 0);
carry += (int)bn_add_words(r_d, r_d, t_d, BN_NIST_224_TOP);
nist_set_224(t_d, buf, 13, 12, 11, 10, 9, 8, 7);
nist_set_224(t_d, buf.bn, 13, 12, 11, 10, 9, 8, 7);
carry -= (int)bn_sub_words(r_d, r_d, t_d, BN_NIST_224_TOP);
nist_set_224(t_d, buf, 0, 0, 0, 0, 13, 12, 11);
nist_set_224(t_d, buf.bn, 0, 0, 0, 0, 13, 12, 11);
carry -= (int)bn_sub_words(r_d, r_d, t_d, BN_NIST_224_TOP);

#if BN_BITS2==64
@@ -606,7 +609,8 @@ int BN_nist_mod_224(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
/* otherwise it's effectively same as in BN_nist_mod_192... */
mask = 0-(PTR_SIZE_INT)(*u.f)(c_d,r_d,_nist_p_224[0],BN_NIST_224_TOP);
mask &= 0-(PTR_SIZE_INT)carry;
res = (BN_ULONG *)(((PTR_SIZE_INT)c_d&~mask) |
res = c_d;
res = (BN_ULONG *)(((PTR_SIZE_INT)res&~mask) |
((PTR_SIZE_INT)r_d&mask));
nist_cp_bn(r_d, res, BN_NIST_224_TOP);
r->top = BN_NIST_224_TOP;
@@ -805,7 +809,8 @@ int BN_nist_mod_256(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,

mask = 0-(PTR_SIZE_INT)(*u.f)(c_d,r_d,_nist_p_256[0],BN_NIST_256_TOP);
mask &= 0-(PTR_SIZE_INT)carry;
res = (BN_ULONG *)(((PTR_SIZE_INT)c_d&~mask) |
res = c_d;
res = (BN_ULONG *)(((PTR_SIZE_INT)res&~mask) |
((PTR_SIZE_INT)r_d&mask));
nist_cp_bn(r_d, res, BN_NIST_256_TOP);
r->top = BN_NIST_256_TOP;
@@ -1026,7 +1031,8 @@ int BN_nist_mod_384(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,

mask = 0-(PTR_SIZE_INT)(*u.f)(c_d,r_d,_nist_p_384[0],BN_NIST_384_TOP);
mask &= 0-(PTR_SIZE_INT)carry;
res = (BN_ULONG *)(((PTR_SIZE_INT)c_d&~mask) |
res = c_d;
res = (BN_ULONG *)(((PTR_SIZE_INT)res&~mask) |
((PTR_SIZE_INT)r_d&mask));
nist_cp_bn(r_d, res, BN_NIST_384_TOP);
r->top = BN_NIST_384_TOP;
@@ -1092,7 +1098,8 @@ int BN_nist_mod_521(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,

bn_add_words(r_d,r_d,t_d,BN_NIST_521_TOP);
mask = 0-(PTR_SIZE_INT)bn_sub_words(t_d,r_d,_nist_p_521,BN_NIST_521_TOP);
res = (BN_ULONG *)(((PTR_SIZE_INT)t_d&~mask) |
res = t_d;
res = (BN_ULONG *)(((PTR_SIZE_INT)res&~mask) |
((PTR_SIZE_INT)r_d&mask));
nist_cp_bn(r_d,res,BN_NIST_521_TOP);
r->top = BN_NIST_521_TOP;
@@ -179,14 +179,14 @@ int BUF_MEM_grow_clean(BUF_MEM *str, size_t len)
return(len);
}

void BUF_reverse(unsigned char *out, unsigned char *in, size_t size)
void BUF_reverse(unsigned char *out, const unsigned char *in, size_t size)
{
size_t i;
if (in)
{
out += size - 1;
for (i = 0; i < size; i++)
*in++ = *out--;
*out-- = *in++;
}
else
{
@@ -88,7 +88,7 @@ int BUF_MEM_grow_clean(BUF_MEM *str, size_t len);
char * BUF_strdup(const char *str);
char * BUF_strndup(const char *str, size_t siz);
void * BUF_memdup(const void *data, size_t siz);
void BUF_reverse(unsigned char *out, unsigned char *in, size_t siz);
void BUF_reverse(unsigned char *out, const unsigned char *in, size_t siz);

/* safe string functions */
size_t BUF_strlcpy(char *dst,const char *src,size_t siz);
@@ -88,7 +88,7 @@ static int eckey_param2type(int *pptype, void **ppval, EC_KEY *ec_key)
if (!pstr)
return 0;
pstr->length = i2d_ECParameters(ec_key, &pstr->data);
if (pstr->length < 0)
if (pstr->length <= 0)
{
ASN1_STRING_free(pstr);
ECerr(EC_F_ECKEY_PARAM2TYPE, ERR_R_EC_LIB);
@@ -89,7 +89,8 @@ int EC_GROUP_get_trinomial_basis(const EC_GROUP *group, unsigned int *k)
if (group == NULL)
return 0;

if (EC_GROUP_method_of(group)->group_set_curve != ec_GF2m_simple_group_set_curve
if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) !=
NID_X9_62_characteristic_two_field
|| !((group->poly[0] != 0) && (group->poly[1] != 0) && (group->poly[2] == 0)))
{
ECerr(EC_F_EC_GROUP_GET_TRINOMIAL_BASIS, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
@@ -107,7 +108,8 @@ int EC_GROUP_get_pentanomial_basis(const EC_GROUP *group, unsigned int *k1,
if (group == NULL)
return 0;

if (EC_GROUP_method_of(group)->group_set_curve != ec_GF2m_simple_group_set_curve
if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) !=
NID_X9_62_characteristic_two_field
|| !((group->poly[0] != 0) && (group->poly[1] != 0) && (group->poly[2] != 0) && (group->poly[3] != 0) && (group->poly[4] == 0)))
{
ECerr(EC_F_EC_GROUP_GET_PENTANOMIAL_BASIS, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
@@ -480,10 +480,10 @@ int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ctx)
if (EC_METHOD_get_field_type(EC_GROUP_method_of(a)) !=
EC_METHOD_get_field_type(EC_GROUP_method_of(b)))
return 1;
/* compare the curve name (if present) */
/* compare the curve name (if present in both) */
if (EC_GROUP_get_curve_name(a) && EC_GROUP_get_curve_name(b) &&
EC_GROUP_get_curve_name(a) == EC_GROUP_get_curve_name(b))
return 0;
EC_GROUP_get_curve_name(a) != EC_GROUP_get_curve_name(b))
return 1;

if (!ctx)
ctx_new = ctx = BN_CTX_new();
@@ -993,12 +993,12 @@ int EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, BN
if (group->meth->point_cmp == 0)
{
ECerr(EC_F_EC_POINT_CMP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
return 0;
return -1;
}
if ((group->meth != a->meth) || (a->meth != b->meth))
{
ECerr(EC_F_EC_POINT_CMP, EC_R_INCOMPATIBLE_OBJECTS);
return 0;
return -1;
}
return group->meth->point_cmp(group, a, b, ctx);
}
@@ -104,6 +104,7 @@ static int bind_helper(ENGINE *e)
{
if (!ENGINE_set_id(e, engine_e_rdrand_id) ||
!ENGINE_set_name(e, engine_e_rdrand_name) ||
!ENGINE_set_flags(e, ENGINE_FLAGS_NO_REGISTER_ALL) ||
!ENGINE_set_init_function(e, rdrand_init) ||
!ENGINE_set_RAND(e, &rdrand_meth) )
return 0;
@@ -67,7 +67,7 @@ files:
links:
@$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
@$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
[ ! -f $(TESTDATA) ] || cp $(TESTDATA) ../../test
@[ -f $(TESTDATA) ] && cp $(TESTDATA) ../../test && echo "$(TESTDATA) -> ../../test/$(TESTDATA)"
@$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)

install:
@@ -366,8 +366,11 @@ int EVP_Digest(const void *data, size_t count,

void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx)
{
EVP_MD_CTX_cleanup(ctx);
OPENSSL_free(ctx);
if (ctx)
{
EVP_MD_CTX_cleanup(ctx);
OPENSSL_free(ctx);
}
}

/* This call frees resources associated with the context */
@@ -842,7 +842,10 @@ static int aes_gcm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
gctx->ctr = NULL;
break;
}
else
#endif
(void)0; /* terminate potentially open 'else' */

AES_set_encrypt_key(key, ctx->key_len * 8, &gctx->ks);
CRYPTO_gcm128_init(&gctx->gcm, &gctx->ks, (block128_f)AES_encrypt);
#ifdef AES_CTR_ASM
@@ -1083,14 +1086,17 @@ static int aes_xts_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
xctx->xts.block1 = (block128_f)vpaes_decrypt;
}

vpaes_set_encrypt_key(key + ctx->key_len/2,
vpaes_set_encrypt_key(key + ctx->key_len/2,
ctx->key_len * 4, &xctx->ks2);
xctx->xts.block2 = (block128_f)vpaes_encrypt;
xctx->xts.block2 = (block128_f)vpaes_encrypt;

xctx->xts.key1 = &xctx->ks1;
break;
}
xctx->xts.key1 = &xctx->ks1;
break;
}
else
#endif
(void)0; /* terminate potentially open 'else' */

if (enc)
{
AES_set_encrypt_key(key, ctx->key_len * 4, &xctx->ks1);
@@ -328,10 +328,11 @@ static int aesni_cbc_hmac_sha1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,

if (res!=SHA_CBLOCK) continue;

mask = 0-((inp_len+8-j)>>(sizeof(j)*8-1));
/* j is not incremented yet */
mask = 0-((inp_len+7-j)>>(sizeof(j)*8-1));
data->u[SHA_LBLOCK-1] |= bitlen&mask;
sha1_block_data_order(&key->md,data,1);
mask &= 0-((j-inp_len-73)>>(sizeof(j)*8-1));
mask &= 0-((j-inp_len-72)>>(sizeof(j)*8-1));
pmac->u[0] |= key->md.h0 & mask;
pmac->u[1] |= key->md.h1 & mask;
pmac->u[2] |= key->md.h2 & mask;
@@ -101,7 +101,7 @@ static int des_ede_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
static int des_ede_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
const unsigned char *in, size_t inl)
{
if (inl>=EVP_MAXCHUNK)
while (inl>=EVP_MAXCHUNK)
{
DES_ede3_ofb64_encrypt(in, out, (long)EVP_MAXCHUNK,
&data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3,
@@ -132,7 +132,7 @@ static int des_ede_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
printf("\n");
}
#endif /* KSSL_DEBUG */
if (inl>=EVP_MAXCHUNK)
while (inl>=EVP_MAXCHUNK)
{
DES_ede3_cbc_encrypt(in, out, (long)EVP_MAXCHUNK,
&data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3,
@@ -151,7 +151,7 @@ static int des_ede_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
static int des_ede_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
const unsigned char *in, size_t inl)
{
if (inl>=EVP_MAXCHUNK)
while (inl>=EVP_MAXCHUNK)
{
DES_ede3_cfb64_encrypt(in, out, (long)EVP_MAXCHUNK,
&data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3,
@@ -85,19 +85,24 @@ int PKCS5_PBKDF2_HMAC(const char *pass, int passlen,
unsigned char digtmp[EVP_MAX_MD_SIZE], *p, itmp[4];
int cplen, j, k, tkeylen, mdlen;
unsigned long i = 1;
HMAC_CTX hctx;
HMAC_CTX hctx_tpl, hctx;

mdlen = EVP_MD_size(digest);
if (mdlen < 0)
return 0;

HMAC_CTX_init(&hctx);
HMAC_CTX_init(&hctx_tpl);
p = out;
tkeylen = keylen;
if(!pass)
passlen = 0;
else if(passlen == -1)
passlen = strlen(pass);
if (!HMAC_Init_ex(&hctx_tpl, pass, passlen, digest, NULL))
{
HMAC_CTX_cleanup(&hctx_tpl);
return 0;
}
while(tkeylen)
{
if(tkeylen > mdlen)
@@ -111,27 +116,44 @@ int PKCS5_PBKDF2_HMAC(const char *pass, int passlen,
itmp[1] = (unsigned char)((i >> 16) & 0xff);
itmp[2] = (unsigned char)((i >> 8) & 0xff);
itmp[3] = (unsigned char)(i & 0xff);
if (!HMAC_Init_ex(&hctx, pass, passlen, digest, NULL)
|| !HMAC_Update(&hctx, salt, saltlen)
|| !HMAC_Update(&hctx, itmp, 4)
|| !HMAC_Final(&hctx, digtmp, NULL))
if (!HMAC_CTX_copy(&hctx, &hctx_tpl))
{
HMAC_CTX_cleanup(&hctx_tpl);
return 0;
}
if (!HMAC_Update(&hctx, salt, saltlen)
|| !HMAC_Update(&hctx, itmp, 4)
|| !HMAC_Final(&hctx, digtmp, NULL))
{
HMAC_CTX_cleanup(&hctx_tpl);
HMAC_CTX_cleanup(&hctx);
return 0;
}
HMAC_CTX_cleanup(&hctx);
memcpy(p, digtmp, cplen);
for(j = 1; j < iter; j++)
{
HMAC(digest, pass, passlen,
digtmp, mdlen, digtmp, NULL);
if (!HMAC_CTX_copy(&hctx, &hctx_tpl))
{
HMAC_CTX_cleanup(&hctx_tpl);
return 0;
}
if (!HMAC_Update(&hctx, digtmp, mdlen)
|| !HMAC_Final(&hctx, digtmp, NULL))
{
HMAC_CTX_cleanup(&hctx_tpl);
HMAC_CTX_cleanup(&hctx);
return 0;
}
HMAC_CTX_cleanup(&hctx);
for(k = 0; k < cplen; k++)
p[k] ^= digtmp[k];
}
tkeylen-= cplen;
i++;
p+= cplen;
}
HMAC_CTX_cleanup(&hctx);
HMAC_CTX_cleanup(&hctx_tpl);
#ifdef DEBUG_PKCS5V2
fprintf(stderr, "Password:\n");
h__dump (pass, passlen);
@@ -53,7 +53,10 @@ ghash-x86_64.s: asm/ghash-x86_64.pl
ghash-sparcv9.s: asm/ghash-sparcv9.pl
$(PERL) asm/ghash-sparcv9.pl $@ $(CFLAGS)
ghash-alpha.s: asm/ghash-alpha.pl
$(PERL) $< | $(CC) -E - | tee $@ > /dev/null
(preproc=/tmp/$$$$.$@; trap "rm $$preproc" INT; \
$(PERL) asm/ghash-alpha.pl > $$preproc && \
$(CC) -E $$preproc > $@ && rm $$preproc)

ghash-parisc.s: asm/ghash-parisc.pl
$(PERL) asm/ghash-parisc.pl $(PERLASM_SCHEME) $@

@@ -266,8 +266,8 @@
ldq $Xlo,8($Xi)
ldq $Xhi,0($Xi)

br $rem_4bit,.Lpic1
.Lpic1: lda $rem_4bit,rem_4bit-.Lpic1($rem_4bit)
bsr $t0,picmeup
nop
___

&loop();
@@ -341,8 +341,8 @@
ldq $Xhi,0($Xi)
ldq $Xlo,8($Xi)

br $rem_4bit,.Lpic2
.Lpic2: lda $rem_4bit,rem_4bit-.Lpic2($rem_4bit)
bsr $t0,picmeup
nop

.Louter:
extql $inhi,$inp,$inhi
@@ -436,11 +436,20 @@
.end gcm_ghash_4bit

.align 4
.ent picmeup
picmeup:
.frame sp,0,$t0
.prologue 0
br $rem_4bit,.Lpic
.Lpic: lda $rem_4bit,12($rem_4bit)
ret ($t0)
.end picmeup
nop
rem_4bit:
.quad 0x0000<<48, 0x1C20<<48, 0x3840<<48, 0x2460<<48
.quad 0x7080<<48, 0x6CA0<<48, 0x48C0<<48, 0x54E0<<48
.quad 0xE100<<48, 0xFD20<<48, 0xD940<<48, 0xC560<<48
.quad 0x9180<<48, 0x8DA0<<48, 0xA9C0<<48, 0xB5E0<<48
.long 0,0x0000<<16, 0,0x1C20<<16, 0,0x3840<<16, 0,0x2460<<16
.long 0,0x7080<<16, 0,0x6CA0<<16, 0,0x48C0<<16, 0,0x54E0<<16
.long 0,0xE100<<16, 0,0xFD20<<16, 0,0xD940<<16, 0,0xC560<<16
.long 0,0x9180<<16, 0,0x8DA0<<16, 0,0xA9C0<<16, 0,0xB5E0<<16
.ascii "GHASH for Alpha, CRYPTOGAMS by <appro\@openssl.org>"
.align 4

@@ -724,6 +724,7 @@ sub assemble {
s/cmpb,\*/comb,/;
s/,\*/,/;
}
s/\bbv\b/bve/ if ($SIZE_T==8);
print $_,"\n";
}

@@ -117,7 +117,7 @@ void CRYPTO_cbc128_decrypt(const unsigned char *in, unsigned char *out,
unsigned char ivec[16], block128_f block)
{
size_t n;
union { size_t align; unsigned char c[16]; } tmp;
union { size_t t[16/sizeof(size_t)]; unsigned char c[16]; } tmp;

assert(in && out && key && ivec);

@@ -137,11 +137,13 @@ void CRYPTO_cbc128_decrypt(const unsigned char *in, unsigned char *out,
out += 16;
}
}
else {
else if (16%sizeof(size_t) == 0) { /* always true */
while (len>=16) {
size_t *out_t=(size_t *)out, *iv_t=(size_t *)iv;

(*block)(in, out, key);
for(n=0; n<16; n+=sizeof(size_t))
*(size_t *)(out+n) ^= *(size_t *)(iv+n);
for(n=0; n<16/sizeof(size_t); n++)
out_t[n] ^= iv_t[n];
iv = in;
len -= 16;
in += 16;
@@ -165,15 +167,16 @@ void CRYPTO_cbc128_decrypt(const unsigned char *in, unsigned char *out,
out += 16;
}
}
else {
size_t c;
else if (16%sizeof(size_t) == 0) { /* always true */
while (len>=16) {
size_t c, *out_t=(size_t *)out, *ivec_t=(size_t *)ivec;
const size_t *in_t=(const size_t *)in;

(*block)(in, tmp.c, key);
for(n=0; n<16; n+=sizeof(size_t)) {
c = *(size_t *)(in+n);
*(size_t *)(out+n) =
*(size_t *)(tmp.c+n) ^ *(size_t *)(ivec+n);
*(size_t *)(ivec+n) = c;
for(n=0; n<16/sizeof(size_t); n++) {
c = in_t[n];
out_t[n] = tmp.t[n] ^ ivec_t[n];
ivec_t[n] = c;
}
len -= 16;
in += 16;
@@ -87,7 +87,7 @@ int CRYPTO_ccm128_setiv(CCM128_CONTEXT *ctx,
ctx->nonce.c[11] = (u8)(mlen>>(32%(sizeof(mlen)*8)));
}
else
*(u32*)(&ctx->nonce.c[8]) = 0;
ctx->nonce.u[1] = 0;

ctx->nonce.c[12] = (u8)(mlen>>24);
ctx->nonce.c[13] = (u8)(mlen>>16);
@@ -108,12 +108,8 @@ size_t CRYPTO_cts128_encrypt(const unsigned char *in, unsigned char *out,
(*cbc)(in,out-16,residue,key,ivec,1);
memcpy(out,tmp.c,residue);
#else
{
size_t n;
for (n=0; n<16; n+=sizeof(size_t))
*(size_t *)(tmp.c+n) = 0;
memset(tmp.c,0,sizeof(tmp));
memcpy(tmp.c,in,residue);
}
memcpy(out,out-16,residue);
(*cbc)(tmp.c,out-16,16,key,ivec,1);
#endif
@@ -144,12 +140,8 @@ size_t CRYPTO_nistcts128_encrypt(const unsigned char *in, unsigned char *out,
#if defined(CBC_HANDLES_TRUNCATED_IO)
(*cbc)(in,out-16+residue,residue,key,ivec,1);
#else
{
size_t n;
for (n=0; n<16; n+=sizeof(size_t))
*(size_t *)(tmp.c+n) = 0;
memset(tmp.c,0,sizeof(tmp));
memcpy(tmp.c,in,residue);
}
(*cbc)(tmp.c,out-16+residue,16,key,ivec,1);
#endif
return len+residue;
@@ -177,8 +169,7 @@ size_t CRYPTO_cts128_decrypt_block(const unsigned char *in, unsigned char *out,

(*block)(in,tmp.c+16,key);

for (n=0; n<16; n+=sizeof(size_t))
*(size_t *)(tmp.c+n) = *(size_t *)(tmp.c+16+n);
memcpy(tmp.c,tmp.c+16,16);
memcpy(tmp.c,in+16,residue);
(*block)(tmp.c,tmp.c,key);

@@ -220,8 +211,7 @@ size_t CRYPTO_nistcts128_decrypt_block(const unsigned char *in, unsigned char *o

(*block)(in+residue,tmp.c+16,key);

for (n=0; n<16; n+=sizeof(size_t))
*(size_t *)(tmp.c+n) = *(size_t *)(tmp.c+16+n);
memcpy(tmp.c,tmp.c+16,16);
memcpy(tmp.c,in,residue);
(*block)(tmp.c,tmp.c,key);

@@ -240,7 +230,7 @@ size_t CRYPTO_nistcts128_decrypt_block(const unsigned char *in, unsigned char *o
size_t CRYPTO_cts128_decrypt(const unsigned char *in, unsigned char *out,
size_t len, const void *key,
unsigned char ivec[16], cbc128_f cbc)
{ size_t residue, n;
{ size_t residue;
union { size_t align; unsigned char c[32]; } tmp;

assert (in && out && key && ivec);
@@ -257,8 +247,7 @@ size_t CRYPTO_cts128_decrypt(const unsigned char *in, unsigned char *out,
out += len;
}

for (n=16; n<32; n+=sizeof(size_t))
*(size_t *)(tmp.c+n) = 0;
memset(tmp.c,0,sizeof(tmp));
/* this places in[16] at &tmp.c[16] and decrypted block at &tmp.c[0] */
(*cbc)(in,tmp.c,16,key,tmp.c+16,0);

@@ -275,7 +264,7 @@ size_t CRYPTO_cts128_decrypt(const unsigned char *in, unsigned char *out,
size_t CRYPTO_nistcts128_decrypt(const unsigned char *in, unsigned char *out,
size_t len, const void *key,
unsigned char ivec[16], cbc128_f cbc)
{ size_t residue, n;
{ size_t residue;
union { size_t align; unsigned char c[32]; } tmp;

assert (in && out && key && ivec);
@@ -297,8 +286,7 @@ size_t CRYPTO_nistcts128_decrypt(const unsigned char *in, unsigned char *out,
out += len;
}

for (n=16; n<32; n+=sizeof(size_t))
*(size_t *)(tmp.c+n) = 0;
memset(tmp.c,0,sizeof(tmp));
/* this places in[16] at &tmp.c[16] and decrypted block at &tmp.c[0] */
(*cbc)(in+residue,tmp.c,16,key,tmp.c+16,0);

@@ -941,15 +941,17 @@ int CRYPTO_gcm128_encrypt(GCM128_CONTEXT *ctx,
size_t j=GHASH_CHUNK;

while (j) {
size_t *out_t=(size_t *)out;
const size_t *in_t=(const size_t *)in;

(*block)(ctx->Yi.c,ctx->EKi.c,key);
++ctr;
if (is_endian.little)
PUTU32(ctx->Yi.c+12,ctr);
else
ctx->Yi.d[3] = ctr;
for (i=0; i<16; i+=sizeof(size_t))
*(size_t *)(out+i) =
*(size_t *)(in+i)^*(size_t *)(ctx->EKi.c+i);
for (i=0; i<16/sizeof(size_t); ++i)
out_t[i] = in_t[i] ^ ctx->EKi.t[i];
out += 16;
in += 16;
j -= 16;
@@ -961,15 +963,17 @@ int CRYPTO_gcm128_encrypt(GCM128_CONTEXT *ctx,
size_t j=i;

while (len>=16) {
size_t *out_t=(size_t *)out;
const size_t *in_t=(const size_t *)in;

(*block)(ctx->Yi.c,ctx->EKi.c,key);
++ctr;
if (is_endian.little)
PUTU32(ctx->Yi.c+12,ctr);
else
ctx->Yi.d[3] = ctr;
for (i=0; i<16; i+=sizeof(size_t))
*(size_t *)(out+i) =
*(size_t *)(in+i)^*(size_t *)(ctx->EKi.c+i);
for (i=0; i<16/sizeof(size_t); ++i)
out_t[i] = in_t[i] ^ ctx->EKi.t[i];
out += 16;
in += 16;
len -= 16;
@@ -978,16 +982,18 @@ int CRYPTO_gcm128_encrypt(GCM128_CONTEXT *ctx,
}
#else
while (len>=16) {
size_t *out_t=(size_t *)out;
const size_t *in_t=(const size_t *)in;

(*block)(ctx->Yi.c,ctx->EKi.c,key);
++ctr;
if (is_endian.little)
PUTU32(ctx->Yi.c+12,ctr);
else
ctx->Yi.d[3] = ctr;
for (i=0; i<16; i+=sizeof(size_t))
*(size_t *)(ctx->Xi.c+i) ^=
*(size_t *)(out+i) =
*(size_t *)(in+i)^*(size_t *)(ctx->EKi.c+i);
for (i=0; i<16/sizeof(size_t); ++i)
ctx->Xi.t[i] ^=
out_t[i] = in_t[i]^ctx->EKi.t[i];
GCM_MUL(ctx,Xi);
out += 16;
in += 16;
@@ -1091,15 +1097,17 @@ int CRYPTO_gcm128_decrypt(GCM128_CONTEXT *ctx,

GHASH(ctx,in,GHASH_CHUNK);
while (j) {
size_t *out_t=(size_t *)out;
const size_t *in_t=(const size_t *)in;

(*block)(ctx->Yi.c,ctx->EKi.c,key);
++ctr;
if (is_endian.little)
PUTU32(ctx->Yi.c+12,ctr);
else
ctx->Yi.d[3] = ctr;
for (i=0; i<16; i+=sizeof(size_t))
*(size_t *)(out+i) =
*(size_t *)(in+i)^*(size_t *)(ctx->EKi.c+i);
for (i=0; i<16/sizeof(size_t); ++i)
out_t[i] = in_t[i]^ctx->EKi.t[i];
out += 16;
in += 16;
j -= 16;
@@ -1109,32 +1117,37 @@ int CRYPTO_gcm128_decrypt(GCM128_CONTEXT *ctx,
if ((i = (len&(size_t)-16))) {
GHASH(ctx,in,i);
while (len>=16) {
size_t *out_t=(size_t *)out;
const size_t *in_t=(const size_t *)in;

(*block)(ctx->Yi.c,ctx->EKi.c,key);
++ctr;
if (is_endian.little)
PUTU32(ctx->Yi.c+12,ctr);
else
ctx->Yi.d[3] = ctr;
for (i=0; i<16; i+=sizeof(size_t))
*(size_t *)(out+i) =
*(size_t *)(in+i)^*(size_t *)(ctx->EKi.c+i);
for (i=0; i<16/sizeof(size_t); ++i)
out_t[i] = in_t[i]^ctx->EKi.t[i];
out += 16;
in += 16;
len -= 16;
}
}
#else
while (len>=16) {
size_t *out_t=(size_t *)out;
const size_t *in_t=(const size_t *)in;

(*block)(ctx->Yi.c,ctx->EKi.c,key);
++ctr;
if (is_endian.little)
PUTU32(ctx->Yi.c+12,ctr);
else
ctx->Yi.d[3] = ctr;
for (i=0; i<16; i+=sizeof(size_t)) {
size_t c = *(size_t *)(in+i);
*(size_t *)(out+i) = c^*(size_t *)(ctx->EKi.c+i);
*(size_t *)(ctx->Xi.c+i) ^= c;
for (i=0; i<16/sizeof(size_t); ++i) {
size_t c = in[i];
out[i] = c^ctx->EKi.t[i];
ctx->Xi.t[i] ^= c;
}
GCM_MUL(ctx,Xi);
out += 16;
@@ -1669,6 +1682,46 @@ static const u8 IV18[]={0x93,0x13,0x22,0x5d,0xf8,0x84,0x06,0xe5,0x55,0x90,0x9c,0
0xa2,0x41,0x89,0x97,0x20,0x0e,0xf8,0x2e,0x44,0xae,0x7e,0x3f},
T18[]= {0xa4,0x4a,0x82,0x66,0xee,0x1c,0x8e,0xb0,0xc8,0xb5,0xd4,0xcf,0x5a,0xe9,0xf1,0x9a};

/* Test Case 19 */
#define K19 K1
#define P19 P1
#define IV19 IV1
#define C19 C1
static const u8 A19[]= {0xd9,0x31,0x32,0x25,0xf8,0x84,0x06,0xe5,0xa5,0x59,0x09,0xc5,0xaf,0xf5,0x26,0x9a,
0x86,0xa7,0xa9,0x53,0x15,0x34,0xf7,0xda,0x2e,0x4c,0x30,0x3d,0x8a,0x31,0x8a,0x72,
0x1c,0x3c,0x0c,0x95,0x95,0x68,0x09,0x53,0x2f,0xcf,0x0e,0x24,0x49,0xa6,0xb5,0x25,
0xb1,0x6a,0xed,0xf5,0xaa,0x0d,0xe6,0x57,0xba,0x63,0x7b,0x39,0x1a,0xaf,0xd2,0x55,
0x52,0x2d,0xc1,0xf0,0x99,0x56,0x7d,0x07,0xf4,0x7f,0x37,0xa3,0x2a,0x84,0x42,0x7d,
0x64,0x3a,0x8c,0xdc,0xbf,0xe5,0xc0,0xc9,0x75,0x98,0xa2,0xbd,0x25,0x55,0xd1,0xaa,
0x8c,0xb0,0x8e,0x48,0x59,0x0d,0xbb,0x3d,0xa7,0xb0,0x8b,0x10,0x56,0x82,0x88,0x38,
0xc5,0xf6,0x1e,0x63,0x93,0xba,0x7a,0x0a,0xbc,0xc9,0xf6,0x62,0x89,0x80,0x15,0xad},
T19[]= {0x5f,0xea,0x79,0x3a,0x2d,0x6f,0x97,0x4d,0x37,0xe6,0x8e,0x0c,0xb8,0xff,0x94,0x92};

/* Test Case 20 */
#define K20 K1
#define A20 A1
static const u8 IV20[64]={0xff,0xff,0xff,0xff}, /* this results in 0xff in counter LSB */
P20[288],
C20[]= {0x56,0xb3,0x37,0x3c,0xa9,0xef,0x6e,0x4a,0x2b,0x64,0xfe,0x1e,0x9a,0x17,0xb6,0x14,
0x25,0xf1,0x0d,0x47,0xa7,0x5a,0x5f,0xce,0x13,0xef,0xc6,0xbc,0x78,0x4a,0xf2,0x4f,
0x41,0x41,0xbd,0xd4,0x8c,0xf7,0xc7,0x70,0x88,0x7a,0xfd,0x57,0x3c,0xca,0x54,0x18,
0xa9,0xae,0xff,0xcd,0x7c,0x5c,0xed,0xdf,0xc6,0xa7,0x83,0x97,0xb9,0xa8,0x5b,0x49,
0x9d,0xa5,0x58,0x25,0x72,0x67,0xca,0xab,0x2a,0xd0,0xb2,0x3c,0xa4,0x76,0xa5,0x3c,
0xb1,0x7f,0xb4,0x1c,0x4b,0x8b,0x47,0x5c,0xb4,0xf3,0xf7,0x16,0x50,0x94,0xc2,0x29,
0xc9,0xe8,0xc4,0xdc,0x0a,0x2a,0x5f,0xf1,0x90,0x3e,0x50,0x15,0x11,0x22,0x13,0x76,
0xa1,0xcd,0xb8,0x36,0x4c,0x50,0x61,0xa2,0x0c,0xae,0x74,0xbc,0x4a,0xcd,0x76,0xce,
0xb0,0xab,0xc9,0xfd,0x32,0x17,0xef,0x9f,0x8c,0x90,0xbe,0x40,0x2d,0xdf,0x6d,0x86,
0x97,0xf4,0xf8,0x80,0xdf,0xf1,0x5b,0xfb,0x7a,0x6b,0x28,0x24,0x1e,0xc8,0xfe,0x18,
0x3c,0x2d,0x59,0xe3,0xf9,0xdf,0xff,0x65,0x3c,0x71,0x26,0xf0,0xac,0xb9,0xe6,0x42,
0x11,0xf4,0x2b,0xae,0x12,0xaf,0x46,0x2b,0x10,0x70,0xbe,0xf1,0xab,0x5e,0x36,0x06,
0x87,0x2c,0xa1,0x0d,0xee,0x15,0xb3,0x24,0x9b,0x1a,0x1b,0x95,0x8f,0x23,0x13,0x4c,
0x4b,0xcc,0xb7,0xd0,0x32,0x00,0xbc,0xe4,0x20,0xa2,0xf8,0xeb,0x66,0xdc,0xf3,0x64,
0x4d,0x14,0x23,0xc1,0xb5,0x69,0x90,0x03,0xc1,0x3e,0xce,0xf4,0xbf,0x38,0xa3,0xb6,
0x0e,0xed,0xc3,0x40,0x33,0xba,0xc1,0x90,0x27,0x83,0xdc,0x6d,0x89,0xe2,0xe7,0x74,
0x18,0x8a,0x43,0x9c,0x7e,0xbc,0xc0,0x67,0x2d,0xbd,0xa4,0xdd,0xcf,0xb2,0x79,0x46,
0x13,0xb0,0xbe,0x41,0x31,0x5e,0xf7,0x78,0x70,0x8a,0x70,0xee,0x7d,0x75,0x16,0x5c},
T20[]= {0x8b,0x30,0x7f,0x6b,0x33,0x28,0x6d,0x0a,0xb0,0x26,0xa9,0xed,0x3f,0xe1,0xe8,0x5f};

#define TEST_CASE(n) do { \
u8 out[sizeof(P##n)]; \
AES_set_encrypt_key(K##n,sizeof(K##n)*8,&key); \
@@ -1713,6 +1766,8 @@ int main()
TEST_CASE(16);
TEST_CASE(17);
TEST_CASE(18);
TEST_CASE(19);
TEST_CASE(20);

#ifdef OPENSSL_CPUID_OBJ
{
@@ -1743,11 +1798,16 @@ int main()
ctr_t/(double)sizeof(buf),
(gcm_t-ctr_t)/(double)sizeof(buf));
#ifdef GHASH
GHASH(&ctx,buf.c,sizeof(buf));
{
void (*gcm_ghash_p)(u64 Xi[2],const u128 Htable[16],
const u8 *inp,size_t len) = ctx.ghash;

GHASH((&ctx),buf.c,sizeof(buf));
start = OPENSSL_rdtsc();
for (i=0;i<100;++i) GHASH(&ctx,buf.c,sizeof(buf));
for (i=0;i<100;++i) GHASH((&ctx),buf.c,sizeof(buf));
gcm_t = OPENSSL_rdtsc() - start;
printf("%.2f\n",gcm_t/(double)sizeof(buf)/(double)i);
}
#endif
}
#endif
@@ -29,10 +29,7 @@ typedef unsigned char u8;
#if defined(__i386) || defined(__i386__) || \
defined(__x86_64) || defined(__x86_64__) || \
defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64) || \
defined(__s390__) || defined(__s390x__) || \
( (defined(__arm__) || defined(__arm)) && \
(defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || \
defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__)) )
defined(__s390__) || defined(__s390x__)
# undef STRICT_ALIGNMENT
#endif

@@ -101,8 +98,8 @@ typedef struct { u64 hi,lo; } u128;

struct gcm128_context {
/* Following 6 names follow names in GCM specification */
union { u64 u[2]; u32 d[4]; u8 c[16]; } Yi,EKi,EK0,len,
Xi,H;
union { u64 u[2]; u32 d[4]; u8 c[16]; size_t t[16/sizeof(size_t)]; }
Yi,EKi,EK0,len,Xi,H;
/* Relative position of Xi, H and pre-computed Htable is used
* in some assembler modules, i.e. don't change the order! */
#if TABLE_BITS==8
@@ -25,11 +25,11 @@
* (Prior to 0.9.5a beta1, a different scheme was used: MMNNFFRBB for
* major minor fix final patch/beta)
*/
#define OPENSSL_VERSION_NUMBER 0x1000105fL
#define OPENSSL_VERSION_NUMBER 0x1000106fL
#ifdef OPENSSL_FIPS
#define OPENSSL_VERSION_TEXT "OpenSSL 1.0.1e-fips 11 Feb 2013"
#define OPENSSL_VERSION_TEXT "OpenSSL 1.0.1f-fips 6 Jan 2014"
#else
#define OPENSSL_VERSION_TEXT "OpenSSL 1.0.1e 11 Feb 2013"
#define OPENSSL_VERSION_TEXT "OpenSSL 1.0.1f 6 Jan 2014"
#endif
#define OPENSSL_VERSION_PTEXT " part of " OPENSSL_VERSION_TEXT

@@ -97,33 +97,33 @@
.PROC
.CALLINFO NO_CALLS
.ENTRY
cmpib,*= 0,$len,Ldone
cmpib,*= 0,$len,L\$done
nop
cmpib,*>>= 15,$len,Little
cmpib,*>>= 15,$len,L\$ittle
ldi $SIZE_T-1,%r1

Lalign
L\$align
and,*<> $inp,%r1,%r28
b,n Laligned
b,n L\$aligned
stb %r0,0($inp)
ldo -1($len),$len
b Lalign
b L\$align
ldo 1($inp),$inp

Laligned
L\$aligned
andcm $len,%r1,%r28
Lot
L\$ot
$ST %r0,0($inp)
addib,*<> -$SIZE_T,%r28,Lot
addib,*<> -$SIZE_T,%r28,L\$ot
ldo $SIZE_T($inp),$inp

and,*<> $len,%r1,$len
b,n Ldone
Little
b,n L\$done
L\$ittle
stb %r0,0($inp)
addib,*<> -1,$len,Little
addib,*<> -1,$len,L\$ittle
ldo 1($inp),$inp
Ldone
L\$done
bv ($rp)
.EXIT
nop
@@ -151,7 +151,7 @@
ldw 0($out),$tick
add $diff,$tick,$tick
stw $tick,0($out)
Loop
L\$oop
mfctl %cr16,$tick
sub $tick,$lasttick,$diff
copy $tick,$lasttick
@@ -161,7 +161,7 @@
add $diff,$tick,$tick
stw $tick,0($out)

addib,<> -1,$cnt,Loop
addib,<> -1,$cnt,L\$oop
addi 4,$out,$out

bv ($rp)
@@ -190,14 +190,14 @@
mfctl %cr16,$tick
sub $tick,$lasttick,$diff
copy $tick,$lasttick
Loop2
L\$oop2
copy $diff,$lastdiff
fdc 0($out)
ldw 0($out),$tick
add $diff,$tick,$tick
stw $tick,0($out)

addib,= -1,$max,Ldone2
addib,= -1,$max,L\$done2
nop

mfctl %cr16,$tick
@@ -208,17 +208,18 @@

ldi 1,%r1
xor %r1,$tick,$tick
addb,<> $tick,$cnt,Loop2
addb,<> $tick,$cnt,L\$oop2
shladd,l $tick,2,$out,$out
Ldone2
L\$done2
bv ($rp)
.EXIT
add $rv,$cnt,$rv
.PROCEND
___
}
$code =~ s/cmpib,\*/comib,/gm if ($SIZE_T==4);
$code =~ s/,\*/,/gm if ($SIZE_T==4);
$code =~ s/cmpib,\*/comib,/gm if ($SIZE_T==4);
$code =~ s/,\*/,/gm if ($SIZE_T==4);
$code =~ s/\bbv\b/bve/gm if ($SIZE_T==8);
print $code;
close STDOUT;

@@ -167,6 +167,7 @@ STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pe
#ifndef OPENSSL_NO_RSA
if (strcmp(name,PEM_STRING_RSA) == 0)
{
d2i=(D2I_OF(void))d2i_RSAPrivateKey;
if (xi->x_pkey != NULL)
{
if (!sk_X509_INFO_push(ret,xi)) goto err;
@@ -80,7 +80,7 @@ sub ::file
IF \@Version LT 800
ECHO MASM version 8.00 or later is strongly recommended.
ENDIF
.686
.486
.MODEL FLAT
OPTION DOTNAME
IF \@Version LT 800
@@ -90,7 +90,14 @@ PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert,

/* Set defaults */
if (!nid_cert)
{
#ifdef OPENSSL_FIPS
if (FIPS_mode())
nid_cert = NID_pbe_WithSHA1And3_Key_TripleDES_CBC;
else
#endif
nid_cert = NID_pbe_WithSHA1And40BitRC2_CBC;
}
if (!nid_key)
nid_key = NID_pbe_WithSHA1And3_Key_TripleDES_CBC;
if (!iter)
@@ -380,8 +380,11 @@ static int ssleay_rand_bytes(unsigned char *buf, int num, int pseudo)
* are fed into the hash function and the results are kept in the
* global 'md'.
*/

CRYPTO_w_lock(CRYPTO_LOCK_RAND);
#ifdef OPENSSL_FIPS
/* NB: in FIPS mode we are already under a lock */
if (!FIPS_mode())
#endif
CRYPTO_w_lock(CRYPTO_LOCK_RAND);

/* prevent ssleay_rand_bytes() from trying to obtain the lock again */
CRYPTO_w_lock(CRYPTO_LOCK_RAND2);
@@ -460,7 +463,10 @@ static int ssleay_rand_bytes(unsigned char *buf, int num, int pseudo)

/* before unlocking, we must clear 'crypto_lock_rand' */
crypto_lock_rand = 0;
CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
#ifdef OPENSSL_FIPS
if (!FIPS_mode())
#endif
CRYPTO_w_unlock(CRYPTO_LOCK_RAND);

while (num > 0)
{
@@ -512,10 +518,16 @@ static int ssleay_rand_bytes(unsigned char *buf, int num, int pseudo)
MD_Init(&m);
MD_Update(&m,(unsigned char *)&(md_c[0]),sizeof(md_c));
MD_Update(&m,local_md,MD_DIGEST_LENGTH);
CRYPTO_w_lock(CRYPTO_LOCK_RAND);
#ifdef OPENSSL_FIPS
if (!FIPS_mode())
#endif
CRYPTO_w_lock(CRYPTO_LOCK_RAND);
MD_Update(&m,md,MD_DIGEST_LENGTH);
MD_Final(&m,md);
CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
#ifdef OPENSSL_FIPS
if (!FIPS_mode())
#endif
CRYPTO_w_unlock(CRYPTO_LOCK_RAND);

EVP_MD_CTX_cleanup(&m);
if (ok)
@@ -138,6 +138,7 @@ void ERR_load_RAND_strings(void);
#define RAND_F_SSLEAY_RAND_BYTES 100

/* Reason codes. */
#define RAND_R_DUAL_EC_DRBG_DISABLED 104
#define RAND_R_ERROR_INITIALISING_DRBG 102
#define RAND_R_ERROR_INSTANTIATING_DRBG 103
#define RAND_R_NO_FIPS_RANDOM_METHOD_SET 101
@@ -78,6 +78,7 @@ static ERR_STRING_DATA RAND_str_functs[]=

static ERR_STRING_DATA RAND_str_reasons[]=
{
{ERR_REASON(RAND_R_DUAL_EC_DRBG_DISABLED),"dual ec drbg disabled"},
{ERR_REASON(RAND_R_ERROR_INITIALISING_DRBG),"error initialising drbg"},
{ERR_REASON(RAND_R_ERROR_INSTANTIATING_DRBG),"error instantiating drbg"},
{ERR_REASON(RAND_R_NO_FIPS_RANDOM_METHOD_SET),"no fips random method set"},
@@ -269,6 +269,14 @@ int RAND_init_fips(void)
DRBG_CTX *dctx;
size_t plen;
unsigned char pers[32], *p;
#ifndef OPENSSL_ALLOW_DUAL_EC_DRBG
if (fips_drbg_type >> 16)
{
RANDerr(RAND_F_RAND_INIT_FIPS, RAND_R_DUAL_EC_DRBG_DISABLED);
return 0;
}
#endif

dctx = FIPS_get_default_drbg();
if (FIPS_drbg_init(dctx, fips_drbg_type, fips_drbg_flags) <= 0)
{
@@ -307,7 +307,8 @@ sub foldedloop {
.STRINGZ "RC4 for PA-RISC, CRYPTOGAMS by <appro\@openssl.org>"
___
$code =~ s/\`([^\`]*)\`/eval $1/gem;
$code =~ s/cmpib,\*/comib,/gm if ($SIZE_T==4);
$code =~ s/cmpib,\*/comib,/gm if ($SIZE_T==4);
$code =~ s/\bbv\b/bve/gm if ($SIZE_T==8);

print $code;
close STDOUT;
@@ -351,27 +351,27 @@ static int rsa_pss_param_print(BIO *bp, RSA_PSS_PARAMS *pss,

if (!BIO_indent(bp, indent, 128))
goto err;
if (BIO_puts(bp, "Salt Length: ") <= 0)
if (BIO_puts(bp, "Salt Length: 0x") <= 0)
goto err;
if (pss->saltLength)
{
if (i2a_ASN1_INTEGER(bp, pss->saltLength) <= 0)
goto err;
}
else if (BIO_puts(bp, "20 (default)") <= 0)
else if (BIO_puts(bp, "0x14 (default)") <= 0)
goto err;
BIO_puts(bp, "\n");

if (!BIO_indent(bp, indent, 128))
goto err;
if (BIO_puts(bp, "Trailer Field: ") <= 0)
if (BIO_puts(bp, "Trailer Field: 0x") <= 0)
goto err;
if (pss->trailerField)
{
if (i2a_ASN1_INTEGER(bp, pss->trailerField) <= 0)
goto err;
}
else if (BIO_puts(bp, "0xbc (default)") <= 0)
else if (BIO_puts(bp, "BC (default)") <= 0)
goto err;
BIO_puts(bp, "\n");

@@ -59,6 +59,12 @@ int RSA_check_key(const RSA *key)
BN_CTX *ctx;
int r;
int ret=1;

if (!key->p || !key->q || !key->n || !key->e || !key->d)
{
RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_VALUE_MISSING);
return 0;
}

i = BN_new();
j = BN_new();
@@ -611,6 +611,8 @@ static int pkey_rsa_ctrl_str(EVP_PKEY_CTX *ctx,
pm = RSA_NO_PADDING;
else if (!strcmp(value, "oeap"))
pm = RSA_PKCS1_OAEP_PADDING;
else if (!strcmp(value, "oaep"))
pm = RSA_PKCS1_OAEP_PADDING;
else if (!strcmp(value, "x931"))
pm = RSA_X931_PADDING;
else if (!strcmp(value, "pss"))
@@ -60,7 +60,9 @@ sha256-armv4.S: asm/sha256-armv4.pl
$(PERL) $< $(PERLASM_SCHEME) $@

sha1-alpha.s: asm/sha1-alpha.pl
$(PERL) $< | $(CC) -E - | tee $@ > /dev/null
(preproc=/tmp/$$$$.$@; trap "rm $$preproc" INT; \
$(PERL) asm/sha1-alpha.pl > $$preproc && \
$(CC) -E $$preproc > $@ && rm $$preproc)

# Solaris make has to be explicitly told
sha1-x86_64.s: asm/sha1-x86_64.pl; $(PERL) asm/sha1-x86_64.pl $(PERLASM_SCHEME) > $@
@@ -254,6 +254,7 @@ sub BODY_40_59 {
___

$code =~ s/\`([^\`]*)\`/eval $1/gem;
$code =~ s/,\*/,/gm if ($SIZE_T==4);
$code =~ s/,\*/,/gm if ($SIZE_T==4);
$code =~ s/\bbv\b/bve/gm if ($SIZE_T==8);
print $code;
close STDOUT;
@@ -745,7 +745,7 @@ ()
mov %rdi,$ctx # reassigned argument
mov %rsi,$inp # reassigned argument
mov %rdx,$num # reassigned argument
vzeroall
vzeroupper

shl \$6,$num
add $inp,$num
@@ -1038,7 +1038,7 @@ ()
&Xtail_avx(\&body_20_39);

$code.=<<___;
vzeroall
vzeroupper

add 0($ctx),$A # update context
add 4($ctx),@T[0]