forked from wolfSSL/wolfssl
prunning on ctaocrypt files
This commit is contained in:
@ -72,11 +72,6 @@ include support/include.am
|
||||
include wolfcrypt/benchmark/include.am
|
||||
include wolfcrypt/src/include.am
|
||||
include wolfcrypt/test/include.am
|
||||
|
||||
if BUILD_FIPS
|
||||
include ctaocrypt/src/include.am
|
||||
endif
|
||||
|
||||
include examples/client/include.am
|
||||
include examples/server/include.am
|
||||
include examples/echoclient/include.am
|
||||
|
@ -1,972 +0,0 @@
|
||||
; /*aes_asm . asm
|
||||
; *
|
||||
; *Copyright[C]2006 -2014 wolfSSL Inc .
|
||||
; *
|
||||
; *This file is part of CyaSSL .
|
||||
; *
|
||||
; *CyaSSL is free software/ you can redistribute it and/or modify
|
||||
; *it under the terms of the GNU General Public License as published by
|
||||
; *the Free Software Foundation/ either version 2 of the License, or
|
||||
; *[at your option]any later version .
|
||||
; *
|
||||
; *CyaSSL ,is distributed in the hope that it will be useful
|
||||
; *but WITHOUT ANY WARRANTY/ without even the implied warranty of
|
||||
; *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
|
||||
; *GNU General Public License for more details .
|
||||
; *
|
||||
; *You should have received a copy of the GNU General Public License
|
||||
; *along with this program/ if not, write to the Free Software
|
||||
; *Foundation,Inc .,51 Franklin Street,Fifth Floor,Boston,MA 02110-1301,USA
|
||||
; */
|
||||
;
|
||||
;
|
||||
; /*See IntelA dvanced Encryption Standard[AES]Instructions Set White Paper
|
||||
; *by Israel,Intel Mobility Group Development Center,Israel Shay Gueron
|
||||
; */
|
||||
;
|
||||
; /* This file is in intel asm syntax, see .s for at&t syntax */
|
||||
;
|
||||
; /*
|
||||
; AES_CBC_encrypt[const ,unsigned char*in
|
||||
; unsigned ,char*out
|
||||
; unsigned ,char ivec+16
|
||||
; unsigned ,long length
|
||||
; const ,unsigned char*KS
|
||||
; int nr]
|
||||
; */
|
||||
_text SEGMENT
|
||||
AES_CBC_encrypt PROC
|
||||
;# parameter 1: rdi
|
||||
;# parameter 2: rsi
|
||||
;# parameter 3: rdx
|
||||
;# parameter 4: rcx
|
||||
;# parameter 5: r8
|
||||
;# parameter 6: r9d
|
||||
|
||||
; save rdi and rsi to rax and r11, restore before ret
|
||||
mov rax,rdi
|
||||
mov r11,rsi
|
||||
|
||||
; convert to what we had for att&t convention
|
||||
mov rdi,rcx
|
||||
mov rsi,rdx
|
||||
mov rdx,r8
|
||||
mov rcx,r9
|
||||
mov r8,[rsp+40]
|
||||
mov r9d,[rsp+48]
|
||||
|
||||
mov r10,rcx
|
||||
shr rcx,4
|
||||
shl r10,60
|
||||
je NO_PARTS
|
||||
add rcx,1
|
||||
NO_PARTS:
|
||||
sub rsi,16
|
||||
movdqa xmm1,[rdx]
|
||||
LOOP_1:
|
||||
pxor xmm1,[rdi]
|
||||
pxor xmm1,[r8]
|
||||
add rsi,16
|
||||
add rdi,16
|
||||
cmp r9d,12
|
||||
aesenc xmm1,16[r8]
|
||||
aesenc xmm1,32[r8]
|
||||
aesenc xmm1,48[r8]
|
||||
aesenc xmm1,64[r8]
|
||||
aesenc xmm1,80[r8]
|
||||
aesenc xmm1,96[r8]
|
||||
aesenc xmm1,112[r8]
|
||||
aesenc xmm1,128[r8]
|
||||
aesenc xmm1,144[r8]
|
||||
movdqa xmm2,160[r8]
|
||||
jb LAST
|
||||
cmp r9d,14
|
||||
|
||||
aesenc xmm1,160[r8]
|
||||
aesenc xmm1,176[r8]
|
||||
movdqa xmm2,192[r8]
|
||||
jb LAST
|
||||
aesenc xmm1,192[r8]
|
||||
aesenc xmm1,208[r8]
|
||||
movdqa xmm2,224[r8]
|
||||
LAST:
|
||||
dec rcx
|
||||
aesenclast xmm1,xmm2
|
||||
movdqu [rsi],xmm1
|
||||
jne LOOP_1
|
||||
; restore non volatile rdi,rsi
|
||||
mov rdi,rax
|
||||
mov rsi,r11
|
||||
ret
|
||||
AES_CBC_encrypt ENDP
|
||||
|
||||
|
||||
|
||||
; /*
|
||||
; AES_CBC_decrypt[const ,unsigned char*in
|
||||
; unsigned ,char*out
|
||||
; unsigned ,char ivec+16
|
||||
; unsigned ,long length
|
||||
; const ,unsigned char*KS
|
||||
; int nr]
|
||||
; */
|
||||
; . globl AES_CBC_decrypt
|
||||
AES_CBC_decrypt PROC
|
||||
;# parameter 1: rdi
|
||||
;# parameter 2: rsi
|
||||
;# parameter 3: rdx
|
||||
;# parameter 4: rcx
|
||||
;# parameter 5: r8
|
||||
;# parameter 6: r9d
|
||||
|
||||
; save rdi and rsi to rax and r11, restore before ret
|
||||
mov rax,rdi
|
||||
mov r11,rsi
|
||||
|
||||
; convert to what we had for att&t convention
|
||||
mov rdi,rcx
|
||||
mov rsi,rdx
|
||||
mov rdx,r8
|
||||
mov rcx,r9
|
||||
mov r8,[rsp+40]
|
||||
mov r9d,[rsp+48]
|
||||
|
||||
; on microsoft xmm6-xmm15 are non volaitle, let's save on stack and restore at end
|
||||
sub rsp,8+8*16 ; 8 = align stack , 8 xmm6-12,15 16 bytes each
|
||||
movdqa [rsp+0], xmm6
|
||||
movdqa [rsp+16], xmm7
|
||||
movdqa [rsp+32], xmm8
|
||||
movdqa [rsp+48], xmm9
|
||||
movdqa [rsp+64], xmm10
|
||||
movdqa [rsp+80], xmm11
|
||||
movdqa [rsp+96], xmm12
|
||||
movdqa [rsp+112], xmm15
|
||||
|
||||
mov r10,rcx
|
||||
shr rcx,4
|
||||
shl r10,60
|
||||
je DNO_PARTS_4
|
||||
add rcx,1
|
||||
DNO_PARTS_4:
|
||||
mov r10,rcx
|
||||
shl r10,62
|
||||
shr r10,62
|
||||
shr rcx,2
|
||||
movdqu xmm5,[rdx]
|
||||
je DREMAINDER_4
|
||||
sub rsi,64
|
||||
DLOOP_4:
|
||||
movdqu xmm1,[rdi]
|
||||
movdqu xmm2,16[rdi]
|
||||
movdqu xmm3,32[rdi]
|
||||
movdqu xmm4,48[rdi]
|
||||
movdqa xmm6,xmm1
|
||||
movdqa xmm7,xmm2
|
||||
movdqa xmm8,xmm3
|
||||
movdqa xmm15,xmm4
|
||||
movdqa xmm9,[r8]
|
||||
movdqa xmm10,16[r8]
|
||||
movdqa xmm11,32[r8]
|
||||
movdqa xmm12,48[r8]
|
||||
pxor xmm1,xmm9
|
||||
pxor xmm2,xmm9
|
||||
pxor xmm3,xmm9
|
||||
|
||||
pxor xmm4,xmm9
|
||||
aesdec xmm1,xmm10
|
||||
aesdec xmm2,xmm10
|
||||
aesdec xmm3,xmm10
|
||||
aesdec xmm4,xmm10
|
||||
aesdec xmm1,xmm11
|
||||
aesdec xmm2,xmm11
|
||||
aesdec xmm3,xmm11
|
||||
aesdec xmm4,xmm11
|
||||
aesdec xmm1,xmm12
|
||||
aesdec xmm2,xmm12
|
||||
aesdec xmm3,xmm12
|
||||
aesdec xmm4,xmm12
|
||||
movdqa xmm9,64[r8]
|
||||
movdqa xmm10,80[r8]
|
||||
movdqa xmm11,96[r8]
|
||||
movdqa xmm12,112[r8]
|
||||
aesdec xmm1,xmm9
|
||||
aesdec xmm2,xmm9
|
||||
aesdec xmm3,xmm9
|
||||
aesdec xmm4,xmm9
|
||||
aesdec xmm1,xmm10
|
||||
aesdec xmm2,xmm10
|
||||
aesdec xmm3,xmm10
|
||||
aesdec xmm4,xmm10
|
||||
aesdec xmm1,xmm11
|
||||
aesdec xmm2,xmm11
|
||||
aesdec xmm3,xmm11
|
||||
aesdec xmm4,xmm11
|
||||
aesdec xmm1,xmm12
|
||||
aesdec xmm2,xmm12
|
||||
aesdec xmm3,xmm12
|
||||
aesdec xmm4,xmm12
|
||||
movdqa xmm9,128[r8]
|
||||
movdqa xmm10,144[r8]
|
||||
movdqa xmm11,160[r8]
|
||||
cmp r9d,12
|
||||
aesdec xmm1,xmm9
|
||||
aesdec xmm2,xmm9
|
||||
aesdec xmm3,xmm9
|
||||
aesdec xmm4,xmm9
|
||||
aesdec xmm1,xmm10
|
||||
aesdec xmm2,xmm10
|
||||
aesdec xmm3,xmm10
|
||||
aesdec xmm4,xmm10
|
||||
jb DLAST_4
|
||||
movdqa xmm9,160[r8]
|
||||
movdqa xmm10,176[r8]
|
||||
movdqa xmm11,192[r8]
|
||||
cmp r9d,14
|
||||
aesdec xmm1,xmm9
|
||||
aesdec xmm2,xmm9
|
||||
aesdec xmm3,xmm9
|
||||
aesdec xmm4,xmm9
|
||||
aesdec xmm1,xmm10
|
||||
aesdec xmm2,xmm10
|
||||
aesdec xmm3,xmm10
|
||||
aesdec xmm4,xmm10
|
||||
jb DLAST_4
|
||||
|
||||
movdqa xmm9,192[r8]
|
||||
movdqa xmm10,208[r8]
|
||||
movdqa xmm11,224[r8]
|
||||
aesdec xmm1,xmm9
|
||||
aesdec xmm2,xmm9
|
||||
aesdec xmm3,xmm9
|
||||
aesdec xmm4,xmm9
|
||||
aesdec xmm1,xmm10
|
||||
aesdec xmm2,xmm10
|
||||
aesdec xmm3,xmm10
|
||||
aesdec xmm4,xmm10
|
||||
DLAST_4:
|
||||
add rdi,64
|
||||
add rsi,64
|
||||
dec rcx
|
||||
aesdeclast xmm1,xmm11
|
||||
aesdeclast xmm2,xmm11
|
||||
aesdeclast xmm3,xmm11
|
||||
aesdeclast xmm4,xmm11
|
||||
pxor xmm1,xmm5
|
||||
pxor xmm2,xmm6
|
||||
pxor xmm3,xmm7
|
||||
pxor xmm4,xmm8
|
||||
movdqu [rsi],xmm1
|
||||
movdqu 16[rsi],xmm2
|
||||
movdqu 32[rsi],xmm3
|
||||
movdqu 48[rsi],xmm4
|
||||
movdqa xmm5,xmm15
|
||||
jne DLOOP_4
|
||||
add rsi,64
|
||||
DREMAINDER_4:
|
||||
cmp r10,0
|
||||
je DEND_4
|
||||
DLOOP_4_2:
|
||||
movdqu xmm1,[rdi]
|
||||
movdqa xmm15,xmm1
|
||||
add rdi,16
|
||||
pxor xmm1,[r8]
|
||||
movdqu xmm2,160[r8]
|
||||
cmp r9d,12
|
||||
aesdec xmm1,16[r8]
|
||||
aesdec xmm1,32[r8]
|
||||
aesdec xmm1,48[r8]
|
||||
aesdec xmm1,64[r8]
|
||||
aesdec xmm1,80[r8]
|
||||
aesdec xmm1,96[r8]
|
||||
aesdec xmm1,112[r8]
|
||||
aesdec xmm1,128[r8]
|
||||
aesdec xmm1,144[r8]
|
||||
jb DLAST_4_2
|
||||
movdqu xmm2,192[r8]
|
||||
cmp r9d,14
|
||||
aesdec xmm1,160[r8]
|
||||
aesdec xmm1,176[r8]
|
||||
jb DLAST_4_2
|
||||
movdqu xmm2,224[r8]
|
||||
aesdec xmm1,192[r8]
|
||||
aesdec xmm1,208[r8]
|
||||
DLAST_4_2:
|
||||
aesdeclast xmm1,xmm2
|
||||
pxor xmm1,xmm5
|
||||
movdqa xmm5,xmm15
|
||||
movdqu [rsi],xmm1
|
||||
|
||||
add rsi,16
|
||||
dec r10
|
||||
jne DLOOP_4_2
|
||||
DEND_4:
|
||||
; restore non volatile rdi,rsi
|
||||
mov rdi,rax
|
||||
mov rsi,r11
|
||||
; restore non volatile xmms from stack
|
||||
movdqa xmm6, [rsp+0]
|
||||
movdqa xmm7, [rsp+16]
|
||||
movdqa xmm8, [rsp+32]
|
||||
movdqa xmm9, [rsp+48]
|
||||
movdqa xmm10, [rsp+64]
|
||||
movdqa xmm11, [rsp+80]
|
||||
movdqa xmm12, [rsp+96]
|
||||
movdqa xmm15, [rsp+112]
|
||||
add rsp,8+8*16 ; 8 = align stack , 8 xmm6-12,15 16 bytes each
|
||||
ret
|
||||
AES_CBC_decrypt ENDP
|
||||
|
||||
; /*
|
||||
; AES_ECB_encrypt[const ,unsigned char*in
|
||||
; unsigned ,char*out
|
||||
; unsigned ,long length
|
||||
; const ,unsigned char*KS
|
||||
; int nr]
|
||||
; */
|
||||
; . globl AES_ECB_encrypt
|
||||
AES_ECB_encrypt PROC
|
||||
;# parameter 1: rdi
|
||||
;# parameter 2: rsi
|
||||
;# parameter 3: rdx
|
||||
;# parameter 4: rcx
|
||||
;# parameter 5: r8d
|
||||
|
||||
; save rdi and rsi to rax and r11, restore before ret
|
||||
mov rax,rdi
|
||||
mov r11,rsi
|
||||
|
||||
; convert to what we had for att&t convention
|
||||
mov rdi,rcx
|
||||
mov rsi,rdx
|
||||
mov rdx,r8
|
||||
mov rcx,r9
|
||||
mov r8d,[rsp+40]
|
||||
|
||||
; on microsoft xmm6-xmm15 are non volaitle, let's save on stack and restore at end
|
||||
sub rsp,8+4*16 ; 8 = align stack , 4 xmm9-12, 16 bytes each
|
||||
movdqa [rsp+0], xmm9
|
||||
movdqa [rsp+16], xmm10
|
||||
movdqa [rsp+32], xmm11
|
||||
movdqa [rsp+48], xmm12
|
||||
|
||||
|
||||
mov r10,rdx
|
||||
shr rdx,4
|
||||
shl r10,60
|
||||
je EECB_NO_PARTS_4
|
||||
add rdx,1
|
||||
EECB_NO_PARTS_4:
|
||||
mov r10,rdx
|
||||
shl r10,62
|
||||
shr r10,62
|
||||
shr rdx,2
|
||||
je EECB_REMAINDER_4
|
||||
sub rsi,64
|
||||
EECB_LOOP_4:
|
||||
movdqu xmm1,[rdi]
|
||||
movdqu xmm2,16[rdi]
|
||||
movdqu xmm3,32[rdi]
|
||||
movdqu xmm4,48[rdi]
|
||||
movdqa xmm9,[rcx]
|
||||
movdqa xmm10,16[rcx]
|
||||
movdqa xmm11,32[rcx]
|
||||
movdqa xmm12,48[rcx]
|
||||
pxor xmm1,xmm9
|
||||
pxor xmm2,xmm9
|
||||
pxor xmm3,xmm9
|
||||
pxor xmm4,xmm9
|
||||
aesenc xmm1,xmm10
|
||||
aesenc xmm2,xmm10
|
||||
aesenc xmm3,xmm10
|
||||
aesenc xmm4,xmm10
|
||||
aesenc xmm1,xmm11
|
||||
aesenc xmm2,xmm11
|
||||
aesenc xmm3,xmm11
|
||||
aesenc xmm4,xmm11
|
||||
aesenc xmm1,xmm12
|
||||
aesenc xmm2,xmm12
|
||||
aesenc xmm3,xmm12
|
||||
aesenc xmm4,xmm12
|
||||
movdqa xmm9,64[rcx]
|
||||
movdqa xmm10,80[rcx]
|
||||
movdqa xmm11,96[rcx]
|
||||
movdqa xmm12,112[rcx]
|
||||
aesenc xmm1,xmm9
|
||||
aesenc xmm2,xmm9
|
||||
aesenc xmm3,xmm9
|
||||
aesenc xmm4,xmm9
|
||||
aesenc xmm1,xmm10
|
||||
aesenc xmm2,xmm10
|
||||
aesenc xmm3,xmm10
|
||||
aesenc xmm4,xmm10
|
||||
aesenc xmm1,xmm11
|
||||
aesenc xmm2,xmm11
|
||||
aesenc xmm3,xmm11
|
||||
aesenc xmm4,xmm11
|
||||
aesenc xmm1,xmm12
|
||||
aesenc xmm2,xmm12
|
||||
aesenc xmm3,xmm12
|
||||
aesenc xmm4,xmm12
|
||||
movdqa xmm9,128[rcx]
|
||||
movdqa xmm10,144[rcx]
|
||||
movdqa xmm11,160[rcx]
|
||||
cmp r8d,12
|
||||
aesenc xmm1,xmm9
|
||||
aesenc xmm2,xmm9
|
||||
aesenc xmm3,xmm9
|
||||
aesenc xmm4,xmm9
|
||||
aesenc xmm1,xmm10
|
||||
aesenc xmm2,xmm10
|
||||
aesenc xmm3,xmm10
|
||||
aesenc xmm4,xmm10
|
||||
jb EECB_LAST_4
|
||||
movdqa xmm9,160[rcx]
|
||||
movdqa xmm10,176[rcx]
|
||||
movdqa xmm11,192[rcx]
|
||||
cmp r8d,14
|
||||
aesenc xmm1,xmm9
|
||||
aesenc xmm2,xmm9
|
||||
aesenc xmm3,xmm9
|
||||
aesenc xmm4,xmm9
|
||||
aesenc xmm1,xmm10
|
||||
aesenc xmm2,xmm10
|
||||
aesenc xmm3,xmm10
|
||||
aesenc xmm4,xmm10
|
||||
jb EECB_LAST_4
|
||||
movdqa xmm9,192[rcx]
|
||||
movdqa xmm10,208[rcx]
|
||||
movdqa xmm11,224[rcx]
|
||||
aesenc xmm1,xmm9
|
||||
aesenc xmm2,xmm9
|
||||
aesenc xmm3,xmm9
|
||||
aesenc xmm4,xmm9
|
||||
aesenc xmm1,xmm10
|
||||
aesenc xmm2,xmm10
|
||||
aesenc xmm3,xmm10
|
||||
aesenc xmm4,xmm10
|
||||
EECB_LAST_4:
|
||||
add rdi,64
|
||||
add rsi,64
|
||||
dec rdx
|
||||
aesenclast xmm1,xmm11
|
||||
aesenclast xmm2,xmm11
|
||||
aesenclast xmm3,xmm11
|
||||
aesenclast xmm4,xmm11
|
||||
movdqu [rsi],xmm1
|
||||
movdqu 16[rsi],xmm2
|
||||
movdqu 32[rsi],xmm3
|
||||
movdqu 48[rsi],xmm4
|
||||
jne EECB_LOOP_4
|
||||
add rsi,64
|
||||
EECB_REMAINDER_4:
|
||||
cmp r10,0
|
||||
je EECB_END_4
|
||||
EECB_LOOP_4_2:
|
||||
movdqu xmm1,[rdi]
|
||||
add rdi,16
|
||||
pxor xmm1,[rcx]
|
||||
movdqu xmm2,160[rcx]
|
||||
aesenc xmm1,16[rcx]
|
||||
aesenc xmm1,32[rcx]
|
||||
aesenc xmm1,48[rcx]
|
||||
aesenc xmm1,64[rcx]
|
||||
aesenc xmm1,80[rcx]
|
||||
aesenc xmm1,96[rcx]
|
||||
aesenc xmm1,112[rcx]
|
||||
aesenc xmm1,128[rcx]
|
||||
aesenc xmm1,144[rcx]
|
||||
cmp r8d,12
|
||||
jb EECB_LAST_4_2
|
||||
movdqu xmm2,192[rcx]
|
||||
aesenc xmm1,160[rcx]
|
||||
aesenc xmm1,176[rcx]
|
||||
cmp r8d,14
|
||||
jb EECB_LAST_4_2
|
||||
movdqu xmm2,224[rcx]
|
||||
aesenc xmm1,192[rcx]
|
||||
aesenc xmm1,208[rcx]
|
||||
EECB_LAST_4_2:
|
||||
aesenclast xmm1,xmm2
|
||||
movdqu [rsi],xmm1
|
||||
add rsi,16
|
||||
dec r10
|
||||
jne EECB_LOOP_4_2
|
||||
EECB_END_4:
|
||||
; restore non volatile rdi,rsi
|
||||
mov rdi,rax
|
||||
mov rsi,r11
|
||||
; restore non volatile xmms from stack
|
||||
movdqa xmm9, [rsp+0]
|
||||
movdqa xmm10, [rsp+16]
|
||||
movdqa xmm11, [rsp+32]
|
||||
movdqa xmm12, [rsp+48]
|
||||
add rsp,8+4*16 ; 8 = align stack , 4 xmm9-12 16 bytes each
|
||||
ret
|
||||
AES_ECB_encrypt ENDP
|
||||
|
||||
; /*
|
||||
; AES_ECB_decrypt[const ,unsigned char*in
|
||||
; unsigned ,char*out
|
||||
; unsigned ,long length
|
||||
; const ,unsigned char*KS
|
||||
; int nr]
|
||||
; */
|
||||
; . globl AES_ECB_decrypt
|
||||
AES_ECB_decrypt PROC
|
||||
;# parameter 1: rdi
|
||||
;# parameter 2: rsi
|
||||
;# parameter 3: rdx
|
||||
;# parameter 4: rcx
|
||||
;# parameter 5: r8d
|
||||
|
||||
; save rdi and rsi to rax and r11, restore before ret
|
||||
mov rax,rdi
|
||||
mov r11,rsi
|
||||
|
||||
; convert to what we had for att&t convention
|
||||
mov rdi,rcx
|
||||
mov rsi,rdx
|
||||
mov rdx,r8
|
||||
mov rcx,r9
|
||||
mov r8d,[rsp+40]
|
||||
|
||||
; on microsoft xmm6-xmm15 are non volaitle, let's save on stack and restore at end
|
||||
sub rsp,8+4*16 ; 8 = align stack , 4 xmm9-12, 16 bytes each
|
||||
movdqa [rsp+0], xmm9
|
||||
movdqa [rsp+16], xmm10
|
||||
movdqa [rsp+32], xmm11
|
||||
movdqa [rsp+48], xmm12
|
||||
|
||||
mov r10,rdx
|
||||
shr rdx,4
|
||||
shl r10,60
|
||||
je DECB_NO_PARTS_4
|
||||
add rdx,1
|
||||
DECB_NO_PARTS_4:
|
||||
mov r10,rdx
|
||||
shl r10,62
|
||||
shr r10,62
|
||||
shr rdx,2
|
||||
je DECB_REMAINDER_4
|
||||
sub rsi,64
|
||||
DECB_LOOP_4:
|
||||
movdqu xmm1,[rdi]
|
||||
movdqu xmm2,16[rdi]
|
||||
movdqu xmm3,32[rdi]
|
||||
movdqu xmm4,48[rdi]
|
||||
movdqa xmm9,[rcx]
|
||||
movdqa xmm10,16[rcx]
|
||||
movdqa xmm11,32[rcx]
|
||||
movdqa xmm12,48[rcx]
|
||||
pxor xmm1,xmm9
|
||||
pxor xmm2,xmm9
|
||||
pxor xmm3,xmm9
|
||||
pxor xmm4,xmm9
|
||||
aesdec xmm1,xmm10
|
||||
aesdec xmm2,xmm10
|
||||
aesdec xmm3,xmm10
|
||||
aesdec xmm4,xmm10
|
||||
aesdec xmm1,xmm11
|
||||
aesdec xmm2,xmm11
|
||||
aesdec xmm3,xmm11
|
||||
aesdec xmm4,xmm11
|
||||
aesdec xmm1,xmm12
|
||||
aesdec xmm2,xmm12
|
||||
aesdec xmm3,xmm12
|
||||
aesdec xmm4,xmm12
|
||||
movdqa xmm9,64[rcx]
|
||||
movdqa xmm10,80[rcx]
|
||||
movdqa xmm11,96[rcx]
|
||||
movdqa xmm12,112[rcx]
|
||||
aesdec xmm1,xmm9
|
||||
aesdec xmm2,xmm9
|
||||
aesdec xmm3,xmm9
|
||||
aesdec xmm4,xmm9
|
||||
aesdec xmm1,xmm10
|
||||
aesdec xmm2,xmm10
|
||||
aesdec xmm3,xmm10
|
||||
aesdec xmm4,xmm10
|
||||
aesdec xmm1,xmm11
|
||||
aesdec xmm2,xmm11
|
||||
aesdec xmm3,xmm11
|
||||
aesdec xmm4,xmm11
|
||||
aesdec xmm1,xmm12
|
||||
aesdec xmm2,xmm12
|
||||
aesdec xmm3,xmm12
|
||||
aesdec xmm4,xmm12
|
||||
movdqa xmm9,128[rcx]
|
||||
movdqa xmm10,144[rcx]
|
||||
movdqa xmm11,160[rcx]
|
||||
cmp r8d,12
|
||||
aesdec xmm1,xmm9
|
||||
aesdec xmm2,xmm9
|
||||
aesdec xmm3,xmm9
|
||||
aesdec xmm4,xmm9
|
||||
aesdec xmm1,xmm10
|
||||
aesdec xmm2,xmm10
|
||||
aesdec xmm3,xmm10
|
||||
aesdec xmm4,xmm10
|
||||
jb DECB_LAST_4
|
||||
movdqa xmm9,160[rcx]
|
||||
movdqa xmm10,176[rcx]
|
||||
movdqa xmm11,192[rcx]
|
||||
cmp r8d,14
|
||||
aesdec xmm1,xmm9
|
||||
aesdec xmm2,xmm9
|
||||
aesdec xmm3,xmm9
|
||||
aesdec xmm4,xmm9
|
||||
aesdec xmm1,xmm10
|
||||
aesdec xmm2,xmm10
|
||||
aesdec xmm3,xmm10
|
||||
aesdec xmm4,xmm10
|
||||
jb DECB_LAST_4
|
||||
movdqa xmm9,192[rcx]
|
||||
movdqa xmm10,208[rcx]
|
||||
movdqa xmm11,224[rcx]
|
||||
aesdec xmm1,xmm9
|
||||
aesdec xmm2,xmm9
|
||||
aesdec xmm3,xmm9
|
||||
aesdec xmm4,xmm9
|
||||
aesdec xmm1,xmm10
|
||||
aesdec xmm2,xmm10
|
||||
aesdec xmm3,xmm10
|
||||
aesdec xmm4,xmm10
|
||||
DECB_LAST_4:
|
||||
add rdi,64
|
||||
add rsi,64
|
||||
dec rdx
|
||||
aesdeclast xmm1,xmm11
|
||||
aesdeclast xmm2,xmm11
|
||||
aesdeclast xmm3,xmm11
|
||||
aesdeclast xmm4,xmm11
|
||||
movdqu [rsi],xmm1
|
||||
movdqu 16[rsi],xmm2
|
||||
movdqu 32[rsi],xmm3
|
||||
movdqu 48[rsi],xmm4
|
||||
jne DECB_LOOP_4
|
||||
add rsi,64
|
||||
DECB_REMAINDER_4:
|
||||
cmp r10,0
|
||||
je DECB_END_4
|
||||
DECB_LOOP_4_2:
|
||||
movdqu xmm1,[rdi]
|
||||
add rdi,16
|
||||
pxor xmm1,[rcx]
|
||||
movdqu xmm2,160[rcx]
|
||||
cmp r8d,12
|
||||
aesdec xmm1,16[rcx]
|
||||
aesdec xmm1,32[rcx]
|
||||
aesdec xmm1,48[rcx]
|
||||
aesdec xmm1,64[rcx]
|
||||
aesdec xmm1,80[rcx]
|
||||
aesdec xmm1,96[rcx]
|
||||
aesdec xmm1,112[rcx]
|
||||
aesdec xmm1,128[rcx]
|
||||
aesdec xmm1,144[rcx]
|
||||
jb DECB_LAST_4_2
|
||||
cmp r8d,14
|
||||
movdqu xmm2,192[rcx]
|
||||
aesdec xmm1,160[rcx]
|
||||
aesdec xmm1,176[rcx]
|
||||
jb DECB_LAST_4_2
|
||||
movdqu xmm2,224[rcx]
|
||||
aesdec xmm1,192[rcx]
|
||||
aesdec xmm1,208[rcx]
|
||||
DECB_LAST_4_2:
|
||||
aesdeclast xmm1,xmm2
|
||||
movdqu [rsi],xmm1
|
||||
add rsi,16
|
||||
dec r10
|
||||
jne DECB_LOOP_4_2
|
||||
DECB_END_4:
|
||||
; restore non volatile rdi,rsi
|
||||
mov rdi,rax
|
||||
mov rsi,r11
|
||||
; restore non volatile xmms from stack
|
||||
movdqa xmm9, [rsp+0]
|
||||
movdqa xmm10, [rsp+16]
|
||||
movdqa xmm11, [rsp+32]
|
||||
movdqa xmm12, [rsp+48]
|
||||
add rsp,8+4*16 ; 8 = align stack , 4 xmm9-12 16 bytes each
|
||||
ret
|
||||
AES_ECB_decrypt ENDP
|
||||
|
||||
|
||||
|
||||
; /*
|
||||
; void ,AES_128_Key_Expansion[const unsigned char*userkey
|
||||
; unsigned char*key_schedule]/
|
||||
; */
|
||||
; . align 16,0x90
|
||||
; . globl AES_128_Key_Expansion
|
||||
AES_128_Key_Expansion PROC
|
||||
;# parameter 1: rdi
|
||||
;# parameter 2: rsi
|
||||
|
||||
; save rdi and rsi to rax and r11, restore before ret
|
||||
mov rax,rdi
|
||||
mov r11,rsi
|
||||
|
||||
; convert to what we had for att&t convention
|
||||
mov rdi,rcx
|
||||
mov rsi,rdx
|
||||
|
||||
mov dword ptr 240[rsi],10
|
||||
|
||||
movdqu xmm1,[rdi]
|
||||
movdqa [rsi],xmm1
|
||||
|
||||
|
||||
ASSISTS:
|
||||
aeskeygenassist xmm2,xmm1,1
|
||||
call PREPARE_ROUNDKEY_128
|
||||
movdqa 16[rsi],xmm1
|
||||
|
||||
aeskeygenassist xmm2,xmm1,2
|
||||
call PREPARE_ROUNDKEY_128
|
||||
movdqa 32[rsi],xmm1
|
||||
|
||||
aeskeygenassist xmm2,xmm1,4
|
||||
call PREPARE_ROUNDKEY_128
|
||||
movdqa 48[rsi],xmm1
|
||||
|
||||
aeskeygenassist xmm2,xmm1,8
|
||||
call PREPARE_ROUNDKEY_128
|
||||
movdqa 64[rsi],xmm1
|
||||
|
||||
aeskeygenassist xmm2,xmm1,16
|
||||
call PREPARE_ROUNDKEY_128
|
||||
movdqa 80[rsi],xmm1
|
||||
|
||||
aeskeygenassist xmm2,xmm1,32
|
||||
call PREPARE_ROUNDKEY_128
|
||||
movdqa 96[rsi],xmm1
|
||||
|
||||
aeskeygenassist xmm2,xmm1,64
|
||||
call PREPARE_ROUNDKEY_128
|
||||
movdqa 112[rsi],xmm1
|
||||
aeskeygenassist xmm2,xmm1,80h
|
||||
call PREPARE_ROUNDKEY_128
|
||||
movdqa 128[rsi],xmm1
|
||||
aeskeygenassist xmm2,xmm1,1bh
|
||||
call PREPARE_ROUNDKEY_128
|
||||
movdqa 144[rsi],xmm1
|
||||
aeskeygenassist xmm2,xmm1,36h
|
||||
call PREPARE_ROUNDKEY_128
|
||||
movdqa 160[rsi],xmm1
|
||||
; restore non volatile rdi,rsi
|
||||
mov rdi,rax
|
||||
mov rsi,r11
|
||||
ret
|
||||
|
||||
PREPARE_ROUNDKEY_128:
|
||||
pshufd xmm2,xmm2,255
|
||||
movdqa xmm3,xmm1
|
||||
pslldq xmm3,4
|
||||
pxor xmm1,xmm3
|
||||
pslldq xmm3,4
|
||||
pxor xmm1,xmm3
|
||||
pslldq xmm3,4
|
||||
pxor xmm1,xmm3
|
||||
pxor xmm1,xmm2
|
||||
ret
|
||||
AES_128_Key_Expansion ENDP
|
||||
|
||||
; /*
|
||||
; void ,AES_192_Key_Expansion[const unsigned char*userkey
|
||||
; unsigned char*key]
|
||||
; */
|
||||
; . globl AES_192_Key_Expansion
|
||||
AES_192_Key_Expansion PROC
|
||||
;# parameter 1: rdi
|
||||
;# parameter 2: rsi
|
||||
|
||||
; save rdi and rsi to rax and r11, restore before ret
|
||||
mov rax,rdi
|
||||
mov r11,rsi
|
||||
|
||||
; convert to what we had for att&t convention
|
||||
mov rdi,rcx
|
||||
mov rsi,rdx
|
||||
|
||||
; on microsoft xmm6-xmm15 are non volaitle, let's save on stack and restore at end
|
||||
sub rsp,8+1*16 ; 8 = align stack , 1 xmm6, 16 bytes each
|
||||
movdqa [rsp+0], xmm6
|
||||
|
||||
movdqu xmm1,[rdi]
|
||||
movdqu xmm3,16[rdi]
|
||||
movdqa [rsi],xmm1
|
||||
movdqa xmm5,xmm3
|
||||
|
||||
aeskeygenassist xmm2,xmm3,1h
|
||||
call PREPARE_ROUNDKEY_192
|
||||
shufpd xmm5,xmm1,0
|
||||
movdqa 16[rsi],xmm5
|
||||
movdqa xmm6,xmm1
|
||||
shufpd xmm6,xmm3,1
|
||||
movdqa 32[rsi],xmm6
|
||||
|
||||
aeskeygenassist xmm2,xmm3,2h
|
||||
call PREPARE_ROUNDKEY_192
|
||||
movdqa 48[rsi],xmm1
|
||||
movdqa xmm5,xmm3
|
||||
|
||||
aeskeygenassist xmm2,xmm3,4h
|
||||
call PREPARE_ROUNDKEY_192
|
||||
shufpd xmm5,xmm1,0
|
||||
movdqa 64[rsi],xmm5
|
||||
movdqa xmm6,xmm1
|
||||
shufpd xmm6,xmm3,1
|
||||
movdqa 80[rsi],xmm6
|
||||
|
||||
aeskeygenassist xmm2,xmm3,8h
|
||||
call PREPARE_ROUNDKEY_192
|
||||
movdqa 96[rsi],xmm1
|
||||
movdqa xmm5,xmm3
|
||||
|
||||
aeskeygenassist xmm2,xmm3,10h
|
||||
call PREPARE_ROUNDKEY_192
|
||||
shufpd xmm5,xmm1,0
|
||||
movdqa 112[rsi],xmm5
|
||||
movdqa xmm6,xmm1
|
||||
shufpd xmm6,xmm3,1
|
||||
movdqa 128[rsi],xmm6
|
||||
|
||||
aeskeygenassist xmm2,xmm3,20h
|
||||
call PREPARE_ROUNDKEY_192
|
||||
movdqa 144[rsi],xmm1
|
||||
movdqa xmm5,xmm3
|
||||
|
||||
aeskeygenassist xmm2,xmm3,40h
|
||||
call PREPARE_ROUNDKEY_192
|
||||
shufpd xmm5,xmm1,0
|
||||
movdqa 160[rsi],xmm5
|
||||
movdqa xmm6,xmm1
|
||||
shufpd xmm6,xmm3,1
|
||||
movdqa 176[rsi],xmm6
|
||||
|
||||
aeskeygenassist xmm2,xmm3,80h
|
||||
call PREPARE_ROUNDKEY_192
|
||||
movdqa 192[rsi],xmm1
|
||||
movdqa 208[rsi],xmm3
|
||||
; restore non volatile rdi,rsi
|
||||
mov rdi,rax
|
||||
mov rsi,r11
|
||||
; restore non volatile xmms from stack
|
||||
movdqa xmm6, [rsp+0]
|
||||
add rsp,8+1*16 ; 8 = align stack , 1 xmm6 16 bytes each
|
||||
ret
|
||||
|
||||
PREPARE_ROUNDKEY_192:
|
||||
pshufd xmm2,xmm2,55h
|
||||
movdqu xmm4,xmm1
|
||||
pslldq xmm4,4
|
||||
pxor xmm1,xmm4
|
||||
|
||||
pslldq xmm4,4
|
||||
pxor xmm1,xmm4
|
||||
pslldq xmm4,4
|
||||
pxor xmm1,xmm4
|
||||
pxor xmm1,xmm2
|
||||
pshufd xmm2,xmm1,0ffh
|
||||
movdqu xmm4,xmm3
|
||||
pslldq xmm4,4
|
||||
pxor xmm3,xmm4
|
||||
pxor xmm3,xmm2
|
||||
ret
|
||||
AES_192_Key_Expansion ENDP
|
||||
|
||||
; /*
|
||||
; void ,AES_256_Key_Expansion[const unsigned char*userkey
|
||||
; unsigned char*key]
|
||||
; */
|
||||
; . globl AES_256_Key_Expansion
|
||||
AES_256_Key_Expansion PROC
|
||||
;# parameter 1: rdi
|
||||
;# parameter 2: rsi
|
||||
|
||||
; save rdi and rsi to rax and r11, restore before ret
|
||||
mov rax,rdi
|
||||
mov r11,rsi
|
||||
|
||||
; convert to what we had for att&t convention
|
||||
mov rdi,rcx
|
||||
mov rsi,rdx
|
||||
|
||||
movdqu xmm1,[rdi]
|
||||
movdqu xmm3,16[rdi]
|
||||
movdqa [rsi],xmm1
|
||||
movdqa 16[rsi],xmm3
|
||||
|
||||
aeskeygenassist xmm2,xmm3,1h
|
||||
call MAKE_RK256_a
|
||||
movdqa 32[rsi],xmm1
|
||||
aeskeygenassist xmm2,xmm1,0h
|
||||
call MAKE_RK256_b
|
||||
movdqa 48[rsi],xmm3
|
||||
aeskeygenassist xmm2,xmm3,2h
|
||||
call MAKE_RK256_a
|
||||
movdqa 64[rsi],xmm1
|
||||
aeskeygenassist xmm2,xmm1,0h
|
||||
call MAKE_RK256_b
|
||||
movdqa 80[rsi],xmm3
|
||||
aeskeygenassist xmm2,xmm3,4h
|
||||
call MAKE_RK256_a
|
||||
movdqa 96[rsi],xmm1
|
||||
aeskeygenassist xmm2,xmm1,0h
|
||||
call MAKE_RK256_b
|
||||
movdqa 112[rsi],xmm3
|
||||
aeskeygenassist xmm2,xmm3,8h
|
||||
call MAKE_RK256_a
|
||||
movdqa 128[rsi],xmm1
|
||||
aeskeygenassist xmm2,xmm1,0h
|
||||
call MAKE_RK256_b
|
||||
movdqa 144[rsi],xmm3
|
||||
aeskeygenassist xmm2,xmm3,10h
|
||||
call MAKE_RK256_a
|
||||
movdqa 160[rsi],xmm1
|
||||
aeskeygenassist xmm2,xmm1,0h
|
||||
call MAKE_RK256_b
|
||||
movdqa 176[rsi],xmm3
|
||||
aeskeygenassist xmm2,xmm3,20h
|
||||
call MAKE_RK256_a
|
||||
movdqa 192[rsi],xmm1
|
||||
|
||||
aeskeygenassist xmm2,xmm1,0h
|
||||
call MAKE_RK256_b
|
||||
movdqa 208[rsi],xmm3
|
||||
aeskeygenassist xmm2,xmm3,40h
|
||||
call MAKE_RK256_a
|
||||
movdqa 224[rsi],xmm1
|
||||
|
||||
; restore non volatile rdi,rsi
|
||||
mov rdi,rax
|
||||
mov rsi,r11
|
||||
ret
|
||||
AES_256_Key_Expansion ENDP
|
||||
|
||||
MAKE_RK256_a:
|
||||
pshufd xmm2,xmm2,0ffh
|
||||
movdqa xmm4,xmm1
|
||||
pslldq xmm4,4
|
||||
pxor xmm1,xmm4
|
||||
pslldq xmm4,4
|
||||
pxor xmm1,xmm4
|
||||
pslldq xmm4,4
|
||||
pxor xmm1,xmm4
|
||||
pxor xmm1,xmm2
|
||||
ret
|
||||
|
||||
MAKE_RK256_b:
|
||||
pshufd xmm2,xmm2,0aah
|
||||
movdqa xmm4,xmm3
|
||||
pslldq xmm4,4
|
||||
pxor xmm3,xmm4
|
||||
pslldq xmm4,4
|
||||
pxor xmm3,xmm4
|
||||
pslldq xmm4,4
|
||||
pxor xmm3,xmm4
|
||||
pxor xmm3,xmm2
|
||||
ret
|
||||
|
||||
END
|
@ -1,816 +0,0 @@
|
||||
/* aes_asm.s
|
||||
*
|
||||
* Copyright (C) 2006-2014 wolfSSL Inc.
|
||||
*
|
||||
* This file is part of wolfSSL. (formerly known as CyaSSL)
|
||||
*
|
||||
* wolfSSL is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wolfSSL is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
|
||||
/* See Intel® Advanced Encryption Standard (AES) Instructions Set White Paper
|
||||
* by Intel Mobility Group, Israel Development Center, Israel Shay Gueron
|
||||
*/
|
||||
|
||||
/* This file is in at&t asm syntax, see .asm for intel syntax */
|
||||
|
||||
|
||||
/*
|
||||
AES_CBC_encrypt (const unsigned char *in,
|
||||
unsigned char *out,
|
||||
unsigned char ivec[16],
|
||||
unsigned long length,
|
||||
const unsigned char *KS,
|
||||
int nr)
|
||||
*/
|
||||
.globl AES_CBC_encrypt
|
||||
AES_CBC_encrypt:
|
||||
# parameter 1: %rdi
|
||||
# parameter 2: %rsi
|
||||
# parameter 3: %rdx
|
||||
# parameter 4: %rcx
|
||||
# parameter 5: %r8
|
||||
# parameter 6: %r9d
|
||||
movq %rcx, %r10
|
||||
shrq $4, %rcx
|
||||
shlq $60, %r10
|
||||
je NO_PARTS
|
||||
addq $1, %rcx
|
||||
NO_PARTS:
|
||||
subq $16, %rsi
|
||||
movdqa (%rdx), %xmm1
|
||||
LOOP:
|
||||
pxor (%rdi), %xmm1
|
||||
pxor (%r8), %xmm1
|
||||
addq $16,%rsi
|
||||
addq $16,%rdi
|
||||
cmpl $12, %r9d
|
||||
aesenc 16(%r8),%xmm1
|
||||
aesenc 32(%r8),%xmm1
|
||||
aesenc 48(%r8),%xmm1
|
||||
aesenc 64(%r8),%xmm1
|
||||
aesenc 80(%r8),%xmm1
|
||||
aesenc 96(%r8),%xmm1
|
||||
aesenc 112(%r8),%xmm1
|
||||
aesenc 128(%r8),%xmm1
|
||||
aesenc 144(%r8),%xmm1
|
||||
movdqa 160(%r8),%xmm2
|
||||
jb LAST
|
||||
cmpl $14, %r9d
|
||||
|
||||
aesenc 160(%r8),%xmm1
|
||||
aesenc 176(%r8),%xmm1
|
||||
movdqa 192(%r8),%xmm2
|
||||
jb LAST
|
||||
aesenc 192(%r8),%xmm1
|
||||
aesenc 208(%r8),%xmm1
|
||||
movdqa 224(%r8),%xmm2
|
||||
LAST:
|
||||
decq %rcx
|
||||
aesenclast %xmm2,%xmm1
|
||||
movdqu %xmm1,(%rsi)
|
||||
jne LOOP
|
||||
ret
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
AES_CBC_decrypt (const unsigned char *in,
|
||||
unsigned char *out,
|
||||
unsigned char ivec[16],
|
||||
unsigned long length,
|
||||
const unsigned char *KS,
|
||||
int nr)
|
||||
*/
|
||||
.globl AES_CBC_decrypt
|
||||
AES_CBC_decrypt:
|
||||
# parameter 1: %rdi
|
||||
# parameter 2: %rsi
|
||||
# parameter 3: %rdx
|
||||
# parameter 4: %rcx
|
||||
# parameter 5: %r8
|
||||
# parameter 6: %r9d
|
||||
|
||||
movq %rcx, %r10
|
||||
shrq $4, %rcx
|
||||
shlq $60, %r10
|
||||
je DNO_PARTS_4
|
||||
addq $1, %rcx
|
||||
DNO_PARTS_4:
|
||||
movq %rcx, %r10
|
||||
shlq $62, %r10
|
||||
shrq $62, %r10
|
||||
shrq $2, %rcx
|
||||
movdqu (%rdx),%xmm5
|
||||
je DREMAINDER_4
|
||||
subq $64, %rsi
|
||||
DLOOP_4:
|
||||
movdqu (%rdi), %xmm1
|
||||
movdqu 16(%rdi), %xmm2
|
||||
movdqu 32(%rdi), %xmm3
|
||||
movdqu 48(%rdi), %xmm4
|
||||
movdqa %xmm1, %xmm6
|
||||
movdqa %xmm2, %xmm7
|
||||
movdqa %xmm3, %xmm8
|
||||
movdqa %xmm4, %xmm15
|
||||
movdqa (%r8), %xmm9
|
||||
movdqa 16(%r8), %xmm10
|
||||
movdqa 32(%r8), %xmm11
|
||||
movdqa 48(%r8), %xmm12
|
||||
pxor %xmm9, %xmm1
|
||||
pxor %xmm9, %xmm2
|
||||
pxor %xmm9, %xmm3
|
||||
|
||||
pxor %xmm9, %xmm4
|
||||
aesdec %xmm10, %xmm1
|
||||
aesdec %xmm10, %xmm2
|
||||
aesdec %xmm10, %xmm3
|
||||
aesdec %xmm10, %xmm4
|
||||
aesdec %xmm11, %xmm1
|
||||
aesdec %xmm11, %xmm2
|
||||
aesdec %xmm11, %xmm3
|
||||
aesdec %xmm11, %xmm4
|
||||
aesdec %xmm12, %xmm1
|
||||
aesdec %xmm12, %xmm2
|
||||
aesdec %xmm12, %xmm3
|
||||
aesdec %xmm12, %xmm4
|
||||
movdqa 64(%r8), %xmm9
|
||||
movdqa 80(%r8), %xmm10
|
||||
movdqa 96(%r8), %xmm11
|
||||
movdqa 112(%r8), %xmm12
|
||||
aesdec %xmm9, %xmm1
|
||||
aesdec %xmm9, %xmm2
|
||||
aesdec %xmm9, %xmm3
|
||||
aesdec %xmm9, %xmm4
|
||||
aesdec %xmm10, %xmm1
|
||||
aesdec %xmm10, %xmm2
|
||||
aesdec %xmm10, %xmm3
|
||||
aesdec %xmm10, %xmm4
|
||||
aesdec %xmm11, %xmm1
|
||||
aesdec %xmm11, %xmm2
|
||||
aesdec %xmm11, %xmm3
|
||||
aesdec %xmm11, %xmm4
|
||||
aesdec %xmm12, %xmm1
|
||||
aesdec %xmm12, %xmm2
|
||||
aesdec %xmm12, %xmm3
|
||||
aesdec %xmm12, %xmm4
|
||||
movdqa 128(%r8), %xmm9
|
||||
movdqa 144(%r8), %xmm10
|
||||
movdqa 160(%r8), %xmm11
|
||||
cmpl $12, %r9d
|
||||
aesdec %xmm9, %xmm1
|
||||
aesdec %xmm9, %xmm2
|
||||
aesdec %xmm9, %xmm3
|
||||
aesdec %xmm9, %xmm4
|
||||
aesdec %xmm10, %xmm1
|
||||
aesdec %xmm10, %xmm2
|
||||
aesdec %xmm10, %xmm3
|
||||
aesdec %xmm10, %xmm4
|
||||
jb DLAST_4
|
||||
movdqa 160(%r8), %xmm9
|
||||
movdqa 176(%r8), %xmm10
|
||||
movdqa 192(%r8), %xmm11
|
||||
cmpl $14, %r9d
|
||||
aesdec %xmm9, %xmm1
|
||||
aesdec %xmm9, %xmm2
|
||||
aesdec %xmm9, %xmm3
|
||||
aesdec %xmm9, %xmm4
|
||||
aesdec %xmm10, %xmm1
|
||||
aesdec %xmm10, %xmm2
|
||||
aesdec %xmm10, %xmm3
|
||||
aesdec %xmm10, %xmm4
|
||||
jb DLAST_4
|
||||
|
||||
movdqa 192(%r8), %xmm9
|
||||
movdqa 208(%r8), %xmm10
|
||||
movdqa 224(%r8), %xmm11
|
||||
aesdec %xmm9, %xmm1
|
||||
aesdec %xmm9, %xmm2
|
||||
aesdec %xmm9, %xmm3
|
||||
aesdec %xmm9, %xmm4
|
||||
aesdec %xmm10, %xmm1
|
||||
aesdec %xmm10, %xmm2
|
||||
aesdec %xmm10, %xmm3
|
||||
aesdec %xmm10, %xmm4
|
||||
DLAST_4:
|
||||
addq $64, %rdi
|
||||
addq $64, %rsi
|
||||
decq %rcx
|
||||
aesdeclast %xmm11, %xmm1
|
||||
aesdeclast %xmm11, %xmm2
|
||||
aesdeclast %xmm11, %xmm3
|
||||
aesdeclast %xmm11, %xmm4
|
||||
pxor %xmm5 ,%xmm1
|
||||
pxor %xmm6 ,%xmm2
|
||||
pxor %xmm7 ,%xmm3
|
||||
pxor %xmm8 ,%xmm4
|
||||
movdqu %xmm1, (%rsi)
|
||||
movdqu %xmm2, 16(%rsi)
|
||||
movdqu %xmm3, 32(%rsi)
|
||||
movdqu %xmm4, 48(%rsi)
|
||||
movdqa %xmm15,%xmm5
|
||||
jne DLOOP_4
|
||||
addq $64, %rsi
|
||||
DREMAINDER_4:
|
||||
cmpq $0, %r10
|
||||
je DEND_4
|
||||
DLOOP_4_2:
|
||||
movdqu (%rdi), %xmm1
|
||||
movdqa %xmm1 ,%xmm15
|
||||
addq $16, %rdi
|
||||
pxor (%r8), %xmm1
|
||||
movdqu 160(%r8), %xmm2
|
||||
cmpl $12, %r9d
|
||||
aesdec 16(%r8), %xmm1
|
||||
aesdec 32(%r8), %xmm1
|
||||
aesdec 48(%r8), %xmm1
|
||||
aesdec 64(%r8), %xmm1
|
||||
aesdec 80(%r8), %xmm1
|
||||
aesdec 96(%r8), %xmm1
|
||||
aesdec 112(%r8), %xmm1
|
||||
aesdec 128(%r8), %xmm1
|
||||
aesdec 144(%r8), %xmm1
|
||||
jb DLAST_4_2
|
||||
movdqu 192(%r8), %xmm2
|
||||
cmpl $14, %r9d
|
||||
aesdec 160(%r8), %xmm1
|
||||
aesdec 176(%r8), %xmm1
|
||||
jb DLAST_4_2
|
||||
movdqu 224(%r8), %xmm2
|
||||
aesdec 192(%r8), %xmm1
|
||||
aesdec 208(%r8), %xmm1
|
||||
DLAST_4_2:
|
||||
aesdeclast %xmm2, %xmm1
|
||||
pxor %xmm5, %xmm1
|
||||
movdqa %xmm15, %xmm5
|
||||
movdqu %xmm1, (%rsi)
|
||||
|
||||
addq $16, %rsi
|
||||
decq %r10
|
||||
jne DLOOP_4_2
|
||||
DEND_4:
|
||||
ret
|
||||
|
||||
|
||||
/*
|
||||
AES_ECB_encrypt (const unsigned char *in,
|
||||
unsigned char *out,
|
||||
unsigned long length,
|
||||
const unsigned char *KS,
|
||||
int nr)
|
||||
*/
|
||||
.globl AES_ECB_encrypt
|
||||
AES_ECB_encrypt:
|
||||
# parameter 1: %rdi
|
||||
# parameter 2: %rsi
|
||||
# parameter 3: %rdx
|
||||
# parameter 4: %rcx
|
||||
# parameter 5: %r8d
|
||||
movq %rdx, %r10
|
||||
shrq $4, %rdx
|
||||
shlq $60, %r10
|
||||
je EECB_NO_PARTS_4
|
||||
addq $1, %rdx
|
||||
EECB_NO_PARTS_4:
|
||||
movq %rdx, %r10
|
||||
shlq $62, %r10
|
||||
shrq $62, %r10
|
||||
shrq $2, %rdx
|
||||
je EECB_REMAINDER_4
|
||||
subq $64, %rsi
|
||||
EECB_LOOP_4:
|
||||
movdqu (%rdi), %xmm1
|
||||
movdqu 16(%rdi), %xmm2
|
||||
movdqu 32(%rdi), %xmm3
|
||||
movdqu 48(%rdi), %xmm4
|
||||
movdqa (%rcx), %xmm9
|
||||
movdqa 16(%rcx), %xmm10
|
||||
movdqa 32(%rcx), %xmm11
|
||||
movdqa 48(%rcx), %xmm12
|
||||
pxor %xmm9, %xmm1
|
||||
pxor %xmm9, %xmm2
|
||||
pxor %xmm9, %xmm3
|
||||
pxor %xmm9, %xmm4
|
||||
aesenc %xmm10, %xmm1
|
||||
aesenc %xmm10, %xmm2
|
||||
aesenc %xmm10, %xmm3
|
||||
aesenc %xmm10, %xmm4
|
||||
aesenc %xmm11, %xmm1
|
||||
aesenc %xmm11, %xmm2
|
||||
aesenc %xmm11, %xmm3
|
||||
aesenc %xmm11, %xmm4
|
||||
aesenc %xmm12, %xmm1
|
||||
aesenc %xmm12, %xmm2
|
||||
aesenc %xmm12, %xmm3
|
||||
aesenc %xmm12, %xmm4
|
||||
movdqa 64(%rcx), %xmm9
|
||||
movdqa 80(%rcx), %xmm10
|
||||
movdqa 96(%rcx), %xmm11
|
||||
movdqa 112(%rcx), %xmm12
|
||||
aesenc %xmm9, %xmm1
|
||||
aesenc %xmm9, %xmm2
|
||||
aesenc %xmm9, %xmm3
|
||||
aesenc %xmm9, %xmm4
|
||||
aesenc %xmm10, %xmm1
|
||||
aesenc %xmm10, %xmm2
|
||||
aesenc %xmm10, %xmm3
|
||||
aesenc %xmm10, %xmm4
|
||||
aesenc %xmm11, %xmm1
|
||||
aesenc %xmm11, %xmm2
|
||||
aesenc %xmm11, %xmm3
|
||||
aesenc %xmm11, %xmm4
|
||||
aesenc %xmm12, %xmm1
|
||||
aesenc %xmm12, %xmm2
|
||||
aesenc %xmm12, %xmm3
|
||||
aesenc %xmm12, %xmm4
|
||||
movdqa 128(%rcx), %xmm9
|
||||
movdqa 144(%rcx), %xmm10
|
||||
movdqa 160(%rcx), %xmm11
|
||||
cmpl $12, %r8d
|
||||
aesenc %xmm9, %xmm1
|
||||
aesenc %xmm9, %xmm2
|
||||
aesenc %xmm9, %xmm3
|
||||
aesenc %xmm9, %xmm4
|
||||
aesenc %xmm10, %xmm1
|
||||
aesenc %xmm10, %xmm2
|
||||
aesenc %xmm10, %xmm3
|
||||
aesenc %xmm10, %xmm4
|
||||
jb EECB_LAST_4
|
||||
movdqa 160(%rcx), %xmm9
|
||||
movdqa 176(%rcx), %xmm10
|
||||
movdqa 192(%rcx), %xmm11
|
||||
cmpl $14, %r8d
|
||||
aesenc %xmm9, %xmm1
|
||||
aesenc %xmm9, %xmm2
|
||||
aesenc %xmm9, %xmm3
|
||||
aesenc %xmm9, %xmm4
|
||||
aesenc %xmm10, %xmm1
|
||||
aesenc %xmm10, %xmm2
|
||||
aesenc %xmm10, %xmm3
|
||||
aesenc %xmm10, %xmm4
|
||||
jb EECB_LAST_4
|
||||
movdqa 192(%rcx), %xmm9
|
||||
movdqa 208(%rcx), %xmm10
|
||||
movdqa 224(%rcx), %xmm11
|
||||
aesenc %xmm9, %xmm1
|
||||
aesenc %xmm9, %xmm2
|
||||
aesenc %xmm9, %xmm3
|
||||
aesenc %xmm9, %xmm4
|
||||
aesenc %xmm10, %xmm1
|
||||
aesenc %xmm10, %xmm2
|
||||
aesenc %xmm10, %xmm3
|
||||
aesenc %xmm10, %xmm4
|
||||
EECB_LAST_4:
|
||||
addq $64, %rdi
|
||||
addq $64, %rsi
|
||||
decq %rdx
|
||||
aesenclast %xmm11, %xmm1
|
||||
aesenclast %xmm11, %xmm2
|
||||
aesenclast %xmm11, %xmm3
|
||||
aesenclast %xmm11, %xmm4
|
||||
movdqu %xmm1, (%rsi)
|
||||
movdqu %xmm2, 16(%rsi)
|
||||
movdqu %xmm3, 32(%rsi)
|
||||
movdqu %xmm4, 48(%rsi)
|
||||
jne EECB_LOOP_4
|
||||
addq $64, %rsi
|
||||
EECB_REMAINDER_4:
|
||||
cmpq $0, %r10
|
||||
je EECB_END_4
|
||||
EECB_LOOP_4_2:
|
||||
movdqu (%rdi), %xmm1
|
||||
addq $16, %rdi
|
||||
pxor (%rcx), %xmm1
|
||||
movdqu 160(%rcx), %xmm2
|
||||
aesenc 16(%rcx), %xmm1
|
||||
aesenc 32(%rcx), %xmm1
|
||||
aesenc 48(%rcx), %xmm1
|
||||
aesenc 64(%rcx), %xmm1
|
||||
aesenc 80(%rcx), %xmm1
|
||||
aesenc 96(%rcx), %xmm1
|
||||
aesenc 112(%rcx), %xmm1
|
||||
aesenc 128(%rcx), %xmm1
|
||||
aesenc 144(%rcx), %xmm1
|
||||
cmpl $12, %r8d
|
||||
jb EECB_LAST_4_2
|
||||
movdqu 192(%rcx), %xmm2
|
||||
aesenc 160(%rcx), %xmm1
|
||||
aesenc 176(%rcx), %xmm1
|
||||
cmpl $14, %r8d
|
||||
jb EECB_LAST_4_2
|
||||
movdqu 224(%rcx), %xmm2
|
||||
aesenc 192(%rcx), %xmm1
|
||||
aesenc 208(%rcx), %xmm1
|
||||
EECB_LAST_4_2:
|
||||
aesenclast %xmm2, %xmm1
|
||||
movdqu %xmm1, (%rsi)
|
||||
addq $16, %rsi
|
||||
decq %r10
|
||||
jne EECB_LOOP_4_2
|
||||
EECB_END_4:
|
||||
ret
|
||||
|
||||
|
||||
/*
|
||||
AES_ECB_decrypt (const unsigned char *in,
|
||||
unsigned char *out,
|
||||
unsigned long length,
|
||||
const unsigned char *KS,
|
||||
int nr)
|
||||
*/
|
||||
.globl AES_ECB_decrypt
|
||||
AES_ECB_decrypt:
|
||||
# parameter 1: %rdi
|
||||
# parameter 2: %rsi
|
||||
# parameter 3: %rdx
|
||||
# parameter 4: %rcx
|
||||
# parameter 5: %r8d
|
||||
|
||||
movq %rdx, %r10
|
||||
shrq $4, %rdx
|
||||
shlq $60, %r10
|
||||
je DECB_NO_PARTS_4
|
||||
addq $1, %rdx
|
||||
DECB_NO_PARTS_4:
|
||||
movq %rdx, %r10
|
||||
shlq $62, %r10
|
||||
shrq $62, %r10
|
||||
shrq $2, %rdx
|
||||
je DECB_REMAINDER_4
|
||||
subq $64, %rsi
|
||||
DECB_LOOP_4:
|
||||
movdqu (%rdi), %xmm1
|
||||
movdqu 16(%rdi), %xmm2
|
||||
movdqu 32(%rdi), %xmm3
|
||||
movdqu 48(%rdi), %xmm4
|
||||
movdqa (%rcx), %xmm9
|
||||
movdqa 16(%rcx), %xmm10
|
||||
movdqa 32(%rcx), %xmm11
|
||||
movdqa 48(%rcx), %xmm12
|
||||
pxor %xmm9, %xmm1
|
||||
pxor %xmm9, %xmm2
|
||||
pxor %xmm9, %xmm3
|
||||
pxor %xmm9, %xmm4
|
||||
aesdec %xmm10, %xmm1
|
||||
aesdec %xmm10, %xmm2
|
||||
aesdec %xmm10, %xmm3
|
||||
aesdec %xmm10, %xmm4
|
||||
aesdec %xmm11, %xmm1
|
||||
aesdec %xmm11, %xmm2
|
||||
aesdec %xmm11, %xmm3
|
||||
aesdec %xmm11, %xmm4
|
||||
aesdec %xmm12, %xmm1
|
||||
aesdec %xmm12, %xmm2
|
||||
aesdec %xmm12, %xmm3
|
||||
aesdec %xmm12, %xmm4
|
||||
movdqa 64(%rcx), %xmm9
|
||||
movdqa 80(%rcx), %xmm10
|
||||
movdqa 96(%rcx), %xmm11
|
||||
movdqa 112(%rcx), %xmm12
|
||||
aesdec %xmm9, %xmm1
|
||||
aesdec %xmm9, %xmm2
|
||||
aesdec %xmm9, %xmm3
|
||||
aesdec %xmm9, %xmm4
|
||||
aesdec %xmm10, %xmm1
|
||||
aesdec %xmm10, %xmm2
|
||||
aesdec %xmm10, %xmm3
|
||||
aesdec %xmm10, %xmm4
|
||||
aesdec %xmm11, %xmm1
|
||||
aesdec %xmm11, %xmm2
|
||||
aesdec %xmm11, %xmm3
|
||||
aesdec %xmm11, %xmm4
|
||||
aesdec %xmm12, %xmm1
|
||||
aesdec %xmm12, %xmm2
|
||||
aesdec %xmm12, %xmm3
|
||||
aesdec %xmm12, %xmm4
|
||||
movdqa 128(%rcx), %xmm9
|
||||
movdqa 144(%rcx), %xmm10
|
||||
movdqa 160(%rcx), %xmm11
|
||||
cmpl $12, %r8d
|
||||
aesdec %xmm9, %xmm1
|
||||
aesdec %xmm9, %xmm2
|
||||
aesdec %xmm9, %xmm3
|
||||
aesdec %xmm9, %xmm4
|
||||
aesdec %xmm10, %xmm1
|
||||
aesdec %xmm10, %xmm2
|
||||
aesdec %xmm10, %xmm3
|
||||
aesdec %xmm10, %xmm4
|
||||
jb DECB_LAST_4
|
||||
movdqa 160(%rcx), %xmm9
|
||||
movdqa 176(%rcx), %xmm10
|
||||
movdqa 192(%rcx), %xmm11
|
||||
cmpl $14, %r8d
|
||||
aesdec %xmm9, %xmm1
|
||||
aesdec %xmm9, %xmm2
|
||||
aesdec %xmm9, %xmm3
|
||||
aesdec %xmm9, %xmm4
|
||||
aesdec %xmm10, %xmm1
|
||||
aesdec %xmm10, %xmm2
|
||||
aesdec %xmm10, %xmm3
|
||||
aesdec %xmm10, %xmm4
|
||||
jb DECB_LAST_4
|
||||
movdqa 192(%rcx), %xmm9
|
||||
movdqa 208(%rcx), %xmm10
|
||||
movdqa 224(%rcx), %xmm11
|
||||
aesdec %xmm9, %xmm1
|
||||
aesdec %xmm9, %xmm2
|
||||
aesdec %xmm9, %xmm3
|
||||
aesdec %xmm9, %xmm4
|
||||
aesdec %xmm10, %xmm1
|
||||
aesdec %xmm10, %xmm2
|
||||
aesdec %xmm10, %xmm3
|
||||
aesdec %xmm10, %xmm4
|
||||
DECB_LAST_4:
|
||||
addq $64, %rdi
|
||||
addq $64, %rsi
|
||||
decq %rdx
|
||||
aesdeclast %xmm11, %xmm1
|
||||
aesdeclast %xmm11, %xmm2
|
||||
aesdeclast %xmm11, %xmm3
|
||||
aesdeclast %xmm11, %xmm4
|
||||
movdqu %xmm1, (%rsi)
|
||||
movdqu %xmm2, 16(%rsi)
|
||||
movdqu %xmm3, 32(%rsi)
|
||||
movdqu %xmm4, 48(%rsi)
|
||||
jne DECB_LOOP_4
|
||||
addq $64, %rsi
|
||||
DECB_REMAINDER_4:
|
||||
cmpq $0, %r10
|
||||
je DECB_END_4
|
||||
DECB_LOOP_4_2:
|
||||
movdqu (%rdi), %xmm1
|
||||
addq $16, %rdi
|
||||
pxor (%rcx), %xmm1
|
||||
movdqu 160(%rcx), %xmm2
|
||||
cmpl $12, %r8d
|
||||
aesdec 16(%rcx), %xmm1
|
||||
aesdec 32(%rcx), %xmm1
|
||||
aesdec 48(%rcx), %xmm1
|
||||
aesdec 64(%rcx), %xmm1
|
||||
aesdec 80(%rcx), %xmm1
|
||||
aesdec 96(%rcx), %xmm1
|
||||
aesdec 112(%rcx), %xmm1
|
||||
aesdec 128(%rcx), %xmm1
|
||||
aesdec 144(%rcx), %xmm1
|
||||
jb DECB_LAST_4_2
|
||||
cmpl $14, %r8d
|
||||
movdqu 192(%rcx), %xmm2
|
||||
aesdec 160(%rcx), %xmm1
|
||||
aesdec 176(%rcx), %xmm1
|
||||
jb DECB_LAST_4_2
|
||||
movdqu 224(%rcx), %xmm2
|
||||
aesdec 192(%rcx), %xmm1
|
||||
aesdec 208(%rcx), %xmm1
|
||||
DECB_LAST_4_2:
|
||||
aesdeclast %xmm2, %xmm1
|
||||
movdqu %xmm1, (%rsi)
|
||||
addq $16, %rsi
|
||||
decq %r10
|
||||
jne DECB_LOOP_4_2
|
||||
DECB_END_4:
|
||||
ret
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
void AES_128_Key_Expansion(const unsigned char* userkey,
|
||||
unsigned char* key_schedule);
|
||||
*/
|
||||
.align 16,0x90
|
||||
.globl AES_128_Key_Expansion
|
||||
AES_128_Key_Expansion:
|
||||
# parameter 1: %rdi
|
||||
# parameter 2: %rsi
|
||||
movl $10, 240(%rsi)
|
||||
|
||||
movdqu (%rdi), %xmm1
|
||||
movdqa %xmm1, (%rsi)
|
||||
|
||||
|
||||
ASSISTS:
|
||||
aeskeygenassist $1, %xmm1, %xmm2
|
||||
call PREPARE_ROUNDKEY_128
|
||||
movdqa %xmm1, 16(%rsi)
|
||||
aeskeygenassist $2, %xmm1, %xmm2
|
||||
call PREPARE_ROUNDKEY_128
|
||||
movdqa %xmm1, 32(%rsi)
|
||||
aeskeygenassist $4, %xmm1, %xmm2
|
||||
call PREPARE_ROUNDKEY_128
|
||||
movdqa %xmm1, 48(%rsi)
|
||||
aeskeygenassist $8, %xmm1, %xmm2
|
||||
call PREPARE_ROUNDKEY_128
|
||||
movdqa %xmm1, 64(%rsi)
|
||||
aeskeygenassist $16, %xmm1, %xmm2
|
||||
call PREPARE_ROUNDKEY_128
|
||||
movdqa %xmm1, 80(%rsi)
|
||||
aeskeygenassist $32, %xmm1, %xmm2
|
||||
call PREPARE_ROUNDKEY_128
|
||||
movdqa %xmm1, 96(%rsi)
|
||||
aeskeygenassist $64, %xmm1, %xmm2
|
||||
call PREPARE_ROUNDKEY_128
|
||||
movdqa %xmm1, 112(%rsi)
|
||||
aeskeygenassist $0x80, %xmm1, %xmm2
|
||||
call PREPARE_ROUNDKEY_128
|
||||
movdqa %xmm1, 128(%rsi)
|
||||
aeskeygenassist $0x1b, %xmm1, %xmm2
|
||||
call PREPARE_ROUNDKEY_128
|
||||
movdqa %xmm1, 144(%rsi)
|
||||
aeskeygenassist $0x36, %xmm1, %xmm2
|
||||
call PREPARE_ROUNDKEY_128
|
||||
movdqa %xmm1, 160(%rsi)
|
||||
ret
|
||||
|
||||
PREPARE_ROUNDKEY_128:
|
||||
pshufd $255, %xmm2, %xmm2
|
||||
movdqa %xmm1, %xmm3
|
||||
pslldq $4, %xmm3
|
||||
pxor %xmm3, %xmm1
|
||||
pslldq $4, %xmm3
|
||||
pxor %xmm3, %xmm1
|
||||
pslldq $4, %xmm3
|
||||
pxor %xmm3, %xmm1
|
||||
pxor %xmm2, %xmm1
|
||||
ret
|
||||
|
||||
|
||||
/*
|
||||
void AES_192_Key_Expansion (const unsigned char *userkey,
|
||||
unsigned char *key)
|
||||
*/
|
||||
.globl AES_192_Key_Expansion
|
||||
AES_192_Key_Expansion:
|
||||
# parameter 1: %rdi
|
||||
# parameter 2: %rsi
|
||||
|
||||
movdqu (%rdi), %xmm1
|
||||
movdqu 16(%rdi), %xmm3
|
||||
movdqa %xmm1, (%rsi)
|
||||
movdqa %xmm3, %xmm5
|
||||
|
||||
aeskeygenassist $0x1, %xmm3, %xmm2
|
||||
call PREPARE_ROUNDKEY_192
|
||||
shufpd $0, %xmm1, %xmm5
|
||||
movdqa %xmm5, 16(%rsi)
|
||||
movdqa %xmm1, %xmm6
|
||||
shufpd $1, %xmm3, %xmm6
|
||||
movdqa %xmm6, 32(%rsi)
|
||||
|
||||
aeskeygenassist $0x2, %xmm3, %xmm2
|
||||
call PREPARE_ROUNDKEY_192
|
||||
movdqa %xmm1, 48(%rsi)
|
||||
movdqa %xmm3, %xmm5
|
||||
|
||||
aeskeygenassist $0x4, %xmm3, %xmm2
|
||||
call PREPARE_ROUNDKEY_192
|
||||
shufpd $0, %xmm1, %xmm5
|
||||
movdqa %xmm5, 64(%rsi)
|
||||
movdqa %xmm1, %xmm6
|
||||
shufpd $1, %xmm3, %xmm6
|
||||
movdqa %xmm6, 80(%rsi)
|
||||
|
||||
aeskeygenassist $0x8, %xmm3, %xmm2
|
||||
call PREPARE_ROUNDKEY_192
|
||||
movdqa %xmm1, 96(%rsi)
|
||||
movdqa %xmm3, %xmm5
|
||||
|
||||
aeskeygenassist $0x10, %xmm3, %xmm2
|
||||
call PREPARE_ROUNDKEY_192
|
||||
shufpd $0, %xmm1, %xmm5
|
||||
movdqa %xmm5, 112(%rsi)
|
||||
movdqa %xmm1, %xmm6
|
||||
shufpd $1, %xmm3, %xmm6
|
||||
movdqa %xmm6, 128(%rsi)
|
||||
|
||||
aeskeygenassist $0x20, %xmm3, %xmm2
|
||||
call PREPARE_ROUNDKEY_192
|
||||
movdqa %xmm1, 144(%rsi)
|
||||
movdqa %xmm3, %xmm5
|
||||
|
||||
aeskeygenassist $0x40, %xmm3, %xmm2
|
||||
call PREPARE_ROUNDKEY_192
|
||||
shufpd $0, %xmm1, %xmm5
|
||||
movdqa %xmm5, 160(%rsi)
|
||||
movdqa %xmm1, %xmm6
|
||||
shufpd $1, %xmm3, %xmm6
|
||||
movdqa %xmm6, 176(%rsi)
|
||||
|
||||
aeskeygenassist $0x80, %xmm3, %xmm2
|
||||
call PREPARE_ROUNDKEY_192
|
||||
movdqa %xmm1, 192(%rsi)
|
||||
movdqa %xmm3, 208(%rsi)
|
||||
ret
|
||||
|
||||
PREPARE_ROUNDKEY_192:
|
||||
pshufd $0x55, %xmm2, %xmm2
|
||||
movdqu %xmm1, %xmm4
|
||||
pslldq $4, %xmm4
|
||||
pxor %xmm4, %xmm1
|
||||
|
||||
pslldq $4, %xmm4
|
||||
pxor %xmm4, %xmm1
|
||||
pslldq $4, %xmm4
|
||||
pxor %xmm4, %xmm1
|
||||
pxor %xmm2, %xmm1
|
||||
pshufd $0xff, %xmm1, %xmm2
|
||||
movdqu %xmm3, %xmm4
|
||||
pslldq $4, %xmm4
|
||||
pxor %xmm4, %xmm3
|
||||
pxor %xmm2, %xmm3
|
||||
ret
|
||||
|
||||
|
||||
/*
|
||||
void AES_256_Key_Expansion (const unsigned char *userkey,
|
||||
unsigned char *key)
|
||||
*/
|
||||
.globl AES_256_Key_Expansion
|
||||
AES_256_Key_Expansion:
|
||||
# parameter 1: %rdi
|
||||
# parameter 2: %rsi
|
||||
|
||||
movdqu (%rdi), %xmm1
|
||||
movdqu 16(%rdi), %xmm3
|
||||
movdqa %xmm1, (%rsi)
|
||||
movdqa %xmm3, 16(%rsi)
|
||||
|
||||
aeskeygenassist $0x1, %xmm3, %xmm2
|
||||
call MAKE_RK256_a
|
||||
movdqa %xmm1, 32(%rsi)
|
||||
aeskeygenassist $0x0, %xmm1, %xmm2
|
||||
call MAKE_RK256_b
|
||||
movdqa %xmm3, 48(%rsi)
|
||||
aeskeygenassist $0x2, %xmm3, %xmm2
|
||||
call MAKE_RK256_a
|
||||
movdqa %xmm1, 64(%rsi)
|
||||
aeskeygenassist $0x0, %xmm1, %xmm2
|
||||
call MAKE_RK256_b
|
||||
movdqa %xmm3, 80(%rsi)
|
||||
aeskeygenassist $0x4, %xmm3, %xmm2
|
||||
call MAKE_RK256_a
|
||||
movdqa %xmm1, 96(%rsi)
|
||||
aeskeygenassist $0x0, %xmm1, %xmm2
|
||||
call MAKE_RK256_b
|
||||
movdqa %xmm3, 112(%rsi)
|
||||
aeskeygenassist $0x8, %xmm3, %xmm2
|
||||
call MAKE_RK256_a
|
||||
movdqa %xmm1, 128(%rsi)
|
||||
aeskeygenassist $0x0, %xmm1, %xmm2
|
||||
call MAKE_RK256_b
|
||||
movdqa %xmm3, 144(%rsi)
|
||||
aeskeygenassist $0x10, %xmm3, %xmm2
|
||||
call MAKE_RK256_a
|
||||
movdqa %xmm1, 160(%rsi)
|
||||
aeskeygenassist $0x0, %xmm1, %xmm2
|
||||
call MAKE_RK256_b
|
||||
movdqa %xmm3, 176(%rsi)
|
||||
aeskeygenassist $0x20, %xmm3, %xmm2
|
||||
call MAKE_RK256_a
|
||||
movdqa %xmm1, 192(%rsi)
|
||||
|
||||
aeskeygenassist $0x0, %xmm1, %xmm2
|
||||
call MAKE_RK256_b
|
||||
movdqa %xmm3, 208(%rsi)
|
||||
aeskeygenassist $0x40, %xmm3, %xmm2
|
||||
call MAKE_RK256_a
|
||||
movdqa %xmm1, 224(%rsi)
|
||||
|
||||
ret
|
||||
|
||||
MAKE_RK256_a:
|
||||
pshufd $0xff, %xmm2, %xmm2
|
||||
movdqa %xmm1, %xmm4
|
||||
pslldq $4, %xmm4
|
||||
pxor %xmm4, %xmm1
|
||||
pslldq $4, %xmm4
|
||||
pxor %xmm4, %xmm1
|
||||
pslldq $4, %xmm4
|
||||
pxor %xmm4, %xmm1
|
||||
pxor %xmm2, %xmm1
|
||||
ret
|
||||
|
||||
MAKE_RK256_b:
|
||||
pshufd $0xaa, %xmm2, %xmm2
|
||||
movdqa %xmm3, %xmm4
|
||||
pslldq $4, %xmm4
|
||||
pxor %xmm4, %xmm3
|
||||
pslldq $4, %xmm4
|
||||
pxor %xmm4, %xmm3
|
||||
pslldq $4, %xmm4
|
||||
pxor %xmm4, %xmm3
|
||||
pxor %xmm2, %xmm3
|
||||
ret
|
||||
|
7688
ctaocrypt/src/asn.c
7688
ctaocrypt/src/asn.c
File diff suppressed because it is too large
Load Diff
@ -1,433 +0,0 @@
|
||||
/*
|
||||
BLAKE2 reference source code package - reference C implementations
|
||||
|
||||
Written in 2012 by Samuel Neves <sneves@dei.uc.pt>
|
||||
|
||||
To the extent possible under law, the author(s) have dedicated all copyright
|
||||
and related and neighboring rights to this software to the public domain
|
||||
worldwide. This software is distributed without any warranty.
|
||||
|
||||
You should have received a copy of the CC0 Public Domain Dedication along with
|
||||
this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
*/
|
||||
/* blake2b.c
|
||||
*
|
||||
* Copyright (C) 2006-2014 wolfSSL Inc.
|
||||
*
|
||||
* This file is part of wolfSSL. (formerly known as CyaSSL)
|
||||
*
|
||||
* wolfSSL is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wolfSSL is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <cyassl/ctaocrypt/settings.h>
|
||||
|
||||
#ifdef HAVE_BLAKE2
|
||||
|
||||
#include <cyassl/ctaocrypt/blake2.h>
|
||||
#include <cyassl/ctaocrypt/blake2-impl.h>
|
||||
|
||||
|
||||
static const word64 blake2b_IV[8] =
|
||||
{
|
||||
0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL,
|
||||
0x3c6ef372fe94f82bULL, 0xa54ff53a5f1d36f1ULL,
|
||||
0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL,
|
||||
0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL
|
||||
};
|
||||
|
||||
static const byte blake2b_sigma[12][16] =
|
||||
{
|
||||
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } ,
|
||||
{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 } ,
|
||||
{ 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 } ,
|
||||
{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 } ,
|
||||
{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 } ,
|
||||
{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 } ,
|
||||
{ 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 } ,
|
||||
{ 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 } ,
|
||||
{ 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 } ,
|
||||
{ 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 } ,
|
||||
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } ,
|
||||
{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 }
|
||||
};
|
||||
|
||||
|
||||
static INLINE int blake2b_set_lastnode( blake2b_state *S )
|
||||
{
|
||||
S->f[1] = ~0ULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Some helper functions, not necessarily useful */
|
||||
static INLINE int blake2b_set_lastblock( blake2b_state *S )
|
||||
{
|
||||
if( S->last_node ) blake2b_set_lastnode( S );
|
||||
|
||||
S->f[0] = ~0ULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static INLINE int blake2b_increment_counter( blake2b_state *S, const word64
|
||||
inc )
|
||||
{
|
||||
S->t[0] += inc;
|
||||
S->t[1] += ( S->t[0] < inc );
|
||||
return 0;
|
||||
}
|
||||
|
||||
static INLINE int blake2b_init0( blake2b_state *S )
|
||||
{
|
||||
int i;
|
||||
XMEMSET( S, 0, sizeof( blake2b_state ) );
|
||||
|
||||
for( i = 0; i < 8; ++i ) S->h[i] = blake2b_IV[i];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* init xors IV with input parameter block */
|
||||
int blake2b_init_param( blake2b_state *S, const blake2b_param *P )
|
||||
{
|
||||
word32 i;
|
||||
blake2b_init0( S );
|
||||
byte *p = ( byte * )( P );
|
||||
|
||||
/* IV XOR ParamBlock */
|
||||
for( i = 0; i < 8; ++i )
|
||||
S->h[i] ^= load64( p + sizeof( S->h[i] ) * i );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int blake2b_init( blake2b_state *S, const byte outlen )
|
||||
{
|
||||
blake2b_param P[1];
|
||||
|
||||
if ( ( !outlen ) || ( outlen > BLAKE2B_OUTBYTES ) ) return -1;
|
||||
|
||||
P->digest_length = outlen;
|
||||
P->key_length = 0;
|
||||
P->fanout = 1;
|
||||
P->depth = 1;
|
||||
store32( &P->leaf_length, 0 );
|
||||
store64( &P->node_offset, 0 );
|
||||
P->node_depth = 0;
|
||||
P->inner_length = 0;
|
||||
XMEMSET( P->reserved, 0, sizeof( P->reserved ) );
|
||||
XMEMSET( P->salt, 0, sizeof( P->salt ) );
|
||||
XMEMSET( P->personal, 0, sizeof( P->personal ) );
|
||||
return blake2b_init_param( S, P );
|
||||
}
|
||||
|
||||
|
||||
int blake2b_init_key( blake2b_state *S, const byte outlen, const void *key,
|
||||
const byte keylen )
|
||||
{
|
||||
blake2b_param P[1];
|
||||
|
||||
if ( ( !outlen ) || ( outlen > BLAKE2B_OUTBYTES ) ) return -1;
|
||||
|
||||
if ( !key || !keylen || keylen > BLAKE2B_KEYBYTES ) return -1;
|
||||
|
||||
P->digest_length = outlen;
|
||||
P->key_length = keylen;
|
||||
P->fanout = 1;
|
||||
P->depth = 1;
|
||||
store32( &P->leaf_length, 0 );
|
||||
store64( &P->node_offset, 0 );
|
||||
P->node_depth = 0;
|
||||
P->inner_length = 0;
|
||||
XMEMSET( P->reserved, 0, sizeof( P->reserved ) );
|
||||
XMEMSET( P->salt, 0, sizeof( P->salt ) );
|
||||
XMEMSET( P->personal, 0, sizeof( P->personal ) );
|
||||
|
||||
if( blake2b_init_param( S, P ) < 0 ) return -1;
|
||||
|
||||
{
|
||||
#ifdef CYASSL_SMALL_STACK
|
||||
byte* block;
|
||||
|
||||
block = (byte*)XMALLOC(BLAKE2B_BLOCKBYTES, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
|
||||
if ( block == NULL ) return -1;
|
||||
#else
|
||||
byte block[BLAKE2B_BLOCKBYTES];
|
||||
#endif
|
||||
|
||||
XMEMSET( block, 0, BLAKE2B_BLOCKBYTES );
|
||||
XMEMCPY( block, key, keylen );
|
||||
blake2b_update( S, block, BLAKE2B_BLOCKBYTES );
|
||||
secure_zero_memory( block, BLAKE2B_BLOCKBYTES ); /* Burn the key from */
|
||||
/* memory */
|
||||
|
||||
#ifdef CYASSL_SMALL_STACK
|
||||
XFREE(block, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int blake2b_compress( blake2b_state *S,
|
||||
const byte block[BLAKE2B_BLOCKBYTES] )
|
||||
{
|
||||
int i;
|
||||
|
||||
#ifdef CYASSL_SMALL_STACK
|
||||
word64* m;
|
||||
word64* v;
|
||||
|
||||
m = (word64*)XMALLOC(sizeof(word64) * 16, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
|
||||
if ( m == NULL ) return -1;
|
||||
|
||||
v = (word64*)XMALLOC(sizeof(word64) * 16, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
|
||||
if ( v == NULL )
|
||||
{
|
||||
XFREE(m, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
word64 m[16];
|
||||
word64 v[16];
|
||||
#endif
|
||||
|
||||
for( i = 0; i < 16; ++i )
|
||||
m[i] = load64( block + i * sizeof( m[i] ) );
|
||||
|
||||
for( i = 0; i < 8; ++i )
|
||||
v[i] = S->h[i];
|
||||
|
||||
v[ 8] = blake2b_IV[0];
|
||||
v[ 9] = blake2b_IV[1];
|
||||
v[10] = blake2b_IV[2];
|
||||
v[11] = blake2b_IV[3];
|
||||
v[12] = S->t[0] ^ blake2b_IV[4];
|
||||
v[13] = S->t[1] ^ blake2b_IV[5];
|
||||
v[14] = S->f[0] ^ blake2b_IV[6];
|
||||
v[15] = S->f[1] ^ blake2b_IV[7];
|
||||
#define G(r,i,a,b,c,d) \
|
||||
do { \
|
||||
a = a + b + m[blake2b_sigma[r][2*i+0]]; \
|
||||
d = rotr64(d ^ a, 32); \
|
||||
c = c + d; \
|
||||
b = rotr64(b ^ c, 24); \
|
||||
a = a + b + m[blake2b_sigma[r][2*i+1]]; \
|
||||
d = rotr64(d ^ a, 16); \
|
||||
c = c + d; \
|
||||
b = rotr64(b ^ c, 63); \
|
||||
} while(0)
|
||||
#define ROUND(r) \
|
||||
do { \
|
||||
G(r,0,v[ 0],v[ 4],v[ 8],v[12]); \
|
||||
G(r,1,v[ 1],v[ 5],v[ 9],v[13]); \
|
||||
G(r,2,v[ 2],v[ 6],v[10],v[14]); \
|
||||
G(r,3,v[ 3],v[ 7],v[11],v[15]); \
|
||||
G(r,4,v[ 0],v[ 5],v[10],v[15]); \
|
||||
G(r,5,v[ 1],v[ 6],v[11],v[12]); \
|
||||
G(r,6,v[ 2],v[ 7],v[ 8],v[13]); \
|
||||
G(r,7,v[ 3],v[ 4],v[ 9],v[14]); \
|
||||
} while(0)
|
||||
ROUND( 0 );
|
||||
ROUND( 1 );
|
||||
ROUND( 2 );
|
||||
ROUND( 3 );
|
||||
ROUND( 4 );
|
||||
ROUND( 5 );
|
||||
ROUND( 6 );
|
||||
ROUND( 7 );
|
||||
ROUND( 8 );
|
||||
ROUND( 9 );
|
||||
ROUND( 10 );
|
||||
ROUND( 11 );
|
||||
|
||||
for( i = 0; i < 8; ++i )
|
||||
S->h[i] = S->h[i] ^ v[i] ^ v[i + 8];
|
||||
|
||||
#undef G
|
||||
#undef ROUND
|
||||
|
||||
#ifdef CYASSL_SMALL_STACK
|
||||
XFREE(m, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
XFREE(v, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* inlen now in bytes */
|
||||
int blake2b_update( blake2b_state *S, const byte *in, word64 inlen )
|
||||
{
|
||||
while( inlen > 0 )
|
||||
{
|
||||
word64 left = S->buflen;
|
||||
word64 fill = 2 * BLAKE2B_BLOCKBYTES - left;
|
||||
|
||||
if( inlen > fill )
|
||||
{
|
||||
XMEMCPY( S->buf + left, in, (cyassl_word)fill ); /* Fill buffer */
|
||||
S->buflen += fill;
|
||||
blake2b_increment_counter( S, BLAKE2B_BLOCKBYTES );
|
||||
|
||||
if ( blake2b_compress( S, S->buf ) < 0 ) return -1; /* Compress */
|
||||
|
||||
XMEMCPY( S->buf, S->buf + BLAKE2B_BLOCKBYTES, BLAKE2B_BLOCKBYTES );
|
||||
/* Shift buffer left */
|
||||
S->buflen -= BLAKE2B_BLOCKBYTES;
|
||||
in += fill;
|
||||
inlen -= fill;
|
||||
}
|
||||
else /* inlen <= fill */
|
||||
{
|
||||
XMEMCPY( S->buf + left, in, (cyassl_word)inlen );
|
||||
S->buflen += inlen; /* Be lazy, do not compress */
|
||||
in += inlen;
|
||||
inlen -= inlen;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Is this correct? */
|
||||
int blake2b_final( blake2b_state *S, byte *out, byte outlen )
|
||||
{
|
||||
byte buffer[BLAKE2B_OUTBYTES];
|
||||
int i;
|
||||
|
||||
if( S->buflen > BLAKE2B_BLOCKBYTES )
|
||||
{
|
||||
blake2b_increment_counter( S, BLAKE2B_BLOCKBYTES );
|
||||
|
||||
if ( blake2b_compress( S, S->buf ) < 0 ) return -1;
|
||||
|
||||
S->buflen -= BLAKE2B_BLOCKBYTES;
|
||||
XMEMCPY( S->buf, S->buf + BLAKE2B_BLOCKBYTES, (cyassl_word)S->buflen );
|
||||
}
|
||||
|
||||
blake2b_increment_counter( S, S->buflen );
|
||||
blake2b_set_lastblock( S );
|
||||
XMEMSET( S->buf + S->buflen, 0, (cyassl_word)(2 * BLAKE2B_BLOCKBYTES - S->buflen) );
|
||||
/* Padding */
|
||||
if ( blake2b_compress( S, S->buf ) < 0 ) return -1;
|
||||
|
||||
for( i = 0; i < 8; ++i ) /* Output full hash to temp buffer */
|
||||
store64( buffer + sizeof( S->h[i] ) * i, S->h[i] );
|
||||
|
||||
XMEMCPY( out, buffer, outlen );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* inlen, at least, should be word64. Others can be size_t. */
|
||||
int blake2b( byte *out, const void *in, const void *key, const byte outlen,
|
||||
const word64 inlen, byte keylen )
|
||||
{
|
||||
blake2b_state S[1];
|
||||
|
||||
/* Verify parameters */
|
||||
if ( NULL == in ) return -1;
|
||||
|
||||
if ( NULL == out ) return -1;
|
||||
|
||||
if( NULL == key ) keylen = 0;
|
||||
|
||||
if( keylen > 0 )
|
||||
{
|
||||
if( blake2b_init_key( S, outlen, key, keylen ) < 0 ) return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( blake2b_init( S, outlen ) < 0 ) return -1;
|
||||
}
|
||||
|
||||
if ( blake2b_update( S, ( byte * )in, inlen ) < 0) return -1;
|
||||
|
||||
return blake2b_final( S, out, outlen );
|
||||
}
|
||||
|
||||
#if defined(BLAKE2B_SELFTEST)
|
||||
#include <string.h>
|
||||
#include "blake2-kat.h"
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
byte key[BLAKE2B_KEYBYTES];
|
||||
byte buf[KAT_LENGTH];
|
||||
|
||||
for( word32 i = 0; i < BLAKE2B_KEYBYTES; ++i )
|
||||
key[i] = ( byte )i;
|
||||
|
||||
for( word32 i = 0; i < KAT_LENGTH; ++i )
|
||||
buf[i] = ( byte )i;
|
||||
|
||||
for( word32 i = 0; i < KAT_LENGTH; ++i )
|
||||
{
|
||||
byte hash[BLAKE2B_OUTBYTES];
|
||||
if ( blake2b( hash, buf, key, BLAKE2B_OUTBYTES, i, BLAKE2B_KEYBYTES ) < 0 )
|
||||
{
|
||||
puts( "error" );
|
||||
return -1;
|
||||
}
|
||||
|
||||
if( 0 != memcmp( hash, blake2b_keyed_kat[i], BLAKE2B_OUTBYTES ) )
|
||||
{
|
||||
puts( "error" );
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
puts( "ok" );
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* CTaoCrypt API */
|
||||
|
||||
/* Init Blake2b digest, track size incase final doesn't want to "remember" */
|
||||
int InitBlake2b(Blake2b* b2b, word32 digestSz)
|
||||
{
|
||||
b2b->digestSz = digestSz;
|
||||
|
||||
return blake2b_init(b2b->S, (byte)digestSz);
|
||||
}
|
||||
|
||||
|
||||
/* Blake2b Update */
|
||||
int Blake2bUpdate(Blake2b* b2b, const byte* data, word32 sz)
|
||||
{
|
||||
return blake2b_update(b2b->S, data, sz);
|
||||
}
|
||||
|
||||
|
||||
/* Blake2b Final, if pass in zero size we use init digestSz */
|
||||
int Blake2bFinal(Blake2b* b2b, byte* final, word32 requestSz)
|
||||
{
|
||||
word32 sz = requestSz ? requestSz : b2b->digestSz;
|
||||
|
||||
return blake2b_final(b2b->S, final, (byte)sz);
|
||||
}
|
||||
|
||||
|
||||
/* end CTaoCrypt API */
|
||||
|
||||
#endif /* HAVE_BLAKE2 */
|
||||
|
@ -1,399 +0,0 @@
|
||||
/* coding.c
|
||||
*
|
||||
* Copyright (C) 2006-2014 wolfSSL Inc.
|
||||
*
|
||||
* This file is part of wolfSSL. (formerly known as CyaSSL)
|
||||
*
|
||||
* wolfSSL is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wolfSSL is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <cyassl/ctaocrypt/settings.h>
|
||||
|
||||
#ifndef NO_CODING
|
||||
|
||||
#include <cyassl/ctaocrypt/coding.h>
|
||||
#include <cyassl/ctaocrypt/error-crypt.h>
|
||||
#include <cyassl/ctaocrypt/logging.h>
|
||||
|
||||
|
||||
enum {
|
||||
BAD = 0xFF, /* invalid encoding */
|
||||
PAD = '=',
|
||||
PEM_LINE_SZ = 64
|
||||
};
|
||||
|
||||
|
||||
static
|
||||
const byte base64Decode[] = { 62, BAD, BAD, BAD, 63, /* + starts at 0x2B */
|
||||
52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
|
||||
BAD, BAD, BAD, BAD, BAD, BAD, BAD,
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
|
||||
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
|
||||
20, 21, 22, 23, 24, 25,
|
||||
BAD, BAD, BAD, BAD, BAD, BAD,
|
||||
26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
|
||||
36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
|
||||
46, 47, 48, 49, 50, 51
|
||||
};
|
||||
|
||||
|
||||
int Base64_Decode(const byte* in, word32 inLen, byte* out, word32* outLen)
|
||||
{
|
||||
word32 i = 0;
|
||||
word32 j = 0;
|
||||
word32 plainSz = inLen - ((inLen + (PEM_LINE_SZ - 1)) / PEM_LINE_SZ );
|
||||
const byte maxIdx = (byte)sizeof(base64Decode) + 0x2B - 1;
|
||||
|
||||
plainSz = (plainSz * 3 + 3) / 4;
|
||||
if (plainSz > *outLen) return BAD_FUNC_ARG;
|
||||
|
||||
while (inLen > 3) {
|
||||
byte b1, b2, b3;
|
||||
byte e1 = in[j++];
|
||||
byte e2 = in[j++];
|
||||
byte e3 = in[j++];
|
||||
byte e4 = in[j++];
|
||||
|
||||
int pad3 = 0;
|
||||
int pad4 = 0;
|
||||
|
||||
if (e1 == 0) /* end file 0's */
|
||||
break;
|
||||
if (e3 == PAD)
|
||||
pad3 = 1;
|
||||
if (e4 == PAD)
|
||||
pad4 = 1;
|
||||
|
||||
if (e1 < 0x2B || e2 < 0x2B || e3 < 0x2B || e4 < 0x2B) {
|
||||
CYASSL_MSG("Bad Base64 Decode data, too small");
|
||||
return ASN_INPUT_E;
|
||||
}
|
||||
|
||||
if (e1 > maxIdx || e2 > maxIdx || e3 > maxIdx || e4 > maxIdx) {
|
||||
CYASSL_MSG("Bad Base64 Decode data, too big");
|
||||
return ASN_INPUT_E;
|
||||
}
|
||||
|
||||
e1 = base64Decode[e1 - 0x2B];
|
||||
e2 = base64Decode[e2 - 0x2B];
|
||||
e3 = (e3 == PAD) ? 0 : base64Decode[e3 - 0x2B];
|
||||
e4 = (e4 == PAD) ? 0 : base64Decode[e4 - 0x2B];
|
||||
|
||||
b1 = (byte)((e1 << 2) | (e2 >> 4));
|
||||
b2 = (byte)(((e2 & 0xF) << 4) | (e3 >> 2));
|
||||
b3 = (byte)(((e3 & 0x3) << 6) | e4);
|
||||
|
||||
out[i++] = b1;
|
||||
if (!pad3)
|
||||
out[i++] = b2;
|
||||
if (!pad4)
|
||||
out[i++] = b3;
|
||||
else
|
||||
break;
|
||||
|
||||
inLen -= 4;
|
||||
if (inLen && (in[j] == ' ' || in[j] == '\r' || in[j] == '\n')) {
|
||||
byte endLine = in[j++];
|
||||
inLen--;
|
||||
while (inLen && endLine == ' ') { /* allow trailing whitespace */
|
||||
endLine = in[j++];
|
||||
inLen--;
|
||||
}
|
||||
if (endLine == '\r') {
|
||||
if (inLen) {
|
||||
endLine = in[j++];
|
||||
inLen--;
|
||||
}
|
||||
}
|
||||
if (endLine != '\n') {
|
||||
CYASSL_MSG("Bad end of line in Base64 Decode");
|
||||
return ASN_INPUT_E;
|
||||
}
|
||||
}
|
||||
}
|
||||
*outLen = i;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#if defined(OPENSSL_EXTRA) || defined (SESSION_CERTS) || defined(CYASSL_KEY_GEN) || defined(CYASSL_CERT_GEN) || defined(HAVE_WEBSERVER)
|
||||
|
||||
static
|
||||
const byte base64Encode[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
|
||||
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
|
||||
'U', 'V', 'W', 'X', 'Y', 'Z',
|
||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
|
||||
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
|
||||
'u', 'v', 'w', 'x', 'y', 'z',
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'+', '/'
|
||||
};
|
||||
|
||||
|
||||
/* make sure *i (idx) won't exceed max, store and possibly escape to out,
|
||||
* raw means use e w/o decode, 0 on success */
|
||||
static int CEscape(int escaped, byte e, byte* out, word32* i, word32 max,
|
||||
int raw)
|
||||
{
|
||||
int doEscape = 0;
|
||||
word32 needed = 1;
|
||||
word32 idx = *i;
|
||||
|
||||
byte basic;
|
||||
byte plus = 0;
|
||||
byte equals = 0;
|
||||
byte newline = 0;
|
||||
|
||||
if (raw)
|
||||
basic = e;
|
||||
else
|
||||
basic = base64Encode[e];
|
||||
|
||||
/* check whether to escape */
|
||||
if (escaped) {
|
||||
switch ((char)basic) {
|
||||
case '+' :
|
||||
plus = 1;
|
||||
doEscape = 1;
|
||||
needed += 2;
|
||||
break;
|
||||
case '=' :
|
||||
equals = 1;
|
||||
doEscape = 1;
|
||||
needed += 2;
|
||||
break;
|
||||
case '\n' :
|
||||
newline = 1;
|
||||
doEscape = 1;
|
||||
needed += 2;
|
||||
break;
|
||||
default:
|
||||
/* do nothing */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* check size */
|
||||
if ( (idx+needed) > max) {
|
||||
CYASSL_MSG("Escape buffer max too small");
|
||||
return BUFFER_E;
|
||||
}
|
||||
|
||||
/* store it */
|
||||
if (doEscape == 0) {
|
||||
out[idx++] = basic;
|
||||
}
|
||||
else {
|
||||
out[idx++] = '%'; /* start escape */
|
||||
|
||||
if (plus) {
|
||||
out[idx++] = '2';
|
||||
out[idx++] = 'B';
|
||||
}
|
||||
else if (equals) {
|
||||
out[idx++] = '3';
|
||||
out[idx++] = 'D';
|
||||
}
|
||||
else if (newline) {
|
||||
out[idx++] = '0';
|
||||
out[idx++] = 'A';
|
||||
}
|
||||
|
||||
}
|
||||
*i = idx;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* internal worker, handles both escaped and normal line endings */
|
||||
static int DoBase64_Encode(const byte* in, word32 inLen, byte* out,
|
||||
word32* outLen, int escaped)
|
||||
{
|
||||
int ret = 0;
|
||||
word32 i = 0,
|
||||
j = 0,
|
||||
n = 0; /* new line counter */
|
||||
|
||||
word32 outSz = (inLen + 3 - 1) / 3 * 4;
|
||||
word32 addSz = (outSz + PEM_LINE_SZ - 1) / PEM_LINE_SZ; /* new lines */
|
||||
|
||||
if (escaped)
|
||||
addSz *= 3; /* instead of just \n, we're doing %0A triplet */
|
||||
|
||||
outSz += addSz;
|
||||
|
||||
/* if escaped we can't predetermine size for one pass encoding, but
|
||||
* make sure we have enough if no escapes are in input */
|
||||
if (outSz > *outLen) return BAD_FUNC_ARG;
|
||||
|
||||
while (inLen > 2) {
|
||||
byte b1 = in[j++];
|
||||
byte b2 = in[j++];
|
||||
byte b3 = in[j++];
|
||||
|
||||
/* encoded idx */
|
||||
byte e1 = b1 >> 2;
|
||||
byte e2 = (byte)(((b1 & 0x3) << 4) | (b2 >> 4));
|
||||
byte e3 = (byte)(((b2 & 0xF) << 2) | (b3 >> 6));
|
||||
byte e4 = b3 & 0x3F;
|
||||
|
||||
/* store */
|
||||
ret = CEscape(escaped, e1, out, &i, *outLen, 0);
|
||||
if (ret != 0) break;
|
||||
ret = CEscape(escaped, e2, out, &i, *outLen, 0);
|
||||
if (ret != 0) break;
|
||||
ret = CEscape(escaped, e3, out, &i, *outLen, 0);
|
||||
if (ret != 0) break;
|
||||
ret = CEscape(escaped, e4, out, &i, *outLen, 0);
|
||||
if (ret != 0) break;
|
||||
|
||||
inLen -= 3;
|
||||
|
||||
if ((++n % (PEM_LINE_SZ / 4)) == 0 && inLen) {
|
||||
ret = CEscape(escaped, '\n', out, &i, *outLen, 1);
|
||||
if (ret != 0) break;
|
||||
}
|
||||
}
|
||||
|
||||
/* last integral */
|
||||
if (inLen && ret == 0) {
|
||||
int twoBytes = (inLen == 2);
|
||||
|
||||
byte b1 = in[j++];
|
||||
byte b2 = (twoBytes) ? in[j++] : 0;
|
||||
|
||||
byte e1 = b1 >> 2;
|
||||
byte e2 = (byte)(((b1 & 0x3) << 4) | (b2 >> 4));
|
||||
byte e3 = (byte)((b2 & 0xF) << 2);
|
||||
|
||||
ret = CEscape(escaped, e1, out, &i, *outLen, 0);
|
||||
if (ret == 0)
|
||||
ret = CEscape(escaped, e2, out, &i, *outLen, 0);
|
||||
if (ret == 0) {
|
||||
/* third */
|
||||
if (twoBytes)
|
||||
ret = CEscape(escaped, e3, out, &i, *outLen, 0);
|
||||
else
|
||||
ret = CEscape(escaped, '=', out, &i, *outLen, 1);
|
||||
}
|
||||
/* fourth always pad */
|
||||
if (ret == 0)
|
||||
ret = CEscape(escaped, '=', out, &i, *outLen, 1);
|
||||
}
|
||||
|
||||
if (ret == 0)
|
||||
ret = CEscape(escaped, '\n', out, &i, *outLen, 1);
|
||||
|
||||
if (i != outSz && escaped == 0 && ret == 0)
|
||||
return ASN_INPUT_E;
|
||||
|
||||
*outLen = i;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* Base64 Encode, PEM style, with \n line endings */
|
||||
int Base64_Encode(const byte* in, word32 inLen, byte* out, word32* outLen)
|
||||
{
|
||||
return DoBase64_Encode(in, inLen, out, outLen, 0);
|
||||
}
|
||||
|
||||
|
||||
/* Base64 Encode, with %0A esacped line endings instead of \n */
|
||||
int Base64_EncodeEsc(const byte* in, word32 inLen, byte* out, word32* outLen)
|
||||
{
|
||||
return DoBase64_Encode(in, inLen, out, outLen, 1);
|
||||
}
|
||||
|
||||
|
||||
#endif /* defined(OPENSSL_EXTRA) || defined (SESSION_CERTS) || defined(CYASSL_KEY_GEN) || defined(CYASSL_CERT_GEN) || defined(HAVE_WEBSERVER) */
|
||||
|
||||
|
||||
#if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER) || defined(HAVE_FIPS)
|
||||
|
||||
static
|
||||
const byte hexDecode[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
|
||||
BAD, BAD, BAD, BAD, BAD, BAD, BAD,
|
||||
10, 11, 12, 13, 14, 15, /* upper case A-F */
|
||||
BAD, BAD, BAD, BAD, BAD, BAD, BAD, BAD,
|
||||
BAD, BAD, BAD, BAD, BAD, BAD, BAD, BAD,
|
||||
BAD, BAD, BAD, BAD, BAD, BAD, BAD, BAD,
|
||||
BAD, BAD, /* G - ` */
|
||||
10, 11, 12, 13, 14, 15 /* lower case a-f */
|
||||
}; /* A starts at 0x41 not 0x3A */
|
||||
|
||||
int Base16_Decode(const byte* in, word32 inLen, byte* out, word32* outLen)
|
||||
{
|
||||
word32 inIdx = 0;
|
||||
word32 outIdx = 0;
|
||||
|
||||
if (inLen == 1 && *outLen && in) {
|
||||
byte b = in[inIdx++] - 0x30; /* 0 starts at 0x30 */
|
||||
|
||||
/* sanity check */
|
||||
if (b >= sizeof(hexDecode)/sizeof(hexDecode[0]))
|
||||
return ASN_INPUT_E;
|
||||
|
||||
b = hexDecode[b];
|
||||
|
||||
if (b == BAD)
|
||||
return ASN_INPUT_E;
|
||||
|
||||
out[outIdx++] = b;
|
||||
|
||||
*outLen = outIdx;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (inLen % 2)
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
if (*outLen < (inLen / 2))
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
while (inLen) {
|
||||
byte b = in[inIdx++] - 0x30; /* 0 starts at 0x30 */
|
||||
byte b2 = in[inIdx++] - 0x30;
|
||||
|
||||
/* sanity checks */
|
||||
if (b >= sizeof(hexDecode)/sizeof(hexDecode[0]))
|
||||
return ASN_INPUT_E;
|
||||
if (b2 >= sizeof(hexDecode)/sizeof(hexDecode[0]))
|
||||
return ASN_INPUT_E;
|
||||
|
||||
b = hexDecode[b];
|
||||
b2 = hexDecode[b2];
|
||||
|
||||
if (b == BAD || b2 == BAD)
|
||||
return ASN_INPUT_E;
|
||||
|
||||
out[outIdx++] = (byte)((b << 4) | b2);
|
||||
inLen -= 2;
|
||||
}
|
||||
|
||||
*outLen = outIdx;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#endif /* (OPENSSL_EXTRA) || (HAVE_WEBSERVER) || (HAVE_FIPS) */
|
||||
|
||||
#endif /* NO_CODING */
|
@ -1,169 +0,0 @@
|
||||
/* compress.c
|
||||
*
|
||||
* Copyright (C) 2006-2014 wolfSSL Inc.
|
||||
*
|
||||
* This file is part of wolfSSL. (formerly known as CyaSSL)
|
||||
*
|
||||
* wolfSSL is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wolfSSL is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <cyassl/ctaocrypt/settings.h>
|
||||
|
||||
#ifdef HAVE_LIBZ
|
||||
|
||||
|
||||
#include <cyassl/ctaocrypt/compress.h>
|
||||
#include <cyassl/ctaocrypt/error-crypt.h>
|
||||
#include <cyassl/ctaocrypt/logging.h>
|
||||
#ifdef NO_INLINE
|
||||
#include <cyassl/ctaocrypt/misc.h>
|
||||
#else
|
||||
#include <ctaocrypt/src/misc.c>
|
||||
#endif
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
|
||||
/* alloc user allocs to work with zlib */
|
||||
static void* myAlloc(void* opaque, unsigned int item, unsigned int size)
|
||||
{
|
||||
(void)opaque;
|
||||
return XMALLOC(item * size, opaque, DYNAMIC_TYPE_LIBZ);
|
||||
}
|
||||
|
||||
|
||||
static void myFree(void* opaque, void* memory)
|
||||
{
|
||||
(void)opaque;
|
||||
XFREE(memory, opaque, DYNAMIC_TYPE_LIBZ);
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAVE_MCAPI
|
||||
#define DEFLATE_DEFAULT_WINDOWBITS 11
|
||||
#define DEFLATE_DEFAULT_MEMLEVEL 1
|
||||
#else
|
||||
#define DEFLATE_DEFAULT_WINDOWBITS 15
|
||||
#define DEFLATE_DEFAULT_MEMLEVEL 8
|
||||
#endif
|
||||
|
||||
|
||||
int Compress(byte* out, word32 outSz, const byte* in, word32 inSz, word32 flags)
|
||||
/*
|
||||
* out - pointer to destination buffer
|
||||
* outSz - size of destination buffer
|
||||
* in - pointer to source buffer to compress
|
||||
* inSz - size of source to compress
|
||||
* flags - flags to control how compress operates
|
||||
*
|
||||
* return:
|
||||
* negative - error code
|
||||
* positive - bytes stored in out buffer
|
||||
*
|
||||
* Note, the output buffer still needs to be larger than the input buffer.
|
||||
* The right chunk of data won't compress at all, and the lookup table will
|
||||
* add to the size of the output. The libz code says the compressed
|
||||
* buffer should be srcSz + 0.1% + 12.
|
||||
*/
|
||||
{
|
||||
z_stream stream;
|
||||
int result = 0;
|
||||
|
||||
stream.next_in = (Bytef*)in;
|
||||
stream.avail_in = (uInt)inSz;
|
||||
#ifdef MAXSEG_64K
|
||||
/* Check for source > 64K on 16-bit machine: */
|
||||
if ((uLong)stream.avail_in != inSz) return COMPRESS_INIT_E;
|
||||
#endif
|
||||
stream.next_out = out;
|
||||
stream.avail_out = (uInt)outSz;
|
||||
if ((uLong)stream.avail_out != outSz) return COMPRESS_INIT_E;
|
||||
|
||||
stream.zalloc = (alloc_func)myAlloc;
|
||||
stream.zfree = (free_func)myFree;
|
||||
stream.opaque = (voidpf)0;
|
||||
|
||||
if (deflateInit2(&stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED,
|
||||
DEFLATE_DEFAULT_WINDOWBITS, DEFLATE_DEFAULT_MEMLEVEL,
|
||||
flags ? Z_FIXED : Z_DEFAULT_STRATEGY) != Z_OK)
|
||||
return COMPRESS_INIT_E;
|
||||
|
||||
if (deflate(&stream, Z_FINISH) != Z_STREAM_END) {
|
||||
deflateEnd(&stream);
|
||||
return COMPRESS_E;
|
||||
}
|
||||
|
||||
result = (int)stream.total_out;
|
||||
|
||||
if (deflateEnd(&stream) != Z_OK)
|
||||
result = COMPRESS_E;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
int DeCompress(byte* out, word32 outSz, const byte* in, word32 inSz)
|
||||
/*
|
||||
* out - pointer to destination buffer
|
||||
* outSz - size of destination buffer
|
||||
* in - pointer to source buffer to compress
|
||||
* inSz - size of source to compress
|
||||
* flags - flags to control how compress operates
|
||||
*
|
||||
* return:
|
||||
* negative - error code
|
||||
* positive - bytes stored in out buffer
|
||||
*/
|
||||
{
|
||||
z_stream stream;
|
||||
int result = 0;
|
||||
|
||||
stream.next_in = (Bytef*)in;
|
||||
stream.avail_in = (uInt)inSz;
|
||||
/* Check for source > 64K on 16-bit machine: */
|
||||
if ((uLong)stream.avail_in != inSz) return DECOMPRESS_INIT_E;
|
||||
|
||||
stream.next_out = out;
|
||||
stream.avail_out = (uInt)outSz;
|
||||
if ((uLong)stream.avail_out != outSz) return DECOMPRESS_INIT_E;
|
||||
|
||||
stream.zalloc = (alloc_func)myAlloc;
|
||||
stream.zfree = (free_func)myFree;
|
||||
stream.opaque = (voidpf)0;
|
||||
|
||||
if (inflateInit2(&stream, DEFLATE_DEFAULT_WINDOWBITS) != Z_OK)
|
||||
return DECOMPRESS_INIT_E;
|
||||
|
||||
if (inflate(&stream, Z_FINISH) != Z_STREAM_END) {
|
||||
inflateEnd(&stream);
|
||||
return DECOMPRESS_E;
|
||||
}
|
||||
|
||||
result = (int)stream.total_out;
|
||||
|
||||
if (inflateEnd(&stream) != Z_OK)
|
||||
result = DECOMPRESS_E;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
#endif /* HAVE_LIBZ */
|
||||
|
@ -1,40 +0,0 @@
|
||||
# vim:ft=automake
|
||||
# All paths should be given relative to the root
|
||||
|
||||
EXTRA_DIST += ctaocrypt/src/misc.c
|
||||
EXTRA_DIST += ctaocrypt/src/asm.c
|
||||
EXTRA_DIST += ctaocrypt/src/aes_asm.asm
|
||||
|
||||
EXTRA_DIST += \
|
||||
ctaocrypt/src/ecc_fp.c \
|
||||
ctaocrypt/src/fp_mont_small.i \
|
||||
ctaocrypt/src/fp_mul_comba_12.i \
|
||||
ctaocrypt/src/fp_mul_comba_17.i \
|
||||
ctaocrypt/src/fp_mul_comba_20.i \
|
||||
ctaocrypt/src/fp_mul_comba_24.i \
|
||||
ctaocrypt/src/fp_mul_comba_28.i \
|
||||
ctaocrypt/src/fp_mul_comba_32.i \
|
||||
ctaocrypt/src/fp_mul_comba_3.i \
|
||||
ctaocrypt/src/fp_mul_comba_48.i \
|
||||
ctaocrypt/src/fp_mul_comba_4.i \
|
||||
ctaocrypt/src/fp_mul_comba_64.i \
|
||||
ctaocrypt/src/fp_mul_comba_6.i \
|
||||
ctaocrypt/src/fp_mul_comba_7.i \
|
||||
ctaocrypt/src/fp_mul_comba_8.i \
|
||||
ctaocrypt/src/fp_mul_comba_9.i \
|
||||
ctaocrypt/src/fp_mul_comba_small_set.i \
|
||||
ctaocrypt/src/fp_sqr_comba_12.i \
|
||||
ctaocrypt/src/fp_sqr_comba_17.i \
|
||||
ctaocrypt/src/fp_sqr_comba_20.i \
|
||||
ctaocrypt/src/fp_sqr_comba_24.i \
|
||||
ctaocrypt/src/fp_sqr_comba_28.i \
|
||||
ctaocrypt/src/fp_sqr_comba_32.i \
|
||||
ctaocrypt/src/fp_sqr_comba_3.i \
|
||||
ctaocrypt/src/fp_sqr_comba_48.i \
|
||||
ctaocrypt/src/fp_sqr_comba_4.i \
|
||||
ctaocrypt/src/fp_sqr_comba_64.i \
|
||||
ctaocrypt/src/fp_sqr_comba_6.i \
|
||||
ctaocrypt/src/fp_sqr_comba_7.i \
|
||||
ctaocrypt/src/fp_sqr_comba_8.i \
|
||||
ctaocrypt/src/fp_sqr_comba_9.i \
|
||||
ctaocrypt/src/fp_sqr_comba_small_set.i
|
File diff suppressed because it is too large
Load Diff
@ -1,162 +0,0 @@
|
||||
/* logging.c
|
||||
*
|
||||
* Copyright (C) 2006-2014 wolfSSL Inc.
|
||||
*
|
||||
* This file is part of wolfSSL. (formerly known as CyaSSL)
|
||||
*
|
||||
* wolfSSL is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wolfSSL is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <cyassl/ctaocrypt/settings.h>
|
||||
|
||||
/* submitted by eof */
|
||||
|
||||
#include <cyassl/ctaocrypt/logging.h>
|
||||
#include <cyassl/ctaocrypt/error-crypt.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
CYASSL_API int CyaSSL_Debugging_ON(void);
|
||||
CYASSL_API void CyaSSL_Debugging_OFF(void);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef DEBUG_CYASSL
|
||||
|
||||
/* Set these to default values initially. */
|
||||
static CyaSSL_Logging_cb log_function = 0;
|
||||
static int loggingEnabled = 0;
|
||||
|
||||
#endif /* DEBUG_CYASSL */
|
||||
|
||||
|
||||
int CyaSSL_SetLoggingCb(CyaSSL_Logging_cb f)
|
||||
{
|
||||
#ifdef DEBUG_CYASSL
|
||||
int res = 0;
|
||||
|
||||
if (f)
|
||||
log_function = f;
|
||||
else
|
||||
res = BAD_FUNC_ARG;
|
||||
|
||||
return res;
|
||||
#else
|
||||
(void)f;
|
||||
return NOT_COMPILED_IN;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int CyaSSL_Debugging_ON(void)
|
||||
{
|
||||
#ifdef DEBUG_CYASSL
|
||||
loggingEnabled = 1;
|
||||
return 0;
|
||||
#else
|
||||
return NOT_COMPILED_IN;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void CyaSSL_Debugging_OFF(void)
|
||||
{
|
||||
#ifdef DEBUG_CYASSL
|
||||
loggingEnabled = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#ifdef DEBUG_CYASSL
|
||||
|
||||
#ifdef FREESCALE_MQX
|
||||
#include <fio.h>
|
||||
#else
|
||||
#include <stdio.h> /* for default printf stuff */
|
||||
#endif
|
||||
|
||||
#ifdef THREADX
|
||||
int dc_log_printf(char*, ...);
|
||||
#endif
|
||||
|
||||
static void cyassl_log(const int logLevel, const char *const logMessage)
|
||||
{
|
||||
if (log_function)
|
||||
log_function(logLevel, logMessage);
|
||||
else {
|
||||
if (loggingEnabled) {
|
||||
#ifdef THREADX
|
||||
dc_log_printf("%s\n", logMessage);
|
||||
#elif defined(MICRIUM)
|
||||
#if (NET_SECURE_MGR_CFG_EN == DEF_ENABLED)
|
||||
NetSecure_TraceOut((CPU_CHAR *)logMessage);
|
||||
#endif
|
||||
#elif defined(CYASSL_MDK_ARM)
|
||||
fflush(stdout) ;
|
||||
printf("%s\n", logMessage);
|
||||
fflush(stdout) ;
|
||||
#else
|
||||
fprintf(stderr, "%s\n", logMessage);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CYASSL_MSG(const char* msg)
|
||||
{
|
||||
if (loggingEnabled)
|
||||
cyassl_log(INFO_LOG , msg);
|
||||
}
|
||||
|
||||
|
||||
void CYASSL_ENTER(const char* msg)
|
||||
{
|
||||
if (loggingEnabled) {
|
||||
char buffer[80];
|
||||
sprintf(buffer, "CyaSSL Entering %s", msg);
|
||||
cyassl_log(ENTER_LOG , buffer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CYASSL_LEAVE(const char* msg, int ret)
|
||||
{
|
||||
if (loggingEnabled) {
|
||||
char buffer[80];
|
||||
sprintf(buffer, "CyaSSL Leaving %s, return %d", msg, ret);
|
||||
cyassl_log(LEAVE_LOG , buffer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CYASSL_ERROR(int error)
|
||||
{
|
||||
if (loggingEnabled) {
|
||||
char buffer[80];
|
||||
sprintf(buffer, "CyaSSL error occured, error = %d", error);
|
||||
cyassl_log(ERROR_LOG , buffer);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* DEBUG_CYASSL */
|
@ -1,159 +0,0 @@
|
||||
/* md2.c
|
||||
*
|
||||
* Copyright (C) 2006-2014 wolfSSL Inc.
|
||||
*
|
||||
* This file is part of wolfSSL. (formerly known as CyaSSL)
|
||||
*
|
||||
* wolfSSL is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wolfSSL is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
|
||||
//#ifdef HAVE_CONFIG_H
|
||||
// #include <config.h>
|
||||
//#endif
|
||||
//
|
||||
//#include <cyassl/ctaocrypt/settings.h>
|
||||
//
|
||||
//#ifdef CYASSL_MD2
|
||||
//
|
||||
//#include <cyassl/ctaocrypt/md2.h>
|
||||
//#include <cyassl/ctaocrypt/error-crypt.h>
|
||||
//
|
||||
//#ifdef NO_INLINE
|
||||
// #include <cyassl/ctaocrypt/misc.h>
|
||||
//#else
|
||||
// #include <ctaocrypt/src/misc.c>
|
||||
//#endif
|
||||
//
|
||||
//
|
||||
//void InitMd2(Md2* md2)
|
||||
//{
|
||||
// XMEMSET(md2->X, 0, MD2_X_SIZE);
|
||||
// XMEMSET(md2->C, 0, MD2_BLOCK_SIZE);
|
||||
// XMEMSET(md2->buffer, 0, MD2_BLOCK_SIZE);
|
||||
// md2->count = 0;
|
||||
//}
|
||||
//
|
||||
//
|
||||
//void Md2Update(Md2* md2, const byte* data, word32 len)
|
||||
//{
|
||||
// static const byte S[256] =
|
||||
// {
|
||||
// 41, 46, 67, 201, 162, 216, 124, 1, 61, 54, 84, 161, 236, 240, 6,
|
||||
// 19, 98, 167, 5, 243, 192, 199, 115, 140, 152, 147, 43, 217, 188,
|
||||
// 76, 130, 202, 30, 155, 87, 60, 253, 212, 224, 22, 103, 66, 111, 24,
|
||||
// 138, 23, 229, 18, 190, 78, 196, 214, 218, 158, 222, 73, 160, 251,
|
||||
// 245, 142, 187, 47, 238, 122, 169, 104, 121, 145, 21, 178, 7, 63,
|
||||
// 148, 194, 16, 137, 11, 34, 95, 33, 128, 127, 93, 154, 90, 144, 50,
|
||||
// 39, 53, 62, 204, 231, 191, 247, 151, 3, 255, 25, 48, 179, 72, 165,
|
||||
// 181, 209, 215, 94, 146, 42, 172, 86, 170, 198, 79, 184, 56, 210,
|
||||
// 150, 164, 125, 182, 118, 252, 107, 226, 156, 116, 4, 241, 69, 157,
|
||||
// 112, 89, 100, 113, 135, 32, 134, 91, 207, 101, 230, 45, 168, 2, 27,
|
||||
// 96, 37, 173, 174, 176, 185, 246, 28, 70, 97, 105, 52, 64, 126, 15,
|
||||
// 85, 71, 163, 35, 221, 81, 175, 58, 195, 92, 249, 206, 186, 197,
|
||||
// 234, 38, 44, 83, 13, 110, 133, 40, 132, 9, 211, 223, 205, 244, 65,
|
||||
// 129, 77, 82, 106, 220, 55, 200, 108, 193, 171, 250, 36, 225, 123,
|
||||
// 8, 12, 189, 177, 74, 120, 136, 149, 139, 227, 99, 232, 109, 233,
|
||||
// 203, 213, 254, 59, 0, 29, 57, 242, 239, 183, 14, 102, 88, 208, 228,
|
||||
// 166, 119, 114, 248, 235, 117, 75, 10, 49, 68, 80, 180, 143, 237,
|
||||
// 31, 26, 219, 153, 141, 51, 159, 17, 131, 20
|
||||
// };
|
||||
//
|
||||
// while (len) {
|
||||
// word32 L = (MD2_PAD_SIZE - md2->count) < len ?
|
||||
// (MD2_PAD_SIZE - md2->count) : len;
|
||||
// XMEMCPY(md2->buffer + md2->count, data, L);
|
||||
// md2->count += L;
|
||||
// data += L;
|
||||
// len -= L;
|
||||
//
|
||||
// if (md2->count == MD2_PAD_SIZE) {
|
||||
// int i;
|
||||
// byte t;
|
||||
//
|
||||
// md2->count = 0;
|
||||
// XMEMCPY(md2->X + MD2_PAD_SIZE, md2->buffer, MD2_PAD_SIZE);
|
||||
// t = md2->C[15];
|
||||
//
|
||||
// for(i = 0; i < MD2_PAD_SIZE; i++) {
|
||||
// md2->X[32 + i] = md2->X[MD2_PAD_SIZE + i] ^ md2->X[i];
|
||||
// t = md2->C[i] ^= S[md2->buffer[i] ^ t];
|
||||
// }
|
||||
//
|
||||
// t=0;
|
||||
// for(i = 0; i < 18; i++) {
|
||||
// int j;
|
||||
// for(j = 0; j < MD2_X_SIZE; j += 8) {
|
||||
// t = md2->X[j+0] ^= S[t];
|
||||
// t = md2->X[j+1] ^= S[t];
|
||||
// t = md2->X[j+2] ^= S[t];
|
||||
// t = md2->X[j+3] ^= S[t];
|
||||
// t = md2->X[j+4] ^= S[t];
|
||||
// t = md2->X[j+5] ^= S[t];
|
||||
// t = md2->X[j+6] ^= S[t];
|
||||
// t = md2->X[j+7] ^= S[t];
|
||||
// }
|
||||
// t = (t + i) & 0xFF;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//void Md2Final(Md2* md2, byte* hash)
|
||||
//{
|
||||
// byte padding[MD2_BLOCK_SIZE];
|
||||
// word32 padLen = MD2_PAD_SIZE - md2->count;
|
||||
// word32 i;
|
||||
//
|
||||
// for (i = 0; i < padLen; i++)
|
||||
// padding[i] = (byte)padLen;
|
||||
//
|
||||
// Md2Update(md2, padding, padLen);
|
||||
// Md2Update(md2, md2->C, MD2_BLOCK_SIZE);
|
||||
//
|
||||
// XMEMCPY(hash, md2->X, MD2_DIGEST_SIZE);
|
||||
//
|
||||
// InitMd2(md2);
|
||||
//}
|
||||
//
|
||||
//
|
||||
//int Md2Hash(const byte* data, word32 len, byte* hash)
|
||||
//{
|
||||
//#ifdef CYASSL_SMALL_STACK
|
||||
// Md2* md2;
|
||||
//#else
|
||||
// Md2 md2[1];
|
||||
//#endif
|
||||
//
|
||||
//#ifdef CYASSL_SMALL_STACK
|
||||
// md2 = (Md2*)XMALLOC(sizeof(Md2), NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
// if (md2 == NULL)
|
||||
// return MEMORY_E;
|
||||
//#endif
|
||||
//
|
||||
// InitMd2(md2);
|
||||
// Md2Update(md2, data, len);
|
||||
// Md2Final(md2, hash);
|
||||
//
|
||||
//#ifdef CYASSL_SMALL_STACK
|
||||
// XFREE(md2, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
//#endif
|
||||
//
|
||||
// return 0;
|
||||
//}
|
||||
//
|
||||
//
|
||||
//#endif /* CYASSL_MD2 */
|
@ -1,219 +0,0 @@
|
||||
/* md4.c
|
||||
*
|
||||
* Copyright (C) 2006-2014 wolfSSL Inc.
|
||||
*
|
||||
* This file is part of wolfSSL. (formerly known as CyaSSL)
|
||||
*
|
||||
* wolfSSL is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wolfSSL is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
//#ifdef HAVE_CONFIG_H
|
||||
// #include <config.h>
|
||||
//#endif
|
||||
//
|
||||
//#include <cyassl/ctaocrypt/settings.h>
|
||||
//
|
||||
//#ifndef NO_MD4
|
||||
//
|
||||
//#include <cyassl/ctaocrypt/md4.h>
|
||||
//#ifdef NO_INLINE
|
||||
// #include <cyassl/ctaocrypt/misc.h>
|
||||
//#else
|
||||
// #include <ctaocrypt/src/misc.c>
|
||||
//#endif
|
||||
//
|
||||
//
|
||||
//#ifndef min
|
||||
//
|
||||
// static INLINE word32 min(word32 a, word32 b)
|
||||
// {
|
||||
// return a > b ? b : a;
|
||||
// }
|
||||
//
|
||||
//#endif /* min */
|
||||
//
|
||||
//
|
||||
//void InitMd4(Md4* md4)
|
||||
//{
|
||||
// md4->digest[0] = 0x67452301L;
|
||||
// md4->digest[1] = 0xefcdab89L;
|
||||
// md4->digest[2] = 0x98badcfeL;
|
||||
// md4->digest[3] = 0x10325476L;
|
||||
//
|
||||
// md4->buffLen = 0;
|
||||
// md4->loLen = 0;
|
||||
// md4->hiLen = 0;
|
||||
//}
|
||||
//
|
||||
//
|
||||
//static void Transform(Md4* md4)
|
||||
//{
|
||||
//#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
|
||||
//#define G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
|
||||
//#define H(x, y, z) ((x) ^ (y) ^ (z))
|
||||
//
|
||||
// /* Copy context->state[] to working vars */
|
||||
// word32 A = md4->digest[0];
|
||||
// word32 B = md4->digest[1];
|
||||
// word32 C = md4->digest[2];
|
||||
// word32 D = md4->digest[3];
|
||||
//
|
||||
//#define function(a,b,c,d,k,s) a=rotlFixed(a+F(b,c,d)+md4->buffer[k],s);
|
||||
// function(A,B,C,D, 0, 3);
|
||||
// function(D,A,B,C, 1, 7);
|
||||
// function(C,D,A,B, 2,11);
|
||||
// function(B,C,D,A, 3,19);
|
||||
// function(A,B,C,D, 4, 3);
|
||||
// function(D,A,B,C, 5, 7);
|
||||
// function(C,D,A,B, 6,11);
|
||||
// function(B,C,D,A, 7,19);
|
||||
// function(A,B,C,D, 8, 3);
|
||||
// function(D,A,B,C, 9, 7);
|
||||
// function(C,D,A,B,10,11);
|
||||
// function(B,C,D,A,11,19);
|
||||
// function(A,B,C,D,12, 3);
|
||||
// function(D,A,B,C,13, 7);
|
||||
// function(C,D,A,B,14,11);
|
||||
// function(B,C,D,A,15,19);
|
||||
//
|
||||
//#undef function
|
||||
//#define function(a,b,c,d,k,s) \
|
||||
// a=rotlFixed(a+G(b,c,d)+md4->buffer[k]+0x5a827999,s);
|
||||
//
|
||||
// function(A,B,C,D, 0, 3);
|
||||
// function(D,A,B,C, 4, 5);
|
||||
// function(C,D,A,B, 8, 9);
|
||||
// function(B,C,D,A,12,13);
|
||||
// function(A,B,C,D, 1, 3);
|
||||
// function(D,A,B,C, 5, 5);
|
||||
// function(C,D,A,B, 9, 9);
|
||||
// function(B,C,D,A,13,13);
|
||||
// function(A,B,C,D, 2, 3);
|
||||
// function(D,A,B,C, 6, 5);
|
||||
// function(C,D,A,B,10, 9);
|
||||
// function(B,C,D,A,14,13);
|
||||
// function(A,B,C,D, 3, 3);
|
||||
// function(D,A,B,C, 7, 5);
|
||||
// function(C,D,A,B,11, 9);
|
||||
// function(B,C,D,A,15,13);
|
||||
//
|
||||
//#undef function
|
||||
//#define function(a,b,c,d,k,s) \
|
||||
// a=rotlFixed(a+H(b,c,d)+md4->buffer[k]+0x6ed9eba1,s);
|
||||
//
|
||||
// function(A,B,C,D, 0, 3);
|
||||
// function(D,A,B,C, 8, 9);
|
||||
// function(C,D,A,B, 4,11);
|
||||
// function(B,C,D,A,12,15);
|
||||
// function(A,B,C,D, 2, 3);
|
||||
// function(D,A,B,C,10, 9);
|
||||
// function(C,D,A,B, 6,11);
|
||||
// function(B,C,D,A,14,15);
|
||||
// function(A,B,C,D, 1, 3);
|
||||
// function(D,A,B,C, 9, 9);
|
||||
// function(C,D,A,B, 5,11);
|
||||
// function(B,C,D,A,13,15);
|
||||
// function(A,B,C,D, 3, 3);
|
||||
// function(D,A,B,C,11, 9);
|
||||
// function(C,D,A,B, 7,11);
|
||||
// function(B,C,D,A,15,15);
|
||||
//
|
||||
// /* Add the working vars back into digest state[] */
|
||||
// md4->digest[0] += A;
|
||||
// md4->digest[1] += B;
|
||||
// md4->digest[2] += C;
|
||||
// md4->digest[3] += D;
|
||||
//}
|
||||
//
|
||||
//
|
||||
//static INLINE void AddLength(Md4* md4, word32 len)
|
||||
//{
|
||||
// word32 tmp = md4->loLen;
|
||||
// if ( (md4->loLen += len) < tmp)
|
||||
// md4->hiLen++; /* carry low to high */
|
||||
//}
|
||||
//
|
||||
//
|
||||
//void Md4Update(Md4* md4, const byte* data, word32 len)
|
||||
//{
|
||||
// /* do block size increments */
|
||||
// byte* local = (byte*)md4->buffer;
|
||||
//
|
||||
// while (len) {
|
||||
// word32 add = min(len, MD4_BLOCK_SIZE - md4->buffLen);
|
||||
// XMEMCPY(&local[md4->buffLen], data, add);
|
||||
//
|
||||
// md4->buffLen += add;
|
||||
// data += add;
|
||||
// len -= add;
|
||||
//
|
||||
// if (md4->buffLen == MD4_BLOCK_SIZE) {
|
||||
// #ifdef BIG_ENDIAN_ORDER
|
||||
// ByteReverseWords(md4->buffer, md4->buffer, MD4_BLOCK_SIZE);
|
||||
// #endif
|
||||
// Transform(md4);
|
||||
// AddLength(md4, MD4_BLOCK_SIZE);
|
||||
// md4->buffLen = 0;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//void Md4Final(Md4* md4, byte* hash)
|
||||
//{
|
||||
// byte* local = (byte*)md4->buffer;
|
||||
//
|
||||
// AddLength(md4, md4->buffLen); /* before adding pads */
|
||||
//
|
||||
// local[md4->buffLen++] = 0x80; /* add 1 */
|
||||
//
|
||||
// /* pad with zeros */
|
||||
// if (md4->buffLen > MD4_PAD_SIZE) {
|
||||
// XMEMSET(&local[md4->buffLen], 0, MD4_BLOCK_SIZE - md4->buffLen);
|
||||
// md4->buffLen += MD4_BLOCK_SIZE - md4->buffLen;
|
||||
//
|
||||
// #ifdef BIG_ENDIAN_ORDER
|
||||
// ByteReverseWords(md4->buffer, md4->buffer, MD4_BLOCK_SIZE);
|
||||
// #endif
|
||||
// Transform(md4);
|
||||
// md4->buffLen = 0;
|
||||
// }
|
||||
// XMEMSET(&local[md4->buffLen], 0, MD4_PAD_SIZE - md4->buffLen);
|
||||
//
|
||||
// /* put lengths in bits */
|
||||
// md4->hiLen = (md4->loLen >> (8*sizeof(md4->loLen) - 3)) +
|
||||
// (md4->hiLen << 3);
|
||||
// md4->loLen = md4->loLen << 3;
|
||||
//
|
||||
// /* store lengths */
|
||||
// #ifdef BIG_ENDIAN_ORDER
|
||||
// ByteReverseWords(md4->buffer, md4->buffer, MD4_BLOCK_SIZE);
|
||||
// #endif
|
||||
// /* ! length ordering dependent on digest endian type ! */
|
||||
// XMEMCPY(&local[MD4_PAD_SIZE], &md4->loLen, sizeof(word32));
|
||||
// XMEMCPY(&local[MD4_PAD_SIZE + sizeof(word32)], &md4->hiLen, sizeof(word32));
|
||||
//
|
||||
// Transform(md4);
|
||||
// #ifdef BIG_ENDIAN_ORDER
|
||||
// ByteReverseWords(md4->digest, md4->digest, MD4_DIGEST_SIZE);
|
||||
// #endif
|
||||
// XMEMCPY(hash, md4->digest, MD4_DIGEST_SIZE);
|
||||
//
|
||||
// InitMd4(md4); /* reset state */
|
||||
//}
|
||||
//
|
||||
//
|
||||
//#endif /* NO_MD4 */
|
||||
//
|
@ -1,391 +0,0 @@
|
||||
/* md5.c
|
||||
*
|
||||
* Copyright (C) 2006-2014 wolfSSL Inc.
|
||||
*
|
||||
* This file is part of wolfSSL. (formerly known as CyaSSL)
|
||||
*
|
||||
* wolfSSL is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wolfSSL is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <cyassl/ctaocrypt/settings.h>
|
||||
|
||||
#if !defined(NO_MD5)
|
||||
|
||||
#ifdef CYASSL_PIC32MZ_HASH
|
||||
#define InitMd5 InitMd5_sw
|
||||
#define Md5Update Md5Update_sw
|
||||
#define Md5Final Md5Final_sw
|
||||
#endif
|
||||
|
||||
#include <cyassl/ctaocrypt/md5.h>
|
||||
#include <cyassl/ctaocrypt/error-crypt.h>
|
||||
|
||||
#ifdef NO_INLINE
|
||||
#include <cyassl/ctaocrypt/misc.h>
|
||||
#else
|
||||
#include <ctaocrypt/src/misc.c>
|
||||
#endif
|
||||
|
||||
#ifdef FREESCALE_MMCAU
|
||||
#include "cau_api.h"
|
||||
#define XTRANSFORM(S,B) cau_md5_hash_n((B), 1, (unsigned char*)(S)->digest)
|
||||
#else
|
||||
#define XTRANSFORM(S,B) Transform((S))
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef STM32F2_HASH
|
||||
/*
|
||||
* STM32F2 hardware MD5 support through the STM32F2 standard peripheral
|
||||
* library. Documentation located in STM32F2xx Standard Peripheral Library
|
||||
* document (See note in README).
|
||||
*/
|
||||
#include "stm32f2xx.h"
|
||||
|
||||
void InitMd5(Md5* md5)
|
||||
{
|
||||
/* STM32F2 struct notes:
|
||||
* md5->buffer = first 4 bytes used to hold partial block if needed
|
||||
* md5->buffLen = num bytes currently stored in md5->buffer
|
||||
* md5->loLen = num bytes that have been written to STM32 FIFO
|
||||
*/
|
||||
XMEMSET(md5->buffer, 0, MD5_REG_SIZE);
|
||||
|
||||
md5->buffLen = 0;
|
||||
md5->loLen = 0;
|
||||
|
||||
/* initialize HASH peripheral */
|
||||
HASH_DeInit();
|
||||
|
||||
/* configure algo used, algo mode, datatype */
|
||||
HASH->CR &= ~ (HASH_CR_ALGO | HASH_CR_DATATYPE | HASH_CR_MODE);
|
||||
HASH->CR |= (HASH_AlgoSelection_MD5 | HASH_AlgoMode_HASH
|
||||
| HASH_DataType_8b);
|
||||
|
||||
/* reset HASH processor */
|
||||
HASH->CR |= HASH_CR_INIT;
|
||||
}
|
||||
|
||||
void Md5Update(Md5* md5, const byte* data, word32 len)
|
||||
{
|
||||
word32 i = 0;
|
||||
word32 fill = 0;
|
||||
word32 diff = 0;
|
||||
|
||||
/* if saved partial block is available */
|
||||
if (md5->buffLen > 0) {
|
||||
fill = 4 - md5->buffLen;
|
||||
|
||||
/* if enough data to fill, fill and push to FIFO */
|
||||
if (fill <= len) {
|
||||
XMEMCPY((byte*)md5->buffer + md5->buffLen, data, fill);
|
||||
HASH_DataIn(*(uint32_t*)md5->buffer);
|
||||
|
||||
data += fill;
|
||||
len -= fill;
|
||||
md5->loLen += 4;
|
||||
md5->buffLen = 0;
|
||||
} else {
|
||||
/* append partial to existing stored block */
|
||||
XMEMCPY((byte*)md5->buffer + md5->buffLen, data, len);
|
||||
md5->buffLen += len;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* write input block in the IN FIFO */
|
||||
for (i = 0; i < len; i += 4)
|
||||
{
|
||||
diff = len - i;
|
||||
if (diff < 4) {
|
||||
/* store incomplete last block, not yet in FIFO */
|
||||
XMEMSET(md5->buffer, 0, MD5_REG_SIZE);
|
||||
XMEMCPY((byte*)md5->buffer, data, diff);
|
||||
md5->buffLen = diff;
|
||||
} else {
|
||||
HASH_DataIn(*(uint32_t*)data);
|
||||
data+=4;
|
||||
}
|
||||
}
|
||||
|
||||
/* keep track of total data length thus far */
|
||||
md5->loLen += (len - md5->buffLen);
|
||||
}
|
||||
|
||||
void Md5Final(Md5* md5, byte* hash)
|
||||
{
|
||||
__IO uint16_t nbvalidbitsdata = 0;
|
||||
|
||||
/* finish reading any trailing bytes into FIFO */
|
||||
if (md5->buffLen > 0) {
|
||||
HASH_DataIn(*(uint32_t*)md5->buffer);
|
||||
md5->loLen += md5->buffLen;
|
||||
}
|
||||
|
||||
/* calculate number of valid bits in last word of input data */
|
||||
nbvalidbitsdata = 8 * (md5->loLen % MD5_REG_SIZE);
|
||||
|
||||
/* configure number of valid bits in last word of the data */
|
||||
HASH_SetLastWordValidBitsNbr(nbvalidbitsdata);
|
||||
|
||||
/* start HASH processor */
|
||||
HASH_StartDigest();
|
||||
|
||||
/* wait until Busy flag == RESET */
|
||||
while (HASH_GetFlagStatus(HASH_FLAG_BUSY) != RESET) {}
|
||||
|
||||
/* read message digest */
|
||||
md5->digest[0] = HASH->HR[0];
|
||||
md5->digest[1] = HASH->HR[1];
|
||||
md5->digest[2] = HASH->HR[2];
|
||||
md5->digest[3] = HASH->HR[3];
|
||||
|
||||
ByteReverseWords(md5->digest, md5->digest, MD5_DIGEST_SIZE);
|
||||
|
||||
XMEMCPY(hash, md5->digest, MD5_DIGEST_SIZE);
|
||||
|
||||
InitMd5(md5); /* reset state */
|
||||
}
|
||||
|
||||
#else /* CTaoCrypt software implementation */
|
||||
|
||||
#ifndef min
|
||||
|
||||
static INLINE word32 min(word32 a, word32 b)
|
||||
{
|
||||
return a > b ? b : a;
|
||||
}
|
||||
|
||||
#endif /* min */
|
||||
|
||||
|
||||
void InitMd5(Md5* md5)
|
||||
{
|
||||
md5->digest[0] = 0x67452301L;
|
||||
md5->digest[1] = 0xefcdab89L;
|
||||
md5->digest[2] = 0x98badcfeL;
|
||||
md5->digest[3] = 0x10325476L;
|
||||
|
||||
md5->buffLen = 0;
|
||||
md5->loLen = 0;
|
||||
md5->hiLen = 0;
|
||||
}
|
||||
|
||||
#ifndef FREESCALE_MMCAU
|
||||
|
||||
static void Transform(Md5* md5)
|
||||
{
|
||||
#define F1(x, y, z) (z ^ (x & (y ^ z)))
|
||||
#define F2(x, y, z) F1(z, x, y)
|
||||
#define F3(x, y, z) (x ^ y ^ z)
|
||||
#define F4(x, y, z) (y ^ (x | ~z))
|
||||
|
||||
#define MD5STEP(f, w, x, y, z, data, s) \
|
||||
w = rotlFixed(w + f(x, y, z) + data, s) + x
|
||||
|
||||
/* Copy context->state[] to working vars */
|
||||
word32 a = md5->digest[0];
|
||||
word32 b = md5->digest[1];
|
||||
word32 c = md5->digest[2];
|
||||
word32 d = md5->digest[3];
|
||||
|
||||
MD5STEP(F1, a, b, c, d, md5->buffer[0] + 0xd76aa478, 7);
|
||||
MD5STEP(F1, d, a, b, c, md5->buffer[1] + 0xe8c7b756, 12);
|
||||
MD5STEP(F1, c, d, a, b, md5->buffer[2] + 0x242070db, 17);
|
||||
MD5STEP(F1, b, c, d, a, md5->buffer[3] + 0xc1bdceee, 22);
|
||||
MD5STEP(F1, a, b, c, d, md5->buffer[4] + 0xf57c0faf, 7);
|
||||
MD5STEP(F1, d, a, b, c, md5->buffer[5] + 0x4787c62a, 12);
|
||||
MD5STEP(F1, c, d, a, b, md5->buffer[6] + 0xa8304613, 17);
|
||||
MD5STEP(F1, b, c, d, a, md5->buffer[7] + 0xfd469501, 22);
|
||||
MD5STEP(F1, a, b, c, d, md5->buffer[8] + 0x698098d8, 7);
|
||||
MD5STEP(F1, d, a, b, c, md5->buffer[9] + 0x8b44f7af, 12);
|
||||
MD5STEP(F1, c, d, a, b, md5->buffer[10] + 0xffff5bb1, 17);
|
||||
MD5STEP(F1, b, c, d, a, md5->buffer[11] + 0x895cd7be, 22);
|
||||
MD5STEP(F1, a, b, c, d, md5->buffer[12] + 0x6b901122, 7);
|
||||
MD5STEP(F1, d, a, b, c, md5->buffer[13] + 0xfd987193, 12);
|
||||
MD5STEP(F1, c, d, a, b, md5->buffer[14] + 0xa679438e, 17);
|
||||
MD5STEP(F1, b, c, d, a, md5->buffer[15] + 0x49b40821, 22);
|
||||
|
||||
MD5STEP(F2, a, b, c, d, md5->buffer[1] + 0xf61e2562, 5);
|
||||
MD5STEP(F2, d, a, b, c, md5->buffer[6] + 0xc040b340, 9);
|
||||
MD5STEP(F2, c, d, a, b, md5->buffer[11] + 0x265e5a51, 14);
|
||||
MD5STEP(F2, b, c, d, a, md5->buffer[0] + 0xe9b6c7aa, 20);
|
||||
MD5STEP(F2, a, b, c, d, md5->buffer[5] + 0xd62f105d, 5);
|
||||
MD5STEP(F2, d, a, b, c, md5->buffer[10] + 0x02441453, 9);
|
||||
MD5STEP(F2, c, d, a, b, md5->buffer[15] + 0xd8a1e681, 14);
|
||||
MD5STEP(F2, b, c, d, a, md5->buffer[4] + 0xe7d3fbc8, 20);
|
||||
MD5STEP(F2, a, b, c, d, md5->buffer[9] + 0x21e1cde6, 5);
|
||||
MD5STEP(F2, d, a, b, c, md5->buffer[14] + 0xc33707d6, 9);
|
||||
MD5STEP(F2, c, d, a, b, md5->buffer[3] + 0xf4d50d87, 14);
|
||||
MD5STEP(F2, b, c, d, a, md5->buffer[8] + 0x455a14ed, 20);
|
||||
MD5STEP(F2, a, b, c, d, md5->buffer[13] + 0xa9e3e905, 5);
|
||||
MD5STEP(F2, d, a, b, c, md5->buffer[2] + 0xfcefa3f8, 9);
|
||||
MD5STEP(F2, c, d, a, b, md5->buffer[7] + 0x676f02d9, 14);
|
||||
MD5STEP(F2, b, c, d, a, md5->buffer[12] + 0x8d2a4c8a, 20);
|
||||
|
||||
MD5STEP(F3, a, b, c, d, md5->buffer[5] + 0xfffa3942, 4);
|
||||
MD5STEP(F3, d, a, b, c, md5->buffer[8] + 0x8771f681, 11);
|
||||
MD5STEP(F3, c, d, a, b, md5->buffer[11] + 0x6d9d6122, 16);
|
||||
MD5STEP(F3, b, c, d, a, md5->buffer[14] + 0xfde5380c, 23);
|
||||
MD5STEP(F3, a, b, c, d, md5->buffer[1] + 0xa4beea44, 4);
|
||||
MD5STEP(F3, d, a, b, c, md5->buffer[4] + 0x4bdecfa9, 11);
|
||||
MD5STEP(F3, c, d, a, b, md5->buffer[7] + 0xf6bb4b60, 16);
|
||||
MD5STEP(F3, b, c, d, a, md5->buffer[10] + 0xbebfbc70, 23);
|
||||
MD5STEP(F3, a, b, c, d, md5->buffer[13] + 0x289b7ec6, 4);
|
||||
MD5STEP(F3, d, a, b, c, md5->buffer[0] + 0xeaa127fa, 11);
|
||||
MD5STEP(F3, c, d, a, b, md5->buffer[3] + 0xd4ef3085, 16);
|
||||
MD5STEP(F3, b, c, d, a, md5->buffer[6] + 0x04881d05, 23);
|
||||
MD5STEP(F3, a, b, c, d, md5->buffer[9] + 0xd9d4d039, 4);
|
||||
MD5STEP(F3, d, a, b, c, md5->buffer[12] + 0xe6db99e5, 11);
|
||||
MD5STEP(F3, c, d, a, b, md5->buffer[15] + 0x1fa27cf8, 16);
|
||||
MD5STEP(F3, b, c, d, a, md5->buffer[2] + 0xc4ac5665, 23);
|
||||
|
||||
MD5STEP(F4, a, b, c, d, md5->buffer[0] + 0xf4292244, 6);
|
||||
MD5STEP(F4, d, a, b, c, md5->buffer[7] + 0x432aff97, 10);
|
||||
MD5STEP(F4, c, d, a, b, md5->buffer[14] + 0xab9423a7, 15);
|
||||
MD5STEP(F4, b, c, d, a, md5->buffer[5] + 0xfc93a039, 21);
|
||||
MD5STEP(F4, a, b, c, d, md5->buffer[12] + 0x655b59c3, 6);
|
||||
MD5STEP(F4, d, a, b, c, md5->buffer[3] + 0x8f0ccc92, 10);
|
||||
MD5STEP(F4, c, d, a, b, md5->buffer[10] + 0xffeff47d, 15);
|
||||
MD5STEP(F4, b, c, d, a, md5->buffer[1] + 0x85845dd1, 21);
|
||||
MD5STEP(F4, a, b, c, d, md5->buffer[8] + 0x6fa87e4f, 6);
|
||||
MD5STEP(F4, d, a, b, c, md5->buffer[15] + 0xfe2ce6e0, 10);
|
||||
MD5STEP(F4, c, d, a, b, md5->buffer[6] + 0xa3014314, 15);
|
||||
MD5STEP(F4, b, c, d, a, md5->buffer[13] + 0x4e0811a1, 21);
|
||||
MD5STEP(F4, a, b, c, d, md5->buffer[4] + 0xf7537e82, 6);
|
||||
MD5STEP(F4, d, a, b, c, md5->buffer[11] + 0xbd3af235, 10);
|
||||
MD5STEP(F4, c, d, a, b, md5->buffer[2] + 0x2ad7d2bb, 15);
|
||||
MD5STEP(F4, b, c, d, a, md5->buffer[9] + 0xeb86d391, 21);
|
||||
|
||||
/* Add the working vars back into digest state[] */
|
||||
md5->digest[0] += a;
|
||||
md5->digest[1] += b;
|
||||
md5->digest[2] += c;
|
||||
md5->digest[3] += d;
|
||||
}
|
||||
|
||||
#endif /* FREESCALE_MMCAU */
|
||||
|
||||
|
||||
static INLINE void AddLength(Md5* md5, word32 len)
|
||||
{
|
||||
word32 tmp = md5->loLen;
|
||||
if ( (md5->loLen += len) < tmp)
|
||||
md5->hiLen++; /* carry low to high */
|
||||
}
|
||||
|
||||
|
||||
void Md5Update(Md5* md5, const byte* data, word32 len)
|
||||
{
|
||||
/* do block size increments */
|
||||
byte* local = (byte*)md5->buffer;
|
||||
|
||||
while (len) {
|
||||
word32 add = min(len, MD5_BLOCK_SIZE - md5->buffLen);
|
||||
XMEMCPY(&local[md5->buffLen], data, add);
|
||||
|
||||
md5->buffLen += add;
|
||||
data += add;
|
||||
len -= add;
|
||||
|
||||
if (md5->buffLen == MD5_BLOCK_SIZE) {
|
||||
#if defined(BIG_ENDIAN_ORDER) && !defined(FREESCALE_MMCAU)
|
||||
ByteReverseWords(md5->buffer, md5->buffer, MD5_BLOCK_SIZE);
|
||||
#endif
|
||||
XTRANSFORM(md5, local);
|
||||
AddLength(md5, MD5_BLOCK_SIZE);
|
||||
md5->buffLen = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Md5Final(Md5* md5, byte* hash)
|
||||
{
|
||||
byte* local = (byte*)md5->buffer;
|
||||
|
||||
AddLength(md5, md5->buffLen); /* before adding pads */
|
||||
|
||||
local[md5->buffLen++] = 0x80; /* add 1 */
|
||||
|
||||
/* pad with zeros */
|
||||
if (md5->buffLen > MD5_PAD_SIZE) {
|
||||
XMEMSET(&local[md5->buffLen], 0, MD5_BLOCK_SIZE - md5->buffLen);
|
||||
md5->buffLen += MD5_BLOCK_SIZE - md5->buffLen;
|
||||
|
||||
#if defined(BIG_ENDIAN_ORDER) && !defined(FREESCALE_MMCAU)
|
||||
ByteReverseWords(md5->buffer, md5->buffer, MD5_BLOCK_SIZE);
|
||||
#endif
|
||||
XTRANSFORM(md5, local);
|
||||
md5->buffLen = 0;
|
||||
}
|
||||
XMEMSET(&local[md5->buffLen], 0, MD5_PAD_SIZE - md5->buffLen);
|
||||
|
||||
/* put lengths in bits */
|
||||
md5->hiLen = (md5->loLen >> (8*sizeof(md5->loLen) - 3)) +
|
||||
(md5->hiLen << 3);
|
||||
md5->loLen = md5->loLen << 3;
|
||||
|
||||
/* store lengths */
|
||||
#if defined(BIG_ENDIAN_ORDER) && !defined(FREESCALE_MMCAU)
|
||||
ByteReverseWords(md5->buffer, md5->buffer, MD5_BLOCK_SIZE);
|
||||
#endif
|
||||
/* ! length ordering dependent on digest endian type ! */
|
||||
XMEMCPY(&local[MD5_PAD_SIZE], &md5->loLen, sizeof(word32));
|
||||
XMEMCPY(&local[MD5_PAD_SIZE + sizeof(word32)], &md5->hiLen, sizeof(word32));
|
||||
|
||||
XTRANSFORM(md5, local);
|
||||
#ifdef BIG_ENDIAN_ORDER
|
||||
ByteReverseWords(md5->digest, md5->digest, MD5_DIGEST_SIZE);
|
||||
#endif
|
||||
XMEMCPY(hash, md5->digest, MD5_DIGEST_SIZE);
|
||||
|
||||
InitMd5(md5); /* reset state */
|
||||
}
|
||||
|
||||
#endif /* STM32F2_HASH */
|
||||
|
||||
|
||||
int Md5Hash(const byte* data, word32 len, byte* hash)
|
||||
{
|
||||
#ifdef CYASSL_SMALL_STACK
|
||||
Md5* md5;
|
||||
#else
|
||||
Md5 md5[1];
|
||||
#endif
|
||||
|
||||
#ifdef CYASSL_SMALL_STACK
|
||||
md5 = (Md5*)XMALLOC(sizeof(Md5), NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (md5 == NULL)
|
||||
return MEMORY_E;
|
||||
#endif
|
||||
|
||||
InitMd5(md5);
|
||||
Md5Update(md5, data, len);
|
||||
Md5Final(md5, hash);
|
||||
|
||||
#ifdef CYASSL_SMALL_STACK
|
||||
XFREE(md5, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* NO_MD5 */
|
@ -1,183 +0,0 @@
|
||||
/* memory.c
|
||||
*
|
||||
* Copyright (C) 2006-2014 wolfSSL Inc.
|
||||
*
|
||||
* This file is part of wolfSSL. (formerly known as CyaSSL)
|
||||
*
|
||||
* wolfSSL is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wolfSSL is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <cyassl/ctaocrypt/settings.h>
|
||||
|
||||
#ifdef USE_CYASSL_MEMORY
|
||||
|
||||
#include <cyassl/ctaocrypt/memory.h>
|
||||
#include <cyassl/ctaocrypt/error-crypt.h>
|
||||
|
||||
#ifdef CYASSL_MALLOC_CHECK
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
/* Set these to default values initially. */
|
||||
static CyaSSL_Malloc_cb malloc_function = 0;
|
||||
static CyaSSL_Free_cb free_function = 0;
|
||||
static CyaSSL_Realloc_cb realloc_function = 0;
|
||||
|
||||
int CyaSSL_SetAllocators(CyaSSL_Malloc_cb mf,
|
||||
CyaSSL_Free_cb ff,
|
||||
CyaSSL_Realloc_cb rf)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
if (mf)
|
||||
malloc_function = mf;
|
||||
else
|
||||
res = BAD_FUNC_ARG;
|
||||
|
||||
if (ff)
|
||||
free_function = ff;
|
||||
else
|
||||
res = BAD_FUNC_ARG;
|
||||
|
||||
if (rf)
|
||||
realloc_function = rf;
|
||||
else
|
||||
res = BAD_FUNC_ARG;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
void* CyaSSL_Malloc(size_t size)
|
||||
{
|
||||
void* res = 0;
|
||||
|
||||
if (malloc_function)
|
||||
res = malloc_function(size);
|
||||
else
|
||||
res = malloc(size);
|
||||
|
||||
#ifdef CYASSL_MALLOC_CHECK
|
||||
if (res == NULL)
|
||||
puts("CyaSSL_malloc failed");
|
||||
#endif
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void CyaSSL_Free(void *ptr)
|
||||
{
|
||||
if (free_function)
|
||||
free_function(ptr);
|
||||
else
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
void* CyaSSL_Realloc(void *ptr, size_t size)
|
||||
{
|
||||
void* res = 0;
|
||||
|
||||
if (realloc_function)
|
||||
res = realloc_function(ptr, size);
|
||||
else
|
||||
res = realloc(ptr, size);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
#endif /* USE_CYASSL_MEMORY */
|
||||
|
||||
|
||||
#ifdef HAVE_IO_POOL
|
||||
|
||||
/* Example for user io pool, shared build may need definitions in lib proper */
|
||||
|
||||
#include <cyassl/ctaocrypt/types.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
#error "Oops, simple I/O pool example needs thread local storage"
|
||||
#endif
|
||||
|
||||
|
||||
/* allow simple per thread in and out pools */
|
||||
/* use 17k size sense max record size is 16k plus overhead */
|
||||
static THREAD_LS_T byte pool_in[17*1024];
|
||||
static THREAD_LS_T byte pool_out[17*1024];
|
||||
|
||||
|
||||
void* XMALLOC(size_t n, void* heap, int type)
|
||||
{
|
||||
(void)heap;
|
||||
|
||||
if (type == DYNAMIC_TYPE_IN_BUFFER) {
|
||||
if (n < sizeof(pool_in))
|
||||
return pool_in;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (type == DYNAMIC_TYPE_OUT_BUFFER) {
|
||||
if (n < sizeof(pool_out))
|
||||
return pool_out;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return malloc(n);
|
||||
}
|
||||
|
||||
void* XREALLOC(void *p, size_t n, void* heap, int type)
|
||||
{
|
||||
(void)heap;
|
||||
|
||||
if (type == DYNAMIC_TYPE_IN_BUFFER) {
|
||||
if (n < sizeof(pool_in))
|
||||
return pool_in;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (type == DYNAMIC_TYPE_OUT_BUFFER) {
|
||||
if (n < sizeof(pool_out))
|
||||
return pool_out;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return realloc(p, n);
|
||||
}
|
||||
|
||||
|
||||
/* unit api calls, let's make sure visisble with CYASSL_API */
|
||||
CYASSL_API void XFREE(void *p, void* heap, int type)
|
||||
{
|
||||
(void)heap;
|
||||
|
||||
if (type == DYNAMIC_TYPE_IN_BUFFER)
|
||||
return; /* do nothing, static pool */
|
||||
|
||||
if (type == DYNAMIC_TYPE_OUT_BUFFER)
|
||||
return; /* do nothing, static pool */
|
||||
|
||||
free(p);
|
||||
}
|
||||
|
||||
#endif /* HAVE_IO_POOL */
|
||||
|
@ -19,155 +19,8 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <cyassl/ctaocrypt/settings.h>
|
||||
|
||||
#include <cyassl/ctaocrypt/misc.h>
|
||||
|
||||
/* inlining these functions is a huge speed increase and a small size decrease,
|
||||
because the functions are smaller than function call setup/cleanup, e.g.,
|
||||
md5 benchmark is twice as fast with inline. If you don't want it, then
|
||||
define NO_INLINE and compile this file into cyassl, otherwise it's used as
|
||||
a source header
|
||||
*/
|
||||
|
||||
#ifdef NO_INLINE
|
||||
#define STATIC
|
||||
#include <wolfssl/wolfcrypt/misc.h>
|
||||
#else
|
||||
#define STATIC static
|
||||
#include <wolfcrypt/src/misc.c>
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef INTEL_INTRINSICS
|
||||
|
||||
#include <stdlib.h> /* get intrinsic definitions */
|
||||
|
||||
/* for non visual studio probably need no long version, 32 bit only
|
||||
* i.e., _rotl and _rotr */
|
||||
#pragma intrinsic(_lrotl, _lrotr)
|
||||
|
||||
STATIC INLINE word32 rotlFixed(word32 x, word32 y)
|
||||
{
|
||||
return y ? _lrotl(x, y) : x;
|
||||
}
|
||||
|
||||
STATIC INLINE word32 rotrFixed(word32 x, word32 y)
|
||||
{
|
||||
return y ? _lrotr(x, y) : x;
|
||||
}
|
||||
|
||||
#else /* generic */
|
||||
|
||||
STATIC INLINE word32 rotlFixed(word32 x, word32 y)
|
||||
{
|
||||
return (x << y) | (x >> (sizeof(y) * 8 - y));
|
||||
}
|
||||
|
||||
|
||||
STATIC INLINE word32 rotrFixed(word32 x, word32 y)
|
||||
{
|
||||
return (x >> y) | (x << (sizeof(y) * 8 - y));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
STATIC INLINE word32 ByteReverseWord32(word32 value)
|
||||
{
|
||||
#ifdef PPC_INTRINSICS
|
||||
/* PPC: load reverse indexed instruction */
|
||||
return (word32)__lwbrx(&value,0);
|
||||
#elif defined(KEIL_INTRINSICS)
|
||||
return (word32)__rev(value);
|
||||
#elif defined(FAST_ROTATE)
|
||||
/* 5 instructions with rotate instruction, 9 without */
|
||||
return (rotrFixed(value, 8U) & 0xff00ff00) |
|
||||
(rotlFixed(value, 8U) & 0x00ff00ff);
|
||||
#else
|
||||
/* 6 instructions with rotate instruction, 8 without */
|
||||
value = ((value & 0xFF00FF00) >> 8) | ((value & 0x00FF00FF) << 8);
|
||||
return rotlFixed(value, 16U);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
STATIC INLINE void ByteReverseWords(word32* out, const word32* in,
|
||||
word32 byteCount)
|
||||
{
|
||||
word32 count = byteCount/(word32)sizeof(word32), i;
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
out[i] = ByteReverseWord32(in[i]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
#ifdef WORD64_AVAILABLE
|
||||
|
||||
|
||||
STATIC INLINE word64 rotlFixed64(word64 x, word64 y)
|
||||
{
|
||||
return (x << y) | (x >> (sizeof(y) * 8 - y));
|
||||
}
|
||||
|
||||
|
||||
STATIC INLINE word64 rotrFixed64(word64 x, word64 y)
|
||||
{
|
||||
return (x >> y) | (x << (sizeof(y) * 8 - y));
|
||||
}
|
||||
|
||||
|
||||
STATIC INLINE word64 ByteReverseWord64(word64 value)
|
||||
{
|
||||
#ifdef CTAOCRYPT_SLOW_WORD64
|
||||
return (word64)(ByteReverseWord32((word32)value)) << 32 |
|
||||
ByteReverseWord32((word32)(value>>32));
|
||||
#else
|
||||
value = ((value & W64LIT(0xFF00FF00FF00FF00)) >> 8) |
|
||||
((value & W64LIT(0x00FF00FF00FF00FF)) << 8);
|
||||
value = ((value & W64LIT(0xFFFF0000FFFF0000)) >> 16) |
|
||||
((value & W64LIT(0x0000FFFF0000FFFF)) << 16);
|
||||
return rotlFixed64(value, 32U);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
STATIC INLINE void ByteReverseWords64(word64* out, const word64* in,
|
||||
word32 byteCount)
|
||||
{
|
||||
word32 count = byteCount/(word32)sizeof(word64), i;
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
out[i] = ByteReverseWord64(in[i]);
|
||||
|
||||
}
|
||||
|
||||
#endif /* WORD64_AVAILABLE */
|
||||
|
||||
|
||||
STATIC INLINE void XorWords(cyassl_word* r, const cyassl_word* a, word32 n)
|
||||
{
|
||||
word32 i;
|
||||
|
||||
for (i = 0; i < n; i++) r[i] ^= a[i];
|
||||
}
|
||||
|
||||
|
||||
STATIC INLINE void xorbuf(void* buf, const void* mask, word32 count)
|
||||
{
|
||||
if (((cyassl_word)buf | (cyassl_word)mask | count) % CYASSL_WORD_SIZE == 0)
|
||||
XorWords( (cyassl_word*)buf,
|
||||
(const cyassl_word*)mask, count / CYASSL_WORD_SIZE);
|
||||
else {
|
||||
word32 i;
|
||||
byte* b = (byte*)buf;
|
||||
const byte* m = (const byte*)mask;
|
||||
|
||||
for (i = 0; i < count; i++) b[i] ^= m[i];
|
||||
}
|
||||
}
|
||||
#undef STATIC
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,474 +0,0 @@
|
||||
/* pwdbased.c
|
||||
*
|
||||
* Copyright (C) 2006-2014 wolfSSL Inc.
|
||||
*
|
||||
* This file is part of wolfSSL. (formerly known as CyaSSL)
|
||||
*
|
||||
* wolfSSL is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wolfSSL is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <cyassl/ctaocrypt/settings.h>
|
||||
|
||||
#ifndef NO_PWDBASED
|
||||
|
||||
#ifdef CYASSL_PIC32MZ_HASH
|
||||
|
||||
#define InitMd5 InitMd5_sw
|
||||
#define Md5Update Md5Update_sw
|
||||
#define Md5Final Md5Final_sw
|
||||
|
||||
#define InitSha InitSha_sw
|
||||
#define ShaUpdate ShaUpdate_sw
|
||||
#define ShaFinal ShaFinal_sw
|
||||
|
||||
#define InitSha256 InitSha256_sw
|
||||
#define Sha256Update Sha256Update_sw
|
||||
#define Sha256Final Sha256Final_sw
|
||||
|
||||
#endif
|
||||
|
||||
#include <cyassl/ctaocrypt/pwdbased.h>
|
||||
#include <cyassl/ctaocrypt/hmac.h>
|
||||
#include <cyassl/ctaocrypt/integer.h>
|
||||
#include <cyassl/ctaocrypt/error-crypt.h>
|
||||
#if defined(CYASSL_SHA512) || defined(CYASSL_SHA384)
|
||||
#include <cyassl/ctaocrypt/sha512.h>
|
||||
#endif
|
||||
|
||||
#ifdef NO_INLINE
|
||||
#include <cyassl/ctaocrypt/misc.h>
|
||||
#else
|
||||
#include <ctaocrypt/src/misc.c>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef min
|
||||
|
||||
static INLINE word32 min(word32 a, word32 b)
|
||||
{
|
||||
return a > b ? b : a;
|
||||
}
|
||||
|
||||
#endif /* min */
|
||||
|
||||
|
||||
int PBKDF1(byte* output, const byte* passwd, int pLen, const byte* salt,
|
||||
int sLen, int iterations, int kLen, int hashType)
|
||||
{
|
||||
Md5 md5;
|
||||
Sha sha;
|
||||
int hLen = (hashType == MD5) ? (int)MD5_DIGEST_SIZE : (int)SHA_DIGEST_SIZE;
|
||||
int i, ret = 0;
|
||||
byte buffer[SHA_DIGEST_SIZE]; /* max size */
|
||||
|
||||
if (hashType != MD5 && hashType != SHA)
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
if (kLen > hLen)
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
if (iterations < 1)
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
if (hashType == MD5) {
|
||||
InitMd5(&md5);
|
||||
Md5Update(&md5, passwd, pLen);
|
||||
Md5Update(&md5, salt, sLen);
|
||||
Md5Final(&md5, buffer);
|
||||
}
|
||||
else {
|
||||
ret = InitSha(&sha);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
ShaUpdate(&sha, passwd, pLen);
|
||||
ShaUpdate(&sha, salt, sLen);
|
||||
ShaFinal(&sha, buffer);
|
||||
}
|
||||
|
||||
for (i = 1; i < iterations; i++) {
|
||||
if (hashType == MD5) {
|
||||
Md5Update(&md5, buffer, hLen);
|
||||
Md5Final(&md5, buffer);
|
||||
}
|
||||
else {
|
||||
ShaUpdate(&sha, buffer, hLen);
|
||||
ShaFinal(&sha, buffer);
|
||||
}
|
||||
}
|
||||
XMEMCPY(output, buffer, kLen);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int PBKDF2(byte* output, const byte* passwd, int pLen, const byte* salt,
|
||||
int sLen, int iterations, int kLen, int hashType)
|
||||
{
|
||||
word32 i = 1;
|
||||
int hLen;
|
||||
int j, ret;
|
||||
Hmac hmac;
|
||||
#ifdef CYASSL_SMALL_STACK
|
||||
byte* buffer;
|
||||
#else
|
||||
byte buffer[MAX_DIGEST_SIZE];
|
||||
#endif
|
||||
|
||||
if (hashType == MD5) {
|
||||
hLen = MD5_DIGEST_SIZE;
|
||||
}
|
||||
else if (hashType == SHA) {
|
||||
hLen = SHA_DIGEST_SIZE;
|
||||
}
|
||||
#ifndef NO_SHA256
|
||||
else if (hashType == SHA256) {
|
||||
hLen = SHA256_DIGEST_SIZE;
|
||||
}
|
||||
#endif
|
||||
#ifdef CYASSL_SHA512
|
||||
else if (hashType == SHA512) {
|
||||
hLen = SHA512_DIGEST_SIZE;
|
||||
}
|
||||
#endif
|
||||
else
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
#ifdef CYASSL_SMALL_STACK
|
||||
buffer = (byte*)XMALLOC(MAX_DIGEST_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (buffer == NULL)
|
||||
return MEMORY_E;
|
||||
#endif
|
||||
|
||||
ret = HmacSetKey(&hmac, hashType, passwd, pLen);
|
||||
|
||||
if (ret == 0) {
|
||||
while (kLen) {
|
||||
int currentLen;
|
||||
|
||||
ret = HmacUpdate(&hmac, salt, sLen);
|
||||
if (ret != 0)
|
||||
break;
|
||||
|
||||
/* encode i */
|
||||
for (j = 0; j < 4; j++) {
|
||||
byte b = (byte)(i >> ((3-j) * 8));
|
||||
|
||||
ret = HmacUpdate(&hmac, &b, 1);
|
||||
if (ret != 0)
|
||||
break;
|
||||
}
|
||||
|
||||
/* check ret from inside for loop */
|
||||
if (ret != 0)
|
||||
break;
|
||||
|
||||
ret = HmacFinal(&hmac, buffer);
|
||||
if (ret != 0)
|
||||
break;
|
||||
|
||||
currentLen = min(kLen, hLen);
|
||||
XMEMCPY(output, buffer, currentLen);
|
||||
|
||||
for (j = 1; j < iterations; j++) {
|
||||
ret = HmacUpdate(&hmac, buffer, hLen);
|
||||
if (ret != 0)
|
||||
break;
|
||||
ret = HmacFinal(&hmac, buffer);
|
||||
if (ret != 0)
|
||||
break;
|
||||
xorbuf(output, buffer, currentLen);
|
||||
}
|
||||
|
||||
/* check ret from inside for loop */
|
||||
if (ret != 0)
|
||||
break;
|
||||
|
||||
output += currentLen;
|
||||
kLen -= currentLen;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CYASSL_SMALL_STACK
|
||||
XFREE(buffer, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef CYASSL_SHA512
|
||||
#define PBKDF_DIGEST_SIZE SHA512_BLOCK_SIZE
|
||||
#elif !defined(NO_SHA256)
|
||||
#define PBKDF_DIGEST_SIZE SHA256_BLOCK_SIZE
|
||||
#else
|
||||
#define PBKDF_DIGEST_SIZE SHA_DIGEST_SIZE
|
||||
#endif
|
||||
|
||||
int PKCS12_PBKDF(byte* output, const byte* passwd, int passLen,const byte* salt,
|
||||
int saltLen, int iterations, int kLen, int hashType, int id)
|
||||
{
|
||||
/* all in bytes instead of bits */
|
||||
word32 u, v, dLen, pLen, iLen, sLen, totalLen;
|
||||
int dynamic = 0;
|
||||
int ret = 0;
|
||||
int i;
|
||||
byte *D, *S, *P, *I;
|
||||
#ifdef CYASSL_SMALL_STACK
|
||||
byte staticBuffer[1]; /* force dynamic usage */
|
||||
#else
|
||||
byte staticBuffer[1024];
|
||||
#endif
|
||||
byte* buffer = staticBuffer;
|
||||
|
||||
#ifdef CYASSL_SMALL_STACK
|
||||
byte* Ai;
|
||||
byte* B;
|
||||
#else
|
||||
byte Ai[PBKDF_DIGEST_SIZE];
|
||||
byte B[PBKDF_DIGEST_SIZE];
|
||||
#endif
|
||||
|
||||
if (!iterations)
|
||||
iterations = 1;
|
||||
|
||||
if (hashType == MD5) {
|
||||
v = MD5_BLOCK_SIZE;
|
||||
u = MD5_DIGEST_SIZE;
|
||||
}
|
||||
else if (hashType == SHA) {
|
||||
v = SHA_BLOCK_SIZE;
|
||||
u = SHA_DIGEST_SIZE;
|
||||
}
|
||||
#ifndef NO_SHA256
|
||||
else if (hashType == SHA256) {
|
||||
v = SHA256_BLOCK_SIZE;
|
||||
u = SHA256_DIGEST_SIZE;
|
||||
}
|
||||
#endif
|
||||
#ifdef CYASSL_SHA512
|
||||
else if (hashType == SHA512) {
|
||||
v = SHA512_BLOCK_SIZE;
|
||||
u = SHA512_DIGEST_SIZE;
|
||||
}
|
||||
#endif
|
||||
else
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
#ifdef CYASSL_SMALL_STACK
|
||||
Ai = (byte*)XMALLOC(PBKDF_DIGEST_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (Ai == NULL)
|
||||
return MEMORY_E;
|
||||
|
||||
B = (byte*)XMALLOC(PBKDF_DIGEST_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (B == NULL) {
|
||||
XFREE(Ai, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
return MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
dLen = v;
|
||||
sLen = v * ((saltLen + v - 1) / v);
|
||||
if (passLen)
|
||||
pLen = v * ((passLen + v - 1) / v);
|
||||
else
|
||||
pLen = 0;
|
||||
iLen = sLen + pLen;
|
||||
|
||||
totalLen = dLen + sLen + pLen;
|
||||
|
||||
if (totalLen > sizeof(staticBuffer)) {
|
||||
buffer = (byte*)XMALLOC(totalLen, 0, DYNAMIC_TYPE_KEY);
|
||||
if (buffer == NULL) {
|
||||
#ifdef CYASSL_SMALL_STACK
|
||||
XFREE(Ai, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
XFREE(B, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
return MEMORY_E;
|
||||
}
|
||||
dynamic = 1;
|
||||
}
|
||||
|
||||
D = buffer;
|
||||
S = D + dLen;
|
||||
P = S + sLen;
|
||||
I = S;
|
||||
|
||||
XMEMSET(D, id, dLen);
|
||||
|
||||
for (i = 0; i < (int)sLen; i++)
|
||||
S[i] = salt[i % saltLen];
|
||||
for (i = 0; i < (int)pLen; i++)
|
||||
P[i] = passwd[i % passLen];
|
||||
|
||||
while (kLen > 0) {
|
||||
word32 currentLen;
|
||||
mp_int B1;
|
||||
|
||||
if (hashType == MD5) {
|
||||
Md5 md5;
|
||||
|
||||
InitMd5(&md5);
|
||||
Md5Update(&md5, buffer, totalLen);
|
||||
Md5Final(&md5, Ai);
|
||||
|
||||
for (i = 1; i < iterations; i++) {
|
||||
Md5Update(&md5, Ai, u);
|
||||
Md5Final(&md5, Ai);
|
||||
}
|
||||
}
|
||||
else if (hashType == SHA) {
|
||||
Sha sha;
|
||||
|
||||
ret = InitSha(&sha);
|
||||
if (ret != 0)
|
||||
break;
|
||||
ShaUpdate(&sha, buffer, totalLen);
|
||||
ShaFinal(&sha, Ai);
|
||||
|
||||
for (i = 1; i < iterations; i++) {
|
||||
ShaUpdate(&sha, Ai, u);
|
||||
ShaFinal(&sha, Ai);
|
||||
}
|
||||
}
|
||||
#ifndef NO_SHA256
|
||||
else if (hashType == SHA256) {
|
||||
Sha256 sha256;
|
||||
|
||||
ret = InitSha256(&sha256);
|
||||
if (ret != 0)
|
||||
break;
|
||||
|
||||
ret = Sha256Update(&sha256, buffer, totalLen);
|
||||
if (ret != 0)
|
||||
break;
|
||||
|
||||
ret = Sha256Final(&sha256, Ai);
|
||||
if (ret != 0)
|
||||
break;
|
||||
|
||||
for (i = 1; i < iterations; i++) {
|
||||
ret = Sha256Update(&sha256, Ai, u);
|
||||
if (ret != 0)
|
||||
break;
|
||||
|
||||
ret = Sha256Final(&sha256, Ai);
|
||||
if (ret != 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef CYASSL_SHA512
|
||||
else if (hashType == SHA512) {
|
||||
Sha512 sha512;
|
||||
|
||||
ret = InitSha512(&sha512);
|
||||
if (ret != 0)
|
||||
break;
|
||||
|
||||
ret = Sha512Update(&sha512, buffer, totalLen);
|
||||
if (ret != 0)
|
||||
break;
|
||||
|
||||
ret = Sha512Final(&sha512, Ai);
|
||||
if (ret != 0)
|
||||
break;
|
||||
|
||||
for (i = 1; i < iterations; i++) {
|
||||
ret = Sha512Update(&sha512, Ai, u);
|
||||
if (ret != 0)
|
||||
break;
|
||||
|
||||
ret = Sha512Final(&sha512, Ai);
|
||||
if (ret != 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
for (i = 0; i < (int)v; i++)
|
||||
B[i] = Ai[i % u];
|
||||
|
||||
if (mp_init(&B1) != MP_OKAY)
|
||||
ret = MP_INIT_E;
|
||||
else if (mp_read_unsigned_bin(&B1, B, v) != MP_OKAY)
|
||||
ret = MP_READ_E;
|
||||
else if (mp_add_d(&B1, (mp_digit)1, &B1) != MP_OKAY)
|
||||
ret = MP_ADD_E;
|
||||
|
||||
if (ret != 0) {
|
||||
mp_clear(&B1);
|
||||
break;
|
||||
}
|
||||
|
||||
for (i = 0; i < (int)iLen; i += v) {
|
||||
int outSz;
|
||||
mp_int i1;
|
||||
mp_int res;
|
||||
|
||||
if (mp_init_multi(&i1, &res, NULL, NULL, NULL, NULL) != MP_OKAY) {
|
||||
ret = MP_INIT_E;
|
||||
break;
|
||||
}
|
||||
if (mp_read_unsigned_bin(&i1, I + i, v) != MP_OKAY)
|
||||
ret = MP_READ_E;
|
||||
else if (mp_add(&i1, &B1, &res) != MP_OKAY)
|
||||
ret = MP_ADD_E;
|
||||
else if ( (outSz = mp_unsigned_bin_size(&res)) < 0)
|
||||
ret = MP_TO_E;
|
||||
else {
|
||||
if (outSz > (int)v) {
|
||||
/* take off MSB */
|
||||
byte tmp[129];
|
||||
ret = mp_to_unsigned_bin(&res, tmp);
|
||||
XMEMCPY(I + i, tmp + 1, v);
|
||||
}
|
||||
else if (outSz < (int)v) {
|
||||
XMEMSET(I + i, 0, v - outSz);
|
||||
ret = mp_to_unsigned_bin(&res, I + i + v - outSz);
|
||||
}
|
||||
else
|
||||
ret = mp_to_unsigned_bin(&res, I + i);
|
||||
}
|
||||
|
||||
mp_clear(&i1);
|
||||
mp_clear(&res);
|
||||
if (ret < 0) break;
|
||||
}
|
||||
|
||||
currentLen = min(kLen, (int)u);
|
||||
XMEMCPY(output, Ai, currentLen);
|
||||
output += currentLen;
|
||||
kLen -= currentLen;
|
||||
mp_clear(&B1);
|
||||
}
|
||||
|
||||
if (dynamic) XFREE(buffer, 0, DYNAMIC_TYPE_KEY);
|
||||
|
||||
#ifdef CYASSL_SMALL_STACK
|
||||
XFREE(Ai, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
XFREE(B, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#undef PBKDF_DIGEST_SIZE
|
||||
|
||||
#endif /* NO_PWDBASED */
|
||||
|
2538
ctaocrypt/src/tfm.c
2538
ctaocrypt/src/tfm.c
File diff suppressed because it is too large
Load Diff
@ -24,696 +24,13 @@
|
||||
#ifndef CTAO_CRYPT_ASN_H
|
||||
#define CTAO_CRYPT_ASN_H
|
||||
|
||||
#include <cyassl/ctaocrypt/types.h>
|
||||
#include <cyassl/ctaocrypt/rsa.h>
|
||||
#include <cyassl/ctaocrypt/dh.h>
|
||||
#include <cyassl/ctaocrypt/dsa.h>
|
||||
#include <cyassl/ctaocrypt/sha.h>
|
||||
#include <cyassl/ctaocrypt/md5.h>
|
||||
#include <cyassl/ctaocrypt/asn_public.h> /* public interface */
|
||||
#ifdef HAVE_ECC
|
||||
#include <cyassl/ctaocrypt/ecc.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
enum {
|
||||
ISSUER = 0,
|
||||
SUBJECT = 1,
|
||||
|
||||
EXTERNAL_SERIAL_SIZE = 32,
|
||||
|
||||
BEFORE = 0,
|
||||
AFTER = 1
|
||||
};
|
||||
|
||||
/* ASN Tags */
|
||||
enum ASN_Tags {
|
||||
ASN_BOOLEAN = 0x01,
|
||||
ASN_INTEGER = 0x02,
|
||||
ASN_BIT_STRING = 0x03,
|
||||
ASN_OCTET_STRING = 0x04,
|
||||
ASN_TAG_NULL = 0x05,
|
||||
ASN_OBJECT_ID = 0x06,
|
||||
ASN_ENUMERATED = 0x0a,
|
||||
ASN_UTF8STRING = 0x0c,
|
||||
ASN_SEQUENCE = 0x10,
|
||||
ASN_SET = 0x11,
|
||||
ASN_UTC_TIME = 0x17,
|
||||
ASN_OTHER_TYPE = 0x00,
|
||||
ASN_RFC822_TYPE = 0x01,
|
||||
ASN_DNS_TYPE = 0x02,
|
||||
ASN_DIR_TYPE = 0x04,
|
||||
ASN_GENERALIZED_TIME = 0x18,
|
||||
CRL_EXTENSIONS = 0xa0,
|
||||
ASN_EXTENSIONS = 0xa3,
|
||||
ASN_LONG_LENGTH = 0x80
|
||||
};
|
||||
|
||||
enum ASN_Flags{
|
||||
ASN_CONSTRUCTED = 0x20,
|
||||
ASN_CONTEXT_SPECIFIC = 0x80
|
||||
};
|
||||
|
||||
enum DN_Tags {
|
||||
ASN_COMMON_NAME = 0x03, /* CN */
|
||||
ASN_SUR_NAME = 0x04, /* SN */
|
||||
ASN_SERIAL_NUMBER = 0x05, /* serialNumber */
|
||||
ASN_COUNTRY_NAME = 0x06, /* C */
|
||||
ASN_LOCALITY_NAME = 0x07, /* L */
|
||||
ASN_STATE_NAME = 0x08, /* ST */
|
||||
ASN_ORG_NAME = 0x0a, /* O */
|
||||
ASN_ORGUNIT_NAME = 0x0b /* OU */
|
||||
};
|
||||
|
||||
enum PBES {
|
||||
PBE_MD5_DES = 0,
|
||||
PBE_SHA1_DES = 1,
|
||||
PBE_SHA1_DES3 = 2,
|
||||
PBE_SHA1_RC4_128 = 3,
|
||||
PBES2 = 13 /* algo ID */
|
||||
};
|
||||
|
||||
enum ENCRYPTION_TYPES {
|
||||
DES_TYPE = 0,
|
||||
DES3_TYPE = 1,
|
||||
RC4_TYPE = 2
|
||||
};
|
||||
|
||||
enum ECC_TYPES {
|
||||
ECC_PREFIX_0 = 160,
|
||||
ECC_PREFIX_1 = 161
|
||||
};
|
||||
|
||||
enum Misc_ASN {
|
||||
ASN_NAME_MAX = 256,
|
||||
MAX_SALT_SIZE = 64, /* MAX PKCS Salt length */
|
||||
MAX_IV_SIZE = 64, /* MAX PKCS Iv length */
|
||||
MAX_KEY_SIZE = 64, /* MAX PKCS Key length */
|
||||
PKCS5 = 5, /* PKCS oid tag */
|
||||
PKCS5v2 = 6, /* PKCS #5 v2.0 */
|
||||
PKCS12 = 12, /* PKCS #12 */
|
||||
MAX_UNICODE_SZ = 256,
|
||||
ASN_BOOL_SIZE = 2, /* including type */
|
||||
ASN_ECC_HEADER_SZ = 2, /* String type + 1 byte len */
|
||||
ASN_ECC_CONTEXT_SZ = 2, /* Content specific type + 1 byte len */
|
||||
SHA_SIZE = 20,
|
||||
RSA_INTS = 8, /* RSA ints in private key */
|
||||
MIN_DATE_SIZE = 13,
|
||||
MAX_DATE_SIZE = 32,
|
||||
ASN_GEN_TIME_SZ = 15, /* 7 numbers * 2 + Zulu tag */
|
||||
MAX_ENCODED_SIG_SZ = 512,
|
||||
MAX_SIG_SZ = 256,
|
||||
MAX_ALGO_SZ = 20,
|
||||
MAX_SEQ_SZ = 5, /* enum(seq | con) + length(4) */
|
||||
MAX_SET_SZ = 5, /* enum(set | con) + length(4) */
|
||||
MAX_OCTET_STR_SZ = 5, /* enum(set | con) + length(4) */
|
||||
MAX_EXP_SZ = 5, /* enum(contextspec|con|exp) + length(4) */
|
||||
MAX_PRSTR_SZ = 5, /* enum(prstr) + length(4) */
|
||||
MAX_VERSION_SZ = 5, /* enum + id + version(byte) + (header(2))*/
|
||||
MAX_ENCODED_DIG_SZ = 73, /* sha512 + enum(bit or octet) + legnth(4) */
|
||||
MAX_RSA_INT_SZ = 517, /* RSA raw sz 4096 for bits + tag + len(4) */
|
||||
MAX_NTRU_KEY_SZ = 610, /* NTRU 112 bit public key */
|
||||
MAX_NTRU_ENC_SZ = 628, /* NTRU 112 bit DER public encoding */
|
||||
MAX_LENGTH_SZ = 4, /* Max length size for DER encoding */
|
||||
MAX_RSA_E_SZ = 16, /* Max RSA public e size */
|
||||
MAX_CA_SZ = 32, /* Max encoded CA basic constraint length */
|
||||
MAX_SN_SZ = 35, /* Max encoded serial number (INT) length */
|
||||
#ifdef CYASSL_CERT_GEN
|
||||
#ifdef CYASSL_CERT_REQ
|
||||
/* Max encoded cert req attributes length */
|
||||
MAX_ATTRIB_SZ = MAX_SEQ_SZ * 3 + (11 + MAX_SEQ_SZ) * 2 +
|
||||
MAX_PRSTR_SZ + CTC_NAME_SIZE, /* 11 is the OID size */
|
||||
#endif
|
||||
#ifdef CYASSL_ALT_NAMES
|
||||
MAX_EXTENSIONS_SZ = 1 + MAX_LENGTH_SZ + CTC_MAX_ALT_SIZE,
|
||||
#else
|
||||
MAX_EXTENSIONS_SZ = 1 + MAX_LENGTH_SZ + MAX_CA_SZ,
|
||||
#endif
|
||||
/* Max total extensions, id + len + others */
|
||||
#endif
|
||||
MAX_OCSP_EXT_SZ = 58, /* Max OCSP Extension length */
|
||||
MAX_OCSP_NONCE_SZ = 18, /* OCSP Nonce size */
|
||||
EIGHTK_BUF = 8192, /* Tmp buffer size */
|
||||
MAX_PUBLIC_KEY_SZ = MAX_NTRU_ENC_SZ + MAX_ALGO_SZ + MAX_SEQ_SZ * 2
|
||||
/* use bigger NTRU size */
|
||||
};
|
||||
|
||||
|
||||
enum Oid_Types {
|
||||
hashType = 0,
|
||||
sigType = 1,
|
||||
keyType = 2,
|
||||
curveType = 3,
|
||||
blkType = 4
|
||||
};
|
||||
|
||||
|
||||
enum Hash_Sum {
|
||||
MD2h = 646,
|
||||
MD5h = 649,
|
||||
SHAh = 88,
|
||||
SHA256h = 414,
|
||||
SHA384h = 415,
|
||||
SHA512h = 416
|
||||
};
|
||||
|
||||
|
||||
enum Block_Sum {
|
||||
DESb = 69,
|
||||
DES3b = 652
|
||||
};
|
||||
|
||||
|
||||
enum Key_Sum {
|
||||
DSAk = 515,
|
||||
RSAk = 645,
|
||||
NTRUk = 274,
|
||||
ECDSAk = 518
|
||||
};
|
||||
|
||||
|
||||
enum Ecc_Sum {
|
||||
ECC_256R1 = 526,
|
||||
ECC_384R1 = 210,
|
||||
ECC_521R1 = 211,
|
||||
ECC_160R1 = 184,
|
||||
ECC_192R1 = 520,
|
||||
ECC_224R1 = 209,
|
||||
CURVE25519_OID = 212 //TODO value to be determined
|
||||
};
|
||||
|
||||
|
||||
enum KDF_Sum {
|
||||
PBKDF2_OID = 660
|
||||
};
|
||||
|
||||
|
||||
enum Extensions_Sum {
|
||||
BASIC_CA_OID = 133,
|
||||
ALT_NAMES_OID = 131,
|
||||
CRL_DIST_OID = 145,
|
||||
AUTH_INFO_OID = 69,
|
||||
CA_ISSUER_OID = 117,
|
||||
AUTH_KEY_OID = 149,
|
||||
SUBJ_KEY_OID = 128,
|
||||
CERT_POLICY_OID = 146,
|
||||
KEY_USAGE_OID = 129, /* 2.5.29.15 */
|
||||
INHIBIT_ANY_OID = 168, /* 2.5.29.54 */
|
||||
EXT_KEY_USAGE_OID = 151, /* 2.5.29.37 */
|
||||
NAME_CONS_OID = 144 /* 2.5.29.30 */
|
||||
};
|
||||
|
||||
enum CertificatePolicy_Sum {
|
||||
CP_ANY_OID = 146 /* id-ce 32 0 */
|
||||
};
|
||||
|
||||
enum SepHardwareName_Sum {
|
||||
HW_NAME_OID = 79 /* 1.3.6.1.5.5.7.8.4 from RFC 4108*/
|
||||
};
|
||||
|
||||
enum AuthInfo_Sum {
|
||||
AIA_OCSP_OID = 116, /* 1.3.6.1.5.5.7.48.1 */
|
||||
AIA_CA_ISSUER_OID = 117 /* 1.3.6.1.5.5.7.48.2 */
|
||||
};
|
||||
|
||||
enum ExtKeyUsage_Sum { /* From RFC 5280 */
|
||||
EKU_ANY_OID = 151, /* 2.5.29.37.0, anyExtendedKeyUsage */
|
||||
EKU_SERVER_AUTH_OID = 71, /* 1.3.6.1.5.5.7.3.1, id-kp-serverAuth */
|
||||
EKU_CLIENT_AUTH_OID = 72, /* 1.3.6.1.5.5.7.3.2, id-kp-clientAuth */
|
||||
EKU_OCSP_SIGN_OID = 79 /* 1.3.6.1.5.5.7.3.9, OCSPSigning */
|
||||
};
|
||||
|
||||
|
||||
enum VerifyType {
|
||||
NO_VERIFY = 0,
|
||||
VERIFY = 1
|
||||
};
|
||||
|
||||
|
||||
/* Key usage extension bits */
|
||||
#define KEYUSE_DIGITAL_SIG 0x0100
|
||||
#define KEYUSE_CONTENT_COMMIT 0x0080
|
||||
#define KEYUSE_KEY_ENCIPHER 0x0040
|
||||
#define KEYUSE_DATA_ENCIPHER 0x0020
|
||||
#define KEYUSE_KEY_AGREE 0x0010
|
||||
#define KEYUSE_KEY_CERT_SIGN 0x0008
|
||||
#define KEYUSE_CRL_SIGN 0x0004
|
||||
#define KEYUSE_ENCIPHER_ONLY 0x0002
|
||||
#define KEYUSE_DECIPHER_ONLY 0x0001
|
||||
|
||||
#define EXTKEYUSE_ANY 0x08
|
||||
#define EXTKEYUSE_OCSP_SIGN 0x04
|
||||
#define EXTKEYUSE_CLIENT_AUTH 0x02
|
||||
#define EXTKEYUSE_SERVER_AUTH 0x01
|
||||
|
||||
typedef struct DNS_entry DNS_entry;
|
||||
|
||||
struct DNS_entry {
|
||||
DNS_entry* next; /* next on DNS list */
|
||||
char* name; /* actual DNS name */
|
||||
};
|
||||
|
||||
|
||||
typedef struct Base_entry Base_entry;
|
||||
|
||||
struct Base_entry {
|
||||
Base_entry* next; /* next on name base list */
|
||||
char* name; /* actual name base */
|
||||
int nameSz; /* name length */
|
||||
byte type; /* Name base type (DNS or RFC822) */
|
||||
};
|
||||
|
||||
|
||||
struct DecodedName {
|
||||
char* fullName;
|
||||
int fullNameLen;
|
||||
int entryCount;
|
||||
int cnIdx;
|
||||
int cnLen;
|
||||
int snIdx;
|
||||
int snLen;
|
||||
int cIdx;
|
||||
int cLen;
|
||||
int lIdx;
|
||||
int lLen;
|
||||
int stIdx;
|
||||
int stLen;
|
||||
int oIdx;
|
||||
int oLen;
|
||||
int ouIdx;
|
||||
int ouLen;
|
||||
int emailIdx;
|
||||
int emailLen;
|
||||
int uidIdx;
|
||||
int uidLen;
|
||||
int serialIdx;
|
||||
int serialLen;
|
||||
};
|
||||
|
||||
|
||||
typedef struct DecodedCert DecodedCert;
|
||||
typedef struct DecodedName DecodedName;
|
||||
typedef struct Signer Signer;
|
||||
|
||||
|
||||
struct DecodedCert {
|
||||
byte* publicKey;
|
||||
word32 pubKeySize;
|
||||
int pubKeyStored;
|
||||
word32 certBegin; /* offset to start of cert */
|
||||
word32 sigIndex; /* offset to start of signature */
|
||||
word32 sigLength; /* length of signature */
|
||||
word32 signatureOID; /* sum of algorithm object id */
|
||||
word32 keyOID; /* sum of key algo object id */
|
||||
int version; /* cert version, 1 or 3 */
|
||||
DNS_entry* altNames; /* alt names list of dns entries */
|
||||
#ifndef IGNORE_NAME_CONSTRAINTS
|
||||
DNS_entry* altEmailNames; /* alt names list of RFC822 entries */
|
||||
Base_entry* permittedNames; /* Permitted name bases */
|
||||
Base_entry* excludedNames; /* Excluded name bases */
|
||||
#endif /* IGNORE_NAME_CONSTRAINTS */
|
||||
byte subjectHash[SHA_SIZE]; /* hash of all Names */
|
||||
byte issuerHash[SHA_SIZE]; /* hash of all Names */
|
||||
#ifdef HAVE_OCSP
|
||||
byte issuerKeyHash[SHA_SIZE]; /* hash of the public Key */
|
||||
#endif /* HAVE_OCSP */
|
||||
byte* signature; /* not owned, points into raw cert */
|
||||
char* subjectCN; /* CommonName */
|
||||
int subjectCNLen; /* CommonName Length */
|
||||
char subjectCNEnc; /* CommonName Encoding */
|
||||
int subjectCNStored; /* have we saved a copy we own */
|
||||
char issuer[ASN_NAME_MAX]; /* full name including common name */
|
||||
char subject[ASN_NAME_MAX]; /* full name including common name */
|
||||
int verify; /* Default to yes, but could be off */
|
||||
byte* source; /* byte buffer holder cert, NOT owner */
|
||||
word32 srcIdx; /* current offset into buffer */
|
||||
word32 maxIdx; /* max offset based on init size */
|
||||
void* heap; /* for user memory overrides */
|
||||
byte serial[EXTERNAL_SERIAL_SIZE]; /* raw serial number */
|
||||
int serialSz; /* raw serial bytes stored */
|
||||
byte* extensions; /* not owned, points into raw cert */
|
||||
int extensionsSz; /* length of cert extensions */
|
||||
word32 extensionsIdx; /* if want to go back and parse later */
|
||||
byte* extAuthInfo; /* Authority Information Access URI */
|
||||
int extAuthInfoSz; /* length of the URI */
|
||||
byte* extCrlInfo; /* CRL Distribution Points */
|
||||
int extCrlInfoSz; /* length of the URI */
|
||||
byte extSubjKeyId[SHA_SIZE]; /* Subject Key ID */
|
||||
byte extSubjKeyIdSet; /* Set when the SKID was read from cert */
|
||||
byte extAuthKeyId[SHA_SIZE]; /* Authority Key ID */
|
||||
byte extAuthKeyIdSet; /* Set when the AKID was read from cert */
|
||||
#ifndef IGNORE_NAME_CONSTRAINTS
|
||||
byte extNameConstraintSet;
|
||||
#endif /* IGNORE_NAME_CONSTRAINTS */
|
||||
byte isCA; /* CA basic constraint true */
|
||||
byte extKeyUsageSet;
|
||||
word16 extKeyUsage; /* Key usage bitfield */
|
||||
byte extExtKeyUsageSet; /* Extended Key Usage */
|
||||
byte extExtKeyUsage; /* Extended Key usage bitfield */
|
||||
#ifdef OPENSSL_EXTRA
|
||||
byte extBasicConstSet;
|
||||
byte extBasicConstCrit;
|
||||
byte extBasicConstPlSet;
|
||||
word32 pathLength; /* CA basic constraint path length, opt */
|
||||
byte extSubjAltNameSet;
|
||||
byte extSubjAltNameCrit;
|
||||
byte extAuthKeyIdCrit;
|
||||
#ifndef IGNORE_NAME_CONSTRAINTS
|
||||
byte extNameConstraintCrit;
|
||||
#endif /* IGNORE_NAME_CONSTRAINTS */
|
||||
byte extSubjKeyIdCrit;
|
||||
byte extKeyUsageCrit;
|
||||
byte extExtKeyUsageCrit;
|
||||
byte* extExtKeyUsageSrc;
|
||||
word32 extExtKeyUsageSz;
|
||||
word32 extExtKeyUsageCount;
|
||||
byte* extAuthKeyIdSrc;
|
||||
word32 extAuthKeyIdSz;
|
||||
byte* extSubjKeyIdSrc;
|
||||
word32 extSubjKeyIdSz;
|
||||
#endif
|
||||
#ifdef HAVE_ECC
|
||||
word32 pkCurveOID; /* Public Key's curve OID */
|
||||
#endif /* HAVE_ECC */
|
||||
byte* beforeDate;
|
||||
int beforeDateLen;
|
||||
byte* afterDate;
|
||||
int afterDateLen;
|
||||
#ifdef HAVE_PKCS7
|
||||
byte* issuerRaw; /* pointer to issuer inside source */
|
||||
int issuerRawLen;
|
||||
#endif
|
||||
#ifndef IGNORE_NAME_CONSTRAINT
|
||||
byte* subjectRaw; /* pointer to subject inside source */
|
||||
int subjectRawLen;
|
||||
#endif
|
||||
#if defined(CYASSL_CERT_GEN)
|
||||
/* easy access to subject info for other sign */
|
||||
char* subjectSN;
|
||||
int subjectSNLen;
|
||||
char subjectSNEnc;
|
||||
char* subjectC;
|
||||
int subjectCLen;
|
||||
char subjectCEnc;
|
||||
char* subjectL;
|
||||
int subjectLLen;
|
||||
char subjectLEnc;
|
||||
char* subjectST;
|
||||
int subjectSTLen;
|
||||
char subjectSTEnc;
|
||||
char* subjectO;
|
||||
int subjectOLen;
|
||||
char subjectOEnc;
|
||||
char* subjectOU;
|
||||
int subjectOULen;
|
||||
char subjectOUEnc;
|
||||
char* subjectEmail;
|
||||
int subjectEmailLen;
|
||||
#endif /* CYASSL_CERT_GEN */
|
||||
#ifdef OPENSSL_EXTRA
|
||||
DecodedName issuerName;
|
||||
DecodedName subjectName;
|
||||
#endif /* OPENSSL_EXTRA */
|
||||
#ifdef CYASSL_SEP
|
||||
int deviceTypeSz;
|
||||
byte* deviceType;
|
||||
int hwTypeSz;
|
||||
byte* hwType;
|
||||
int hwSerialNumSz;
|
||||
byte* hwSerialNum;
|
||||
#ifdef OPENSSL_EXTRA
|
||||
byte extCertPolicySet;
|
||||
byte extCertPolicyCrit;
|
||||
#endif /* OPENSSL_EXTRA */
|
||||
#endif /* CYASSL_SEP */
|
||||
};
|
||||
|
||||
|
||||
#ifdef SHA_DIGEST_SIZE
|
||||
#define SIGNER_DIGEST_SIZE SHA_DIGEST_SIZE
|
||||
#else
|
||||
#define SIGNER_DIGEST_SIZE 20
|
||||
#endif
|
||||
|
||||
/* CA Signers */
|
||||
/* if change layout change PERSIST_CERT_CACHE functions too */
|
||||
struct Signer {
|
||||
word32 pubKeySize;
|
||||
word32 keyOID; /* key type */
|
||||
word16 keyUsage;
|
||||
byte* publicKey;
|
||||
int nameLen;
|
||||
char* name; /* common name */
|
||||
#ifndef IGNORE_NAME_CONSTRAINTS
|
||||
Base_entry* permittedNames;
|
||||
Base_entry* excludedNames;
|
||||
#endif /* IGNORE_NAME_CONSTRAINTS */
|
||||
byte subjectNameHash[SIGNER_DIGEST_SIZE];
|
||||
/* sha hash of names in certificate */
|
||||
#ifndef NO_SKID
|
||||
byte subjectKeyIdHash[SIGNER_DIGEST_SIZE];
|
||||
/* sha hash of names in certificate */
|
||||
#endif
|
||||
Signer* next;
|
||||
};
|
||||
|
||||
|
||||
/* not for public consumption but may use for testing sometimes */
|
||||
#ifdef CYASSL_TEST_CERT
|
||||
#define CYASSL_TEST_API CYASSL_API
|
||||
#else
|
||||
#define CYASSL_TEST_API CYASSL_LOCAL
|
||||
#endif
|
||||
|
||||
CYASSL_TEST_API void FreeAltNames(DNS_entry*, void*);
|
||||
#ifndef IGNORE_NAME_CONSTRAINTS
|
||||
CYASSL_TEST_API void FreeNameSubtrees(Base_entry*, void*);
|
||||
#endif /* IGNORE_NAME_CONSTRAINTS */
|
||||
CYASSL_TEST_API void InitDecodedCert(DecodedCert*, byte*, word32, void*);
|
||||
CYASSL_TEST_API void FreeDecodedCert(DecodedCert*);
|
||||
CYASSL_TEST_API int ParseCert(DecodedCert*, int type, int verify, void* cm);
|
||||
|
||||
CYASSL_LOCAL int ParseCertRelative(DecodedCert*, int type, int verify,void* cm);
|
||||
CYASSL_LOCAL int DecodeToKey(DecodedCert*, int verify);
|
||||
|
||||
CYASSL_LOCAL Signer* MakeSigner(void*);
|
||||
CYASSL_LOCAL void FreeSigner(Signer*, void*);
|
||||
CYASSL_LOCAL void FreeSignerTable(Signer**, int, void*);
|
||||
|
||||
|
||||
CYASSL_LOCAL int ToTraditional(byte* buffer, word32 length);
|
||||
CYASSL_LOCAL int ToTraditionalEnc(byte* buffer, word32 length,const char*, int);
|
||||
|
||||
CYASSL_LOCAL int ValidateDate(const byte* date, byte format, int dateType);
|
||||
|
||||
/* ASN.1 helper functions */
|
||||
CYASSL_LOCAL int GetLength(const byte* input, word32* inOutIdx, int* len,
|
||||
word32 maxIdx);
|
||||
CYASSL_LOCAL int GetSequence(const byte* input, word32* inOutIdx, int* len,
|
||||
word32 maxIdx);
|
||||
CYASSL_LOCAL int GetSet(const byte* input, word32* inOutIdx, int* len,
|
||||
word32 maxIdx);
|
||||
CYASSL_LOCAL int GetMyVersion(const byte* input, word32* inOutIdx,
|
||||
int* version);
|
||||
CYASSL_LOCAL int GetInt(mp_int* mpi, const byte* input, word32* inOutIdx,
|
||||
word32 maxIdx);
|
||||
CYASSL_LOCAL int GetAlgoId(const byte* input, word32* inOutIdx, word32* oid,
|
||||
word32 maxIdx);
|
||||
CYASSL_LOCAL word32 SetLength(word32 length, byte* output);
|
||||
CYASSL_LOCAL word32 SetSequence(word32 len, byte* output);
|
||||
CYASSL_LOCAL word32 SetOctetString(word32 len, byte* output);
|
||||
CYASSL_LOCAL word32 SetImplicit(byte tag, byte number, word32 len,byte* output);
|
||||
CYASSL_LOCAL word32 SetExplicit(byte number, word32 len, byte* output);
|
||||
CYASSL_LOCAL word32 SetSet(word32 len, byte* output);
|
||||
CYASSL_LOCAL word32 SetAlgoID(int algoOID, byte* output, int type, int curveSz);
|
||||
CYASSL_LOCAL int SetMyVersion(word32 version, byte* output, int header);
|
||||
CYASSL_LOCAL int SetSerialNumber(const byte* sn, word32 snSz, byte* output);
|
||||
CYASSL_LOCAL int GetNameHash(const byte* source, word32* idx, byte* hash,
|
||||
int maxIdx);
|
||||
|
||||
#ifdef HAVE_ECC
|
||||
/* ASN sig helpers */
|
||||
CYASSL_LOCAL int StoreECC_DSA_Sig(byte* out, word32* outLen, mp_int* r,
|
||||
mp_int* s);
|
||||
CYASSL_LOCAL int DecodeECC_DSA_Sig(const byte* sig, word32 sigLen,
|
||||
mp_int* r, mp_int* s);
|
||||
#endif
|
||||
|
||||
#ifdef CYASSL_CERT_GEN
|
||||
|
||||
enum cert_enums {
|
||||
NAME_ENTRIES = 8,
|
||||
JOINT_LEN = 2,
|
||||
EMAIL_JOINT_LEN = 9,
|
||||
RSA_KEY = 10,
|
||||
NTRU_KEY = 11,
|
||||
ECC_KEY = 12
|
||||
};
|
||||
|
||||
#ifndef CYASSL_PEMCERT_TODER_DEFINED
|
||||
#include <wolfssl/wolfcrypt/asn.h>
|
||||
#ifndef WOLFSSL_PEMCERT_TODER_DEFINED
|
||||
#ifndef NO_FILESYSTEM
|
||||
/* forward from CyaSSL */
|
||||
CYASSL_API
|
||||
int CyaSSL_PemCertToDer(const char* fileName, unsigned char* derBuf, int derSz);
|
||||
#define CYASSL_PEMCERT_TODER_DEFINED
|
||||
#define CyaSSL_PemCertToDer wolfSSL_PemCertToDer
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* CYASSL_CERT_GEN */
|
||||
|
||||
|
||||
|
||||
/* for pointer use */
|
||||
typedef struct CertStatus CertStatus;
|
||||
|
||||
#ifdef HAVE_OCSP
|
||||
|
||||
enum Ocsp_Response_Status {
|
||||
OCSP_SUCCESSFUL = 0, /* Response has valid confirmations */
|
||||
OCSP_MALFORMED_REQUEST = 1, /* Illegal confirmation request */
|
||||
OCSP_INTERNAL_ERROR = 2, /* Internal error in issuer */
|
||||
OCSP_TRY_LATER = 3, /* Try again later */
|
||||
OCSP_SIG_REQUIRED = 5, /* Must sign the request (4 is skipped) */
|
||||
OCSP_UNAUTHROIZED = 6 /* Request unauthorized */
|
||||
};
|
||||
|
||||
|
||||
enum Ocsp_Cert_Status {
|
||||
CERT_GOOD = 0,
|
||||
CERT_REVOKED = 1,
|
||||
CERT_UNKNOWN = 2
|
||||
};
|
||||
|
||||
|
||||
enum Ocsp_Sums {
|
||||
OCSP_BASIC_OID = 117,
|
||||
OCSP_NONCE_OID = 118
|
||||
};
|
||||
|
||||
|
||||
typedef struct OcspRequest OcspRequest;
|
||||
typedef struct OcspResponse OcspResponse;
|
||||
|
||||
|
||||
struct CertStatus {
|
||||
CertStatus* next;
|
||||
|
||||
byte serial[EXTERNAL_SERIAL_SIZE];
|
||||
int serialSz;
|
||||
|
||||
int status;
|
||||
|
||||
byte thisDate[MAX_DATE_SIZE];
|
||||
byte nextDate[MAX_DATE_SIZE];
|
||||
byte thisDateFormat;
|
||||
byte nextDateFormat;
|
||||
};
|
||||
|
||||
|
||||
struct OcspResponse {
|
||||
int responseStatus; /* return code from Responder */
|
||||
|
||||
byte* response; /* Pointer to beginning of OCSP Response */
|
||||
word32 responseSz; /* length of the OCSP Response */
|
||||
|
||||
byte producedDate[MAX_DATE_SIZE];
|
||||
/* Date at which this response was signed */
|
||||
byte producedDateFormat; /* format of the producedDate */
|
||||
byte* issuerHash;
|
||||
byte* issuerKeyHash;
|
||||
|
||||
byte* cert;
|
||||
word32 certSz;
|
||||
|
||||
byte* sig; /* Pointer to sig in source */
|
||||
word32 sigSz; /* Length in octets for the sig */
|
||||
word32 sigOID; /* OID for hash used for sig */
|
||||
|
||||
CertStatus* status; /* certificate status to fill out */
|
||||
|
||||
byte* nonce; /* pointer to nonce inside ASN.1 response */
|
||||
int nonceSz; /* length of the nonce string */
|
||||
|
||||
byte* source; /* pointer to source buffer, not owned */
|
||||
word32 maxIdx; /* max offset based on init size */
|
||||
};
|
||||
|
||||
|
||||
struct OcspRequest {
|
||||
DecodedCert* cert;
|
||||
|
||||
byte useNonce;
|
||||
byte nonce[MAX_OCSP_NONCE_SZ];
|
||||
int nonceSz;
|
||||
|
||||
byte* issuerHash; /* pointer to issuerHash in source cert */
|
||||
byte* issuerKeyHash; /* pointer to issuerKeyHash in source cert */
|
||||
byte* serial; /* pointer to serial number in source cert */
|
||||
int serialSz; /* length of the serial number */
|
||||
|
||||
byte* dest; /* pointer to the destination ASN.1 buffer */
|
||||
word32 destSz; /* length of the destination buffer */
|
||||
};
|
||||
|
||||
|
||||
CYASSL_LOCAL void InitOcspResponse(OcspResponse*, CertStatus*, byte*, word32);
|
||||
CYASSL_LOCAL int OcspResponseDecode(OcspResponse*);
|
||||
|
||||
CYASSL_LOCAL void InitOcspRequest(OcspRequest*, DecodedCert*,
|
||||
byte, byte*, word32);
|
||||
CYASSL_LOCAL int EncodeOcspRequest(OcspRequest*);
|
||||
|
||||
CYASSL_LOCAL int CompareOcspReqResp(OcspRequest*, OcspResponse*);
|
||||
|
||||
|
||||
#endif /* HAVE_OCSP */
|
||||
|
||||
|
||||
/* for pointer use */
|
||||
typedef struct RevokedCert RevokedCert;
|
||||
|
||||
#ifdef HAVE_CRL
|
||||
|
||||
struct RevokedCert {
|
||||
byte serialNumber[EXTERNAL_SERIAL_SIZE];
|
||||
int serialSz;
|
||||
RevokedCert* next;
|
||||
};
|
||||
|
||||
typedef struct DecodedCRL DecodedCRL;
|
||||
|
||||
struct DecodedCRL {
|
||||
word32 certBegin; /* offset to start of cert */
|
||||
word32 sigIndex; /* offset to start of signature */
|
||||
word32 sigLength; /* length of signature */
|
||||
word32 signatureOID; /* sum of algorithm object id */
|
||||
byte* signature; /* pointer into raw source, not owned */
|
||||
byte issuerHash[SHA_DIGEST_SIZE]; /* issuer hash */
|
||||
byte crlHash[SHA_DIGEST_SIZE]; /* raw crl data hash */
|
||||
byte lastDate[MAX_DATE_SIZE]; /* last date updated */
|
||||
byte nextDate[MAX_DATE_SIZE]; /* next update date */
|
||||
byte lastDateFormat; /* format of last date */
|
||||
byte nextDateFormat; /* format of next date */
|
||||
RevokedCert* certs; /* revoked cert list */
|
||||
int totalCerts; /* number on list */
|
||||
};
|
||||
|
||||
CYASSL_LOCAL void InitDecodedCRL(DecodedCRL*);
|
||||
CYASSL_LOCAL int ParseCRL(DecodedCRL*, const byte* buff, word32 sz, void* cm);
|
||||
CYASSL_LOCAL void FreeDecodedCRL(DecodedCRL*);
|
||||
|
||||
|
||||
#endif /* HAVE_CRL */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* CTAO_CRYPT_ASN_H */
|
||||
|
||||
#endif /* !NO_ASN */
|
||||
|
@ -32,7 +32,12 @@
|
||||
#define InitBlake2b wc_InitBlake2b
|
||||
#define Blake2bUpdate wc_Blake2bUpdate
|
||||
#define Blake2bFinal wc_Blake2bFinal
|
||||
#endif
|
||||
#else
|
||||
/* name for when fips hmac calls blake */
|
||||
#define wc_InitBlake2b InitBlake2b
|
||||
#define wc_Blake2bUpdate Blake2bUpdate
|
||||
#define wc_Blake2bFinal Blake2bFinal
|
||||
#endif /* HAVE_FIPS */
|
||||
|
||||
#endif /* CTAOCRYPT_BLAKE2_H */
|
||||
#endif /* HAVE_BLAKE2 */
|
||||
|
@ -23,41 +23,7 @@
|
||||
#ifndef CTAO_CRYPT_CODING_H
|
||||
#define CTAO_CRYPT_CODING_H
|
||||
|
||||
#ifndef HAVE_FIPS
|
||||
#include <wolfssl/wolfcrypt/coding.h>
|
||||
#else
|
||||
#include <wolfssl/wolfcrypt/coding.h>
|
||||
|
||||
#include <cyassl/ctaocrypt/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* decode needed by CyaSSL */
|
||||
CYASSL_LOCAL int Base64_Decode(const byte* in, word32 inLen, byte* out,
|
||||
word32* outLen);
|
||||
|
||||
#if defined(OPENSSL_EXTRA) || defined(SESSION_CERTS) || defined(CYASSL_KEY_GEN) || defined(CYASSL_CERT_GEN) || defined(HAVE_WEBSERVER)
|
||||
/* encode isn't */
|
||||
CYASSL_API
|
||||
int Base64_Encode(const byte* in, word32 inLen, byte* out,
|
||||
word32* outLen);
|
||||
CYASSL_API
|
||||
int Base64_EncodeEsc(const byte* in, word32 inLen, byte* out,
|
||||
word32* outLen);
|
||||
#endif
|
||||
|
||||
#if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER) || defined(HAVE_FIPS)
|
||||
CYASSL_API
|
||||
int Base16_Decode(const byte* in, word32 inLen, byte* out, word32* outLen);
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* HAVE_FIPS */
|
||||
#endif /* CTAO_CRYPT_CODING_H */
|
||||
|
||||
|
@ -31,26 +31,6 @@
|
||||
#define Compress wc_Compress
|
||||
#define DeCompress wc_DeCompress
|
||||
|
||||
//#include <cyassl/ctaocrypt/types.h>
|
||||
//
|
||||
//
|
||||
//#ifdef __cplusplus
|
||||
// extern "C" {
|
||||
//#endif
|
||||
//
|
||||
//
|
||||
//#define COMPRESS_FIXED 1
|
||||
//
|
||||
//
|
||||
//CYASSL_API int Compress(byte*, word32, const byte*, word32, word32);
|
||||
//CYASSL_API int DeCompress(byte*, word32, const byte*, word32);
|
||||
//
|
||||
//
|
||||
//#ifdef __cplusplus
|
||||
// } /* extern "C" */
|
||||
//#endif
|
||||
//
|
||||
//
|
||||
#endif /* CTAO_CRYPT_COMPRESS_H */
|
||||
|
||||
#endif /* HAVE_LIBZ */
|
||||
|
@ -28,301 +28,7 @@
|
||||
#ifndef CTAO_CRYPT_INTEGER_H
|
||||
#define CTAO_CRYPT_INTEGER_H
|
||||
|
||||
#ifndef HAVE_FIPS
|
||||
#include <wolfssl/wolfcrypt/integer.h>
|
||||
#else
|
||||
/* may optionally use fast math instead, not yet supported on all platforms and
|
||||
may not be faster on all
|
||||
*/
|
||||
#include <cyassl/ctaocrypt/types.h> /* will set MP_xxBIT if not default */
|
||||
#ifdef USE_FAST_MATH
|
||||
#include <cyassl/ctaocrypt/tfm.h>
|
||||
#else
|
||||
#include <wolfssl/wolfcrypt/integer.h>
|
||||
|
||||
#ifndef CHAR_BIT
|
||||
#include <limits.h>
|
||||
#endif
|
||||
|
||||
#include <cyassl/ctaocrypt/mpi_class.h>
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(x,y) ((x)<(y)?(x):(y))
|
||||
#endif
|
||||
|
||||
#ifndef MAX
|
||||
#define MAX(x,y) ((x)>(y)?(x):(y))
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
/* C++ compilers don't like assigning void * to mp_digit * */
|
||||
#define OPT_CAST(x) (x *)
|
||||
|
||||
#else
|
||||
|
||||
/* C on the other hand doesn't care */
|
||||
#define OPT_CAST(x)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* detect 64-bit mode if possible */
|
||||
#if defined(__x86_64__)
|
||||
#if !(defined(MP_64BIT) && defined(MP_16BIT) && defined(MP_8BIT))
|
||||
#define MP_64BIT
|
||||
#endif
|
||||
#endif
|
||||
/* if intel compiler doesn't provide 128 bit type don't turn on 64bit */
|
||||
#if defined(MP_64BIT) && defined(__INTEL_COMPILER) && !defined(HAVE___UINT128_T)
|
||||
#undef MP_64BIT
|
||||
#endif
|
||||
|
||||
/* some default configurations.
|
||||
*
|
||||
* A "mp_digit" must be able to hold DIGIT_BIT + 1 bits
|
||||
* A "mp_word" must be able to hold 2*DIGIT_BIT + 1 bits
|
||||
*
|
||||
* At the very least a mp_digit must be able to hold 7 bits
|
||||
* [any size beyond that is ok provided it doesn't overflow the data type]
|
||||
*/
|
||||
#ifdef MP_8BIT
|
||||
typedef unsigned char mp_digit;
|
||||
typedef unsigned short mp_word;
|
||||
#elif defined(MP_16BIT) || defined(NO_64BIT)
|
||||
typedef unsigned short mp_digit;
|
||||
typedef unsigned int mp_word;
|
||||
#elif defined(MP_64BIT)
|
||||
/* for GCC only on supported platforms */
|
||||
typedef unsigned long long mp_digit; /* 64 bit type, 128 uses mode(TI) */
|
||||
typedef unsigned long mp_word __attribute__ ((mode(TI)));
|
||||
|
||||
#define DIGIT_BIT 60
|
||||
#else
|
||||
/* this is the default case, 28-bit digits */
|
||||
|
||||
#if defined(_MSC_VER) || defined(__BORLANDC__)
|
||||
typedef unsigned __int64 ulong64;
|
||||
#else
|
||||
typedef unsigned long long ulong64;
|
||||
#endif
|
||||
|
||||
typedef unsigned int mp_digit; /* long could be 64 now, changed TAO */
|
||||
typedef ulong64 mp_word;
|
||||
|
||||
#ifdef MP_31BIT
|
||||
/* this is an extension that uses 31-bit digits */
|
||||
#define DIGIT_BIT 31
|
||||
#else
|
||||
/* default case is 28-bit digits, defines MP_28BIT as a handy test macro */
|
||||
#define DIGIT_BIT 28
|
||||
#define MP_28BIT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/* otherwise the bits per digit is calculated automatically from the size of
|
||||
a mp_digit */
|
||||
#ifndef DIGIT_BIT
|
||||
#define DIGIT_BIT ((int)((CHAR_BIT * sizeof(mp_digit) - 1)))
|
||||
/* bits per digit */
|
||||
#endif
|
||||
|
||||
#define MP_DIGIT_BIT DIGIT_BIT
|
||||
#define MP_MASK ((((mp_digit)1)<<((mp_digit)DIGIT_BIT))-((mp_digit)1))
|
||||
#define MP_DIGIT_MAX MP_MASK
|
||||
|
||||
/* equalities */
|
||||
#define MP_LT -1 /* less than */
|
||||
#define MP_EQ 0 /* equal to */
|
||||
#define MP_GT 1 /* greater than */
|
||||
|
||||
#define MP_ZPOS 0 /* positive integer */
|
||||
#define MP_NEG 1 /* negative */
|
||||
|
||||
#define MP_OKAY 0 /* ok result */
|
||||
#define MP_MEM -2 /* out of mem */
|
||||
#define MP_VAL -3 /* invalid input */
|
||||
#define MP_RANGE MP_VAL
|
||||
|
||||
#define MP_YES 1 /* yes response */
|
||||
#define MP_NO 0 /* no response */
|
||||
|
||||
/* Primality generation flags */
|
||||
#define LTM_PRIME_BBS 0x0001 /* BBS style prime */
|
||||
#define LTM_PRIME_SAFE 0x0002 /* Safe prime (p-1)/2 == prime */
|
||||
#define LTM_PRIME_2MSB_ON 0x0008 /* force 2nd MSB to 1 */
|
||||
|
||||
typedef int mp_err;
|
||||
|
||||
/* define this to use lower memory usage routines (exptmods mostly) */
|
||||
#define MP_LOW_MEM
|
||||
|
||||
/* default precision */
|
||||
#ifndef MP_PREC
|
||||
#ifndef MP_LOW_MEM
|
||||
#define MP_PREC 32 /* default digits of precision */
|
||||
#else
|
||||
#define MP_PREC 1 /* default digits of precision */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* size of comba arrays, should be at least 2 * 2**(BITS_PER_WORD -
|
||||
BITS_PER_DIGIT*2) */
|
||||
#define MP_WARRAY (1 << (sizeof(mp_word) * CHAR_BIT - 2 * DIGIT_BIT + 1))
|
||||
|
||||
/* the infamous mp_int structure */
|
||||
typedef struct {
|
||||
int used, alloc, sign;
|
||||
mp_digit *dp;
|
||||
} mp_int;
|
||||
|
||||
/* callback for mp_prime_random, should fill dst with random bytes and return
|
||||
how many read [upto len] */
|
||||
typedef int ltm_prime_callback(unsigned char *dst, int len, void *dat);
|
||||
|
||||
|
||||
#define USED(m) ((m)->used)
|
||||
#define DIGIT(m,k) ((m)->dp[(k)])
|
||||
#define SIGN(m) ((m)->sign)
|
||||
|
||||
|
||||
/* ---> Basic Manipulations <--- */
|
||||
#define mp_iszero(a) (((a)->used == 0) ? MP_YES : MP_NO)
|
||||
#define mp_iseven(a) \
|
||||
(((a)->used > 0 && (((a)->dp[0] & 1) == 0)) ? MP_YES : MP_NO)
|
||||
#define mp_isodd(a) \
|
||||
(((a)->used > 0 && (((a)->dp[0] & 1) == 1)) ? MP_YES : MP_NO)
|
||||
|
||||
|
||||
/* number of primes */
|
||||
#ifdef MP_8BIT
|
||||
#define PRIME_SIZE 31
|
||||
#else
|
||||
#define PRIME_SIZE 256
|
||||
#endif
|
||||
|
||||
#define mp_prime_random(a, t, size, bbs, cb, dat) \
|
||||
mp_prime_random_ex(a, t, ((size) * 8) + 1, (bbs==1)?LTM_PRIME_BBS:0, cb, dat)
|
||||
|
||||
#define mp_read_raw(mp, str, len) mp_read_signed_bin((mp), (str), (len))
|
||||
#define mp_raw_size(mp) mp_signed_bin_size(mp)
|
||||
#define mp_toraw(mp, str) mp_to_signed_bin((mp), (str))
|
||||
#define mp_read_mag(mp, str, len) mp_read_unsigned_bin((mp), (str), (len))
|
||||
#define mp_mag_size(mp) mp_unsigned_bin_size(mp)
|
||||
#define mp_tomag(mp, str) mp_to_unsigned_bin((mp), (str))
|
||||
|
||||
#define mp_tobinary(M, S) mp_toradix((M), (S), 2)
|
||||
#define mp_tooctal(M, S) mp_toradix((M), (S), 8)
|
||||
#define mp_todecimal(M, S) mp_toradix((M), (S), 10)
|
||||
#define mp_tohex(M, S) mp_toradix((M), (S), 16)
|
||||
|
||||
#define s_mp_mul(a, b, c) s_mp_mul_digs(a, b, c, (a)->used + (b)->used + 1)
|
||||
|
||||
extern const char *mp_s_rmap;
|
||||
|
||||
/* 6 functions needed by Rsa */
|
||||
int mp_init (mp_int * a);
|
||||
void mp_clear (mp_int * a);
|
||||
int mp_unsigned_bin_size(mp_int * a);
|
||||
int mp_read_unsigned_bin (mp_int * a, const unsigned char *b, int c);
|
||||
int mp_to_unsigned_bin (mp_int * a, unsigned char *b);
|
||||
int mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y);
|
||||
/* end functions needed by Rsa */
|
||||
|
||||
/* functions added to support above needed, removed TOOM and KARATSUBA */
|
||||
int mp_count_bits (mp_int * a);
|
||||
int mp_leading_bit (mp_int * a);
|
||||
int mp_init_copy (mp_int * a, mp_int * b);
|
||||
int mp_copy (mp_int * a, mp_int * b);
|
||||
int mp_grow (mp_int * a, int size);
|
||||
int mp_div_2d (mp_int * a, int b, mp_int * c, mp_int * d);
|
||||
void mp_zero (mp_int * a);
|
||||
void mp_clamp (mp_int * a);
|
||||
void mp_exch (mp_int * a, mp_int * b);
|
||||
void mp_rshd (mp_int * a, int b);
|
||||
void mp_rshb (mp_int * a, int b);
|
||||
int mp_mod_2d (mp_int * a, int b, mp_int * c);
|
||||
int mp_mul_2d (mp_int * a, int b, mp_int * c);
|
||||
int mp_lshd (mp_int * a, int b);
|
||||
int mp_abs (mp_int * a, mp_int * b);
|
||||
int mp_invmod (mp_int * a, mp_int * b, mp_int * c);
|
||||
int fast_mp_invmod (mp_int * a, mp_int * b, mp_int * c);
|
||||
int mp_invmod_slow (mp_int * a, mp_int * b, mp_int * c);
|
||||
int mp_cmp_mag (mp_int * a, mp_int * b);
|
||||
int mp_cmp (mp_int * a, mp_int * b);
|
||||
int mp_cmp_d(mp_int * a, mp_digit b);
|
||||
void mp_set (mp_int * a, mp_digit b);
|
||||
int mp_mod (mp_int * a, mp_int * b, mp_int * c);
|
||||
int mp_div(mp_int * a, mp_int * b, mp_int * c, mp_int * d);
|
||||
int mp_div_2(mp_int * a, mp_int * b);
|
||||
int mp_add (mp_int * a, mp_int * b, mp_int * c);
|
||||
int s_mp_add (mp_int * a, mp_int * b, mp_int * c);
|
||||
int s_mp_sub (mp_int * a, mp_int * b, mp_int * c);
|
||||
int mp_sub (mp_int * a, mp_int * b, mp_int * c);
|
||||
int mp_reduce_is_2k_l(mp_int *a);
|
||||
int mp_reduce_is_2k(mp_int *a);
|
||||
int mp_dr_is_modulus(mp_int *a);
|
||||
int mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int);
|
||||
int mp_montgomery_setup (mp_int * n, mp_digit * rho);
|
||||
int fast_mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho);
|
||||
int mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho);
|
||||
void mp_dr_setup(mp_int *a, mp_digit *d);
|
||||
int mp_dr_reduce (mp_int * x, mp_int * n, mp_digit k);
|
||||
int mp_reduce_2k(mp_int *a, mp_int *n, mp_digit d);
|
||||
int fast_s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs);
|
||||
int s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs);
|
||||
int mp_reduce_2k_setup_l(mp_int *a, mp_int *d);
|
||||
int mp_reduce_2k_l(mp_int *a, mp_int *n, mp_int *d);
|
||||
int mp_reduce (mp_int * x, mp_int * m, mp_int * mu);
|
||||
int mp_reduce_setup (mp_int * a, mp_int * b);
|
||||
int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode);
|
||||
int mp_montgomery_calc_normalization (mp_int * a, mp_int * b);
|
||||
int s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs);
|
||||
int s_mp_sqr (mp_int * a, mp_int * b);
|
||||
int fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs);
|
||||
int fast_s_mp_sqr (mp_int * a, mp_int * b);
|
||||
int mp_init_size (mp_int * a, int size);
|
||||
int mp_div_3 (mp_int * a, mp_int *c, mp_digit * d);
|
||||
int mp_mul_2(mp_int * a, mp_int * b);
|
||||
int mp_mul (mp_int * a, mp_int * b, mp_int * c);
|
||||
int mp_sqr (mp_int * a, mp_int * b);
|
||||
int mp_mulmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d);
|
||||
int mp_mul_d (mp_int * a, mp_digit b, mp_int * c);
|
||||
int mp_2expt (mp_int * a, int b);
|
||||
int mp_reduce_2k_setup(mp_int *a, mp_digit *d);
|
||||
int mp_add_d (mp_int* a, mp_digit b, mp_int* c);
|
||||
int mp_set_int (mp_int * a, unsigned long b);
|
||||
int mp_sub_d (mp_int * a, mp_digit b, mp_int * c);
|
||||
/* end support added functions */
|
||||
|
||||
/* added */
|
||||
int mp_init_multi(mp_int* a, mp_int* b, mp_int* c, mp_int* d, mp_int* e,
|
||||
mp_int* f);
|
||||
|
||||
#if defined(HAVE_ECC) || defined(CYASSL_KEY_GEN)
|
||||
int mp_sqrmod(mp_int* a, mp_int* b, mp_int* c);
|
||||
#endif
|
||||
#ifdef HAVE_ECC
|
||||
int mp_read_radix(mp_int* a, const char* str, int radix);
|
||||
#endif
|
||||
|
||||
#ifdef CYASSL_KEY_GEN
|
||||
int mp_prime_is_prime (mp_int * a, int t, int *result);
|
||||
int mp_gcd (mp_int * a, mp_int * b, mp_int * c);
|
||||
int mp_lcm (mp_int * a, mp_int * b, mp_int * c);
|
||||
#endif
|
||||
|
||||
int mp_cnt_lsb(mp_int *a);
|
||||
int mp_mod_d(mp_int* a, mp_digit b, mp_digit* c);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* USE_FAST_MATH */
|
||||
|
||||
#endif /* HAVE_FIPS */
|
||||
#endif /* CTAO_CRYPT_INTEGER_H */
|
||||
|
||||
|
@ -26,57 +26,15 @@
|
||||
#define CYASSL_LOGGING_H
|
||||
|
||||
/* for fips compatibility @wc_fips */
|
||||
#ifndef HAVE_FIPS
|
||||
#include <wolfssl/wolfcrypt/logging.h>
|
||||
#define CYASSL_LEAVE WOLFSSL_LEAVE
|
||||
#define CYASSL_ERROR WOLFSSL_ERROR
|
||||
#define CYASSL_ENTER WOLFSSL_ENTER
|
||||
#define CYASSL_MSG WOLFSSL_MSG
|
||||
/* check old macros possibly declared */
|
||||
#if defined(CYASSL_DEBUG) && !defined(DEBUG_WOLFSSL)
|
||||
#define DEBUG_WOLFSSL
|
||||
#endif
|
||||
#else
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
enum CYA_Log_Levels {
|
||||
ERROR_LOG = 0,
|
||||
INFO_LOG,
|
||||
ENTER_LOG,
|
||||
LEAVE_LOG,
|
||||
OTHER_LOG
|
||||
};
|
||||
|
||||
typedef void (*CyaSSL_Logging_cb)(const int logLevel,
|
||||
const char *const logMessage);
|
||||
|
||||
CYASSL_API int CyaSSL_SetLoggingCb(CyaSSL_Logging_cb log_function);
|
||||
|
||||
|
||||
#ifdef DEBUG_CYASSL
|
||||
|
||||
void CYASSL_ENTER(const char* msg);
|
||||
void CYASSL_LEAVE(const char* msg, int ret);
|
||||
|
||||
void CYASSL_ERROR(int);
|
||||
void CYASSL_MSG(const char* msg);
|
||||
|
||||
#else /* DEBUG_CYASSL */
|
||||
|
||||
#define CYASSL_ENTER(m)
|
||||
#define CYASSL_LEAVE(m, r)
|
||||
|
||||
#define CYASSL_ERROR(e)
|
||||
#define CYASSL_MSG(m)
|
||||
|
||||
#endif /* DEBUG_CYASSL */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* HAVE_FIPS*/
|
||||
#endif /* CYASSL_MEMORY_H */
|
||||
#include <wolfssl/wolfcrypt/logging.h>
|
||||
#define CYASSL_LEAVE WOLFSSL_LEAVE
|
||||
#define CYASSL_ERROR WOLFSSL_ERROR
|
||||
#define CYASSL_ENTER WOLFSSL_ENTER
|
||||
#define CYASSL_MSG WOLFSSL_MSG
|
||||
/* check old macros possibly declared */
|
||||
#if defined(CYASSL_DEBUG) && !defined(DEBUG_WOLFSSL)
|
||||
#define DEBUG_WOLFSSL
|
||||
#endif
|
||||
|
||||
#endif /* CYASSL_LOGGING_H */
|
||||
|
||||
|
@ -25,7 +25,6 @@
|
||||
#define CTAO_CRYPT_MD5_H
|
||||
|
||||
#include <wolfssl/wolfcrypt/md5.h>
|
||||
#include <cyassl/ctaocrypt/types.h>
|
||||
|
||||
#ifndef HAVE_FIPS
|
||||
#define InitMd5 wc_InitMd5
|
||||
|
@ -25,38 +25,17 @@
|
||||
#ifndef CYASSL_MEMORY_H
|
||||
#define CYASSL_MEMORY_H
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
/* for fips compatibility @wc_fips */
|
||||
#ifndef HAVE_FIPS
|
||||
#include <wolfssl/wolfcrypt/memory.h>
|
||||
#else
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
typedef void *(*CyaSSL_Malloc_cb)(size_t size);
|
||||
typedef void (*CyaSSL_Free_cb)(void *ptr);
|
||||
typedef void *(*CyaSSL_Realloc_cb)(void *ptr, size_t size);
|
||||
|
||||
|
||||
/* Public set function */
|
||||
CYASSL_API int CyaSSL_SetAllocators(CyaSSL_Malloc_cb malloc_function,
|
||||
CyaSSL_Free_cb free_function,
|
||||
CyaSSL_Realloc_cb realloc_function);
|
||||
#define CyaSSL_Malloc_cb wolfSSL_Malloc_cb
|
||||
#define CyaSSL_Free_cb wolfSSL_Free_cb
|
||||
#define CyaSSL_Realloc_cb wolfSSL_Realloc_cb
|
||||
#define CyaSSL_SetAllocators wolfSSL_SetAllocators
|
||||
|
||||
/* Public in case user app wants to use XMALLOC/XFREE */
|
||||
CYASSL_API void* CyaSSL_Malloc(size_t size);
|
||||
CYASSL_API void CyaSSL_Free(void *ptr);
|
||||
CYASSL_API void* CyaSSL_Realloc(void *ptr, size_t size);
|
||||
#define CyaSSL_Malloc wolfSSL_Malloc
|
||||
#define CyaSSL_Free wolfSSL_Free
|
||||
#define CyaSSL_Realloc wolfSSL_Realloc
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* HAVE_FIPS */
|
||||
#endif /* CYASSL_MEMORY_H */
|
||||
|
||||
|
@ -23,54 +23,7 @@
|
||||
#ifndef CTAO_CRYPT_MISC_H
|
||||
#define CTAO_CRYPT_MISC_H
|
||||
|
||||
#include <cyassl/ctaocrypt/types.h>
|
||||
#include <wolfssl/wolfcrypt/misc.h>
|
||||
|
||||
#ifndef HAVE_FIPS
|
||||
#include <wolfssl/wolfcrypt/misc.h>
|
||||
#else
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef NO_INLINE
|
||||
CYASSL_LOCAL
|
||||
word32 rotlFixed(word32, word32);
|
||||
CYASSL_LOCAL
|
||||
word32 rotrFixed(word32, word32);
|
||||
|
||||
CYASSL_LOCAL
|
||||
word32 ByteReverseWord32(word32);
|
||||
CYASSL_LOCAL
|
||||
void ByteReverseWords(word32*, const word32*, word32);
|
||||
|
||||
CYASSL_LOCAL
|
||||
void XorWords(word*, const word*, word32);
|
||||
CYASSL_LOCAL
|
||||
void xorbuf(void*, const void*, word32);
|
||||
|
||||
#ifdef WORD64_AVAILABLE
|
||||
CYASSL_LOCAL
|
||||
word64 rotlFixed64(word64, word64);
|
||||
CYASSL_LOCAL
|
||||
word64 rotrFixed64(word64, word64);
|
||||
|
||||
CYASSL_LOCAL
|
||||
word64 ByteReverseWord64(word64);
|
||||
CYASSL_LOCAL
|
||||
void ByteReverseWords64(word64*, const word64*, word32);
|
||||
#endif /* WORD64_AVAILABLE */
|
||||
|
||||
#endif /* NO_INLINE */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* HAVE_FIPS */
|
||||
#endif /* CTAO_CRYPT_MISC_H */
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wolfSSL is distributed in the hope that it will be useful,
|
||||
* wolfSSL is distributed in the hope that it will be useful,
|
||||
* * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
@ -25,29 +25,11 @@
|
||||
#ifndef CTAO_CRYPT_PWDBASED_H
|
||||
#define CTAO_CRYPT_PWDBASED_H
|
||||
|
||||
#include <cyassl/ctaocrypt/types.h>
|
||||
#include <cyassl/ctaocrypt/md5.h> /* for hash type */
|
||||
#include <cyassl/ctaocrypt/sha.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
CYASSL_API int PBKDF1(byte* output, const byte* passwd, int pLen,
|
||||
const byte* salt, int sLen, int iterations, int kLen,
|
||||
int hashType);
|
||||
CYASSL_API int PBKDF2(byte* output, const byte* passwd, int pLen,
|
||||
const byte* salt, int sLen, int iterations, int kLen,
|
||||
int hashType);
|
||||
CYASSL_API int PKCS12_PBKDF(byte* output, const byte* passwd, int pLen,
|
||||
const byte* salt, int sLen, int iterations,
|
||||
int kLen, int hashType, int purpose);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
/* for pwdbased reverse compatibility */
|
||||
#include <wolfssl/wolfcrypt/pwdbased.h>
|
||||
#define PBKDF1 wc_PBKDF1
|
||||
#define PBKDF2 wc_PBKDF2
|
||||
#define PKCS12_PBKDF wc_PKCS12_PBKDF
|
||||
|
||||
#endif /* CTAO_CRYPT_PWDBASED_H */
|
||||
#endif /* NO_PWDBASED */
|
||||
|
@ -28,12 +28,6 @@
|
||||
|
||||
/* for reverse compatibility after name change */
|
||||
#include <cyassl/ctaocrypt/settings_comp.h>
|
||||
#if defined(WOLFSSL_LEANPSK) && !defined(CYASSL_LEANPSK)
|
||||
#define CYASSL_LEANPSK
|
||||
#endif
|
||||
#if defined(NO_WOLFSSL_MEMORY) && !defined(NO_CYASSL_MEMORY)
|
||||
#define NO_CYASSL_MEMORY
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -23,12 +23,23 @@
|
||||
#define CTAO_CRYPT_SETTINGS_C_H
|
||||
|
||||
/* Macro redefinitions for compatibility */
|
||||
#ifdef WOLFSSL_SHA512
|
||||
#define CYASSL_SHA512 WOLFSSL_SHA512
|
||||
#if defined(WOLFSSL_SHA512) && !defined(CYASSL_SHA512)
|
||||
#define CYASSL_SHA512
|
||||
#endif
|
||||
#ifdef WOLFSSL_SHA384
|
||||
#define CYASSL_SHA384 WOLFSSL_SHA384
|
||||
#if defined(WOLFSSL_SHA384) && !defined(CYASSL_SHA384)
|
||||
#define CYASSL_SHA384
|
||||
#endif
|
||||
#if defined(WOLFSSL_LEANPSK) && !defined(CYASSL_LEANPSK)
|
||||
#define CYASSL_LEANPSK
|
||||
#endif
|
||||
#if defined(NO_WOLFSSL_MEMORY) && !defined(NO_CYASSL_MEMORY)
|
||||
#define NO_CYASSL_MEMORY
|
||||
#endif
|
||||
|
||||
/* asn.c compatibility */
|
||||
#define RsaPrivateKeyDecode wc_RsaPrivateKeyDecode
|
||||
#define RsaPublicKeyDecode wc_RsaPublicKeyDecode
|
||||
#define RsaPublicKeyDecodeRaw wc_RsaPublicKeyDecodeRaw
|
||||
|
||||
/* These are compatibility from fips protected headers
|
||||
* When using non-fips mode and including old headers this allows for
|
||||
@ -94,10 +105,7 @@
|
||||
#define RsaSSL_VerifyInline wc_RsaSSL_VerifyInline
|
||||
#define RsaSSL_Verify wc_RsaSSL_Verify
|
||||
#define RsaEncryptSize wc_RsaEncryptSize
|
||||
#define RsaPrivateKeyDecode wc_RsaPrivateKeyDecode
|
||||
#define RsaPublicKeyDecode wc_RsaPublicKeyDecode
|
||||
#define RsaPublicKeyDecodeRaw wc_RsaPublicKeyDecodeRaw
|
||||
#define RsaFlattenPublicKey wc_RsaFlattenPublicKey
|
||||
#define RsaFlattenPublicKey wc_RsaFlattenPublicKey
|
||||
|
||||
#ifdef WOLFSSL_KEY_GEN
|
||||
#define MakeRsaKey wc_MakeRsaKey
|
||||
|
@ -35,673 +35,7 @@
|
||||
#ifndef CTAO_CRYPT_TFM_H
|
||||
#define CTAO_CRYPT_TFM_H
|
||||
|
||||
#include <cyassl/ctaocrypt/types.h>
|
||||
#ifndef CHAR_BIT
|
||||
#include <limits.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(x,y) ((x)<(y)?(x):(y))
|
||||
#endif
|
||||
|
||||
#ifndef MAX
|
||||
#define MAX(x,y) ((x)>(y)?(x):(y))
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef NO_64BIT
|
||||
/* autodetect x86-64 and make sure we are using 64-bit digits with x86-64 asm */
|
||||
#if defined(__x86_64__)
|
||||
#if defined(TFM_X86) || defined(TFM_SSE2) || defined(TFM_ARM)
|
||||
#error x86-64 detected, x86-32/SSE2/ARM optimizations are not valid!
|
||||
#endif
|
||||
#if !defined(TFM_X86_64) && !defined(TFM_NO_ASM)
|
||||
#define TFM_X86_64
|
||||
#endif
|
||||
#endif
|
||||
#if defined(TFM_X86_64)
|
||||
#if !defined(FP_64BIT)
|
||||
#define FP_64BIT
|
||||
#endif
|
||||
#endif
|
||||
/* use 64-bit digit even if not using asm on x86_64 */
|
||||
#if defined(__x86_64__) && !defined(FP_64BIT)
|
||||
#define FP_64BIT
|
||||
#endif
|
||||
/* if intel compiler doesn't provide 128 bit type don't turn on 64bit */
|
||||
#if defined(FP_64BIT) && defined(__INTEL_COMPILER) && !defined(HAVE___UINT128_T)
|
||||
#undef FP_64BIT
|
||||
#undef TFM_X86_64
|
||||
#endif
|
||||
#endif /* NO_64BIT */
|
||||
|
||||
/* try to detect x86-32 */
|
||||
#if defined(__i386__) && !defined(TFM_SSE2)
|
||||
#if defined(TFM_X86_64) || defined(TFM_ARM)
|
||||
#error x86-32 detected, x86-64/ARM optimizations are not valid!
|
||||
#endif
|
||||
#if !defined(TFM_X86) && !defined(TFM_NO_ASM)
|
||||
#define TFM_X86
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* make sure we're 32-bit for x86-32/sse/arm/ppc32 */
|
||||
#if (defined(TFM_X86) || defined(TFM_SSE2) || defined(TFM_ARM) || defined(TFM_PPC32)) && defined(FP_64BIT)
|
||||
#warning x86-32, SSE2 and ARM, PPC32 optimizations require 32-bit digits (undefining)
|
||||
#undef FP_64BIT
|
||||
#endif
|
||||
|
||||
/* multi asms? */
|
||||
#ifdef TFM_X86
|
||||
#define TFM_ASM
|
||||
#endif
|
||||
#ifdef TFM_X86_64
|
||||
#ifdef TFM_ASM
|
||||
#error TFM_ASM already defined!
|
||||
#endif
|
||||
#define TFM_ASM
|
||||
#endif
|
||||
#ifdef TFM_SSE2
|
||||
#ifdef TFM_ASM
|
||||
#error TFM_ASM already defined!
|
||||
#endif
|
||||
#define TFM_ASM
|
||||
#endif
|
||||
#ifdef TFM_ARM
|
||||
#ifdef TFM_ASM
|
||||
#error TFM_ASM already defined!
|
||||
#endif
|
||||
#define TFM_ASM
|
||||
#endif
|
||||
#ifdef TFM_PPC32
|
||||
#ifdef TFM_ASM
|
||||
#error TFM_ASM already defined!
|
||||
#endif
|
||||
#define TFM_ASM
|
||||
#endif
|
||||
#ifdef TFM_PPC64
|
||||
#ifdef TFM_ASM
|
||||
#error TFM_ASM already defined!
|
||||
#endif
|
||||
#define TFM_ASM
|
||||
#endif
|
||||
#ifdef TFM_AVR32
|
||||
#ifdef TFM_ASM
|
||||
#error TFM_ASM already defined!
|
||||
#endif
|
||||
#define TFM_ASM
|
||||
#endif
|
||||
|
||||
/* we want no asm? */
|
||||
#ifdef TFM_NO_ASM
|
||||
#undef TFM_X86
|
||||
#undef TFM_X86_64
|
||||
#undef TFM_SSE2
|
||||
#undef TFM_ARM
|
||||
#undef TFM_PPC32
|
||||
#undef TFM_PPC64
|
||||
#undef TFM_AVR32
|
||||
#undef TFM_ASM
|
||||
#endif
|
||||
|
||||
/* ECC helpers */
|
||||
#ifdef TFM_ECC192
|
||||
#ifdef FP_64BIT
|
||||
#define TFM_MUL3
|
||||
#define TFM_SQR3
|
||||
#else
|
||||
#define TFM_MUL6
|
||||
#define TFM_SQR6
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef TFM_ECC224
|
||||
#ifdef FP_64BIT
|
||||
#define TFM_MUL4
|
||||
#define TFM_SQR4
|
||||
#else
|
||||
#define TFM_MUL7
|
||||
#define TFM_SQR7
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef TFM_ECC256
|
||||
#ifdef FP_64BIT
|
||||
#define TFM_MUL4
|
||||
#define TFM_SQR4
|
||||
#else
|
||||
#define TFM_MUL8
|
||||
#define TFM_SQR8
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef TFM_ECC384
|
||||
#ifdef FP_64BIT
|
||||
#define TFM_MUL6
|
||||
#define TFM_SQR6
|
||||
#else
|
||||
#define TFM_MUL12
|
||||
#define TFM_SQR12
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef TFM_ECC521
|
||||
#ifdef FP_64BIT
|
||||
#define TFM_MUL9
|
||||
#define TFM_SQR9
|
||||
#else
|
||||
#define TFM_MUL17
|
||||
#define TFM_SQR17
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/* some default configurations.
|
||||
*/
|
||||
#if defined(FP_64BIT)
|
||||
/* for GCC only on supported platforms */
|
||||
typedef unsigned long long fp_digit; /* 64bit, 128 uses mode(TI) below */
|
||||
typedef unsigned long fp_word __attribute__ ((mode(TI)));
|
||||
#else
|
||||
#if defined(_MSC_VER) || defined(__BORLANDC__)
|
||||
typedef unsigned __int64 ulong64;
|
||||
#else
|
||||
typedef unsigned long long ulong64;
|
||||
#endif
|
||||
|
||||
#ifndef NO_64BIT
|
||||
typedef unsigned int fp_digit;
|
||||
typedef ulong64 fp_word;
|
||||
#define FP_32BIT
|
||||
#else
|
||||
/* some procs like coldfire prefer not to place multiply into 64bit type
|
||||
even though it exists */
|
||||
typedef unsigned short fp_digit;
|
||||
typedef unsigned int fp_word;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* # of digits this is */
|
||||
#define DIGIT_BIT (int)((CHAR_BIT) * sizeof(fp_digit))
|
||||
|
||||
/* Max size of any number in bits. Basically the largest size you will be
|
||||
* multiplying should be half [or smaller] of FP_MAX_SIZE-four_digit
|
||||
*
|
||||
* It defaults to 4096-bits [allowing multiplications upto 2048x2048 bits ]
|
||||
*/
|
||||
#ifndef FP_MAX_BITS
|
||||
#define FP_MAX_BITS 4096
|
||||
#endif
|
||||
#define FP_MAX_SIZE (FP_MAX_BITS+(8*DIGIT_BIT))
|
||||
|
||||
/* will this lib work? */
|
||||
#if (CHAR_BIT & 7)
|
||||
#error CHAR_BIT must be a multiple of eight.
|
||||
#endif
|
||||
#if FP_MAX_BITS % CHAR_BIT
|
||||
#error FP_MAX_BITS must be a multiple of CHAR_BIT
|
||||
#endif
|
||||
|
||||
#define FP_MASK (fp_digit)(-1)
|
||||
#define FP_SIZE (FP_MAX_SIZE/DIGIT_BIT)
|
||||
|
||||
/* signs */
|
||||
#define FP_ZPOS 0
|
||||
#define FP_NEG 1
|
||||
|
||||
/* return codes */
|
||||
#define FP_OKAY 0
|
||||
#define FP_VAL 1
|
||||
#define FP_MEM 2
|
||||
|
||||
/* equalities */
|
||||
#define FP_LT -1 /* less than */
|
||||
#define FP_EQ 0 /* equal to */
|
||||
#define FP_GT 1 /* greater than */
|
||||
|
||||
/* replies */
|
||||
#define FP_YES 1 /* yes response */
|
||||
#define FP_NO 0 /* no response */
|
||||
|
||||
/* a FP type */
|
||||
typedef struct {
|
||||
fp_digit dp[FP_SIZE];
|
||||
int used,
|
||||
sign;
|
||||
} fp_int;
|
||||
|
||||
/* externally define this symbol to ignore the default settings, useful for changing the build from the make process */
|
||||
#ifndef TFM_ALREADY_SET
|
||||
|
||||
/* do we want the large set of small multiplications ?
|
||||
Enable these if you are going to be doing a lot of small (<= 16 digit) multiplications say in ECC
|
||||
Or if you're on a 64-bit machine doing RSA as a 1024-bit integer == 16 digits ;-)
|
||||
*/
|
||||
/* need to refactor the function */
|
||||
/*#define TFM_SMALL_SET */
|
||||
|
||||
/* do we want huge code
|
||||
Enable these if you are doing 20, 24, 28, 32, 48, 64 digit multiplications (useful for RSA)
|
||||
Less important on 64-bit machines as 32 digits == 2048 bits
|
||||
*/
|
||||
#if 0
|
||||
#define TFM_MUL3
|
||||
#define TFM_MUL4
|
||||
#define TFM_MUL6
|
||||
#define TFM_MUL7
|
||||
#define TFM_MUL8
|
||||
#define TFM_MUL9
|
||||
#define TFM_MUL12
|
||||
#define TFM_MUL17
|
||||
#endif
|
||||
#ifdef TFM_HUGE_SET
|
||||
#define TFM_MUL20
|
||||
#define TFM_MUL24
|
||||
#define TFM_MUL28
|
||||
#define TFM_MUL32
|
||||
#if (FP_MAX_BITS >= 6144) && defined(FP_64BIT)
|
||||
#define TFM_MUL48
|
||||
#endif
|
||||
#if (FP_MAX_BITS >= 8192) && defined(FP_64BIT)
|
||||
#define TFM_MUL64
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#define TFM_SQR3
|
||||
#define TFM_SQR4
|
||||
#define TFM_SQR6
|
||||
#define TFM_SQR7
|
||||
#define TFM_SQR8
|
||||
#define TFM_SQR9
|
||||
#define TFM_SQR12
|
||||
#define TFM_SQR17
|
||||
#endif
|
||||
#ifdef TFM_HUGE_SET
|
||||
#define TFM_SQR20
|
||||
#define TFM_SQR24
|
||||
#define TFM_SQR28
|
||||
#define TFM_SQR32
|
||||
#define TFM_SQR48
|
||||
#define TFM_SQR64
|
||||
#endif
|
||||
|
||||
/* do we want some overflow checks
|
||||
Not required if you make sure your numbers are within range (e.g. by default a modulus for fp_exptmod() can only be upto 2048 bits long)
|
||||
*/
|
||||
/* #define TFM_CHECK */
|
||||
|
||||
/* Is the target a P4 Prescott
|
||||
*/
|
||||
/* #define TFM_PRESCOTT */
|
||||
|
||||
/* Do we want timing resistant fp_exptmod() ?
|
||||
* This makes it slower but also timing invariant with respect to the exponent
|
||||
*/
|
||||
/* #define TFM_TIMING_RESISTANT */
|
||||
|
||||
#endif /* TFM_ALREADY_SET */
|
||||
|
||||
/* functions */
|
||||
|
||||
/* returns a TFM ident string useful for debugging... */
|
||||
/*const char *fp_ident(void);*/
|
||||
|
||||
/* initialize [or zero] an fp int */
|
||||
#define fp_init(a) (void)XMEMSET((a), 0, sizeof(fp_int))
|
||||
#define fp_zero(a) fp_init(a)
|
||||
|
||||
/* zero/even/odd ? */
|
||||
#define fp_iszero(a) (((a)->used == 0) ? FP_YES : FP_NO)
|
||||
#define fp_iseven(a) (((a)->used >= 0 && (((a)->dp[0] & 1) == 0)) ? FP_YES : FP_NO)
|
||||
#define fp_isodd(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 1)) ? FP_YES : FP_NO)
|
||||
|
||||
/* set to a small digit */
|
||||
void fp_set(fp_int *a, fp_digit b);
|
||||
|
||||
/* copy from a to b */
|
||||
#define fp_copy(a, b) (void)(((a) != (b)) ? ((void)XMEMCPY((b), (a), sizeof(fp_int))) : (void)0)
|
||||
#define fp_init_copy(a, b) fp_copy(b, a)
|
||||
|
||||
/* clamp digits */
|
||||
#define fp_clamp(a) { while ((a)->used && (a)->dp[(a)->used-1] == 0) --((a)->used); (a)->sign = (a)->used ? (a)->sign : FP_ZPOS; }
|
||||
|
||||
/* negate and absolute */
|
||||
#define fp_neg(a, b) { fp_copy(a, b); (b)->sign ^= 1; fp_clamp(b); }
|
||||
#define fp_abs(a, b) { fp_copy(a, b); (b)->sign = 0; }
|
||||
|
||||
/* right shift x digits */
|
||||
void fp_rshd(fp_int *a, int x);
|
||||
|
||||
/* right shift x bits */
|
||||
void fp_rshb(fp_int *a, int x);
|
||||
|
||||
/* left shift x digits */
|
||||
void fp_lshd(fp_int *a, int x);
|
||||
|
||||
/* signed comparison */
|
||||
int fp_cmp(fp_int *a, fp_int *b);
|
||||
|
||||
/* unsigned comparison */
|
||||
int fp_cmp_mag(fp_int *a, fp_int *b);
|
||||
|
||||
/* power of 2 operations */
|
||||
void fp_div_2d(fp_int *a, int b, fp_int *c, fp_int *d);
|
||||
void fp_mod_2d(fp_int *a, int b, fp_int *c);
|
||||
void fp_mul_2d(fp_int *a, int b, fp_int *c);
|
||||
void fp_2expt (fp_int *a, int b);
|
||||
void fp_mul_2(fp_int *a, fp_int *c);
|
||||
void fp_div_2(fp_int *a, fp_int *c);
|
||||
|
||||
/* Counts the number of lsbs which are zero before the first zero bit */
|
||||
int fp_cnt_lsb(fp_int *a);
|
||||
|
||||
/* c = a + b */
|
||||
void fp_add(fp_int *a, fp_int *b, fp_int *c);
|
||||
|
||||
/* c = a - b */
|
||||
void fp_sub(fp_int *a, fp_int *b, fp_int *c);
|
||||
|
||||
/* c = a * b */
|
||||
void fp_mul(fp_int *a, fp_int *b, fp_int *c);
|
||||
|
||||
/* b = a*a */
|
||||
void fp_sqr(fp_int *a, fp_int *b);
|
||||
|
||||
/* a/b => cb + d == a */
|
||||
int fp_div(fp_int *a, fp_int *b, fp_int *c, fp_int *d);
|
||||
|
||||
/* c = a mod b, 0 <= c < b */
|
||||
int fp_mod(fp_int *a, fp_int *b, fp_int *c);
|
||||
|
||||
/* compare against a single digit */
|
||||
int fp_cmp_d(fp_int *a, fp_digit b);
|
||||
|
||||
/* c = a + b */
|
||||
void fp_add_d(fp_int *a, fp_digit b, fp_int *c);
|
||||
|
||||
/* c = a - b */
|
||||
void fp_sub_d(fp_int *a, fp_digit b, fp_int *c);
|
||||
|
||||
/* c = a * b */
|
||||
void fp_mul_d(fp_int *a, fp_digit b, fp_int *c);
|
||||
|
||||
/* a/b => cb + d == a */
|
||||
/*int fp_div_d(fp_int *a, fp_digit b, fp_int *c, fp_digit *d);*/
|
||||
|
||||
/* c = a mod b, 0 <= c < b */
|
||||
/*int fp_mod_d(fp_int *a, fp_digit b, fp_digit *c);*/
|
||||
|
||||
/* ---> number theory <--- */
|
||||
/* d = a + b (mod c) */
|
||||
/*int fp_addmod(fp_int *a, fp_int *b, fp_int *c, fp_int *d);*/
|
||||
|
||||
/* d = a - b (mod c) */
|
||||
/*int fp_submod(fp_int *a, fp_int *b, fp_int *c, fp_int *d);*/
|
||||
|
||||
/* d = a * b (mod c) */
|
||||
int fp_mulmod(fp_int *a, fp_int *b, fp_int *c, fp_int *d);
|
||||
|
||||
/* c = a * a (mod b) */
|
||||
int fp_sqrmod(fp_int *a, fp_int *b, fp_int *c);
|
||||
|
||||
/* c = 1/a (mod b) */
|
||||
int fp_invmod(fp_int *a, fp_int *b, fp_int *c);
|
||||
|
||||
/* c = (a, b) */
|
||||
/*void fp_gcd(fp_int *a, fp_int *b, fp_int *c);*/
|
||||
|
||||
/* c = [a, b] */
|
||||
/*void fp_lcm(fp_int *a, fp_int *b, fp_int *c);*/
|
||||
|
||||
/* setups the montgomery reduction */
|
||||
int fp_montgomery_setup(fp_int *a, fp_digit *mp);
|
||||
|
||||
/* computes a = B**n mod b without division or multiplication useful for
|
||||
* normalizing numbers in a Montgomery system.
|
||||
*/
|
||||
void fp_montgomery_calc_normalization(fp_int *a, fp_int *b);
|
||||
|
||||
/* computes x/R == x (mod N) via Montgomery Reduction */
|
||||
void fp_montgomery_reduce(fp_int *a, fp_int *m, fp_digit mp);
|
||||
|
||||
/* d = a**b (mod c) */
|
||||
int fp_exptmod(fp_int *a, fp_int *b, fp_int *c, fp_int *d);
|
||||
|
||||
/* primality stuff */
|
||||
|
||||
/* perform a Miller-Rabin test of a to the base b and store result in "result" */
|
||||
/*void fp_prime_miller_rabin (fp_int * a, fp_int * b, int *result);*/
|
||||
|
||||
/* 256 trial divisions + 8 Miller-Rabins, returns FP_YES if probable prime */
|
||||
/*int fp_isprime(fp_int *a);*/
|
||||
|
||||
/* Primality generation flags */
|
||||
/*#define TFM_PRIME_BBS 0x0001 */ /* BBS style prime */
|
||||
/*#define TFM_PRIME_SAFE 0x0002 */ /* Safe prime (p-1)/2 == prime */
|
||||
/*#define TFM_PRIME_2MSB_OFF 0x0004 */ /* force 2nd MSB to 0 */
|
||||
/*#define TFM_PRIME_2MSB_ON 0x0008 */ /* force 2nd MSB to 1 */
|
||||
|
||||
/* callback for fp_prime_random, should fill dst with random bytes and return how many read [upto len] */
|
||||
/*typedef int tfm_prime_callback(unsigned char *dst, int len, void *dat);*/
|
||||
|
||||
/*#define fp_prime_random(a, t, size, bbs, cb, dat) fp_prime_random_ex(a, t, ((size) * 8) + 1, (bbs==1)?TFM_PRIME_BBS:0, cb, dat)*/
|
||||
|
||||
/*int fp_prime_random_ex(fp_int *a, int t, int size, int flags, tfm_prime_callback cb, void *dat);*/
|
||||
|
||||
/* radix conersions */
|
||||
int fp_count_bits(fp_int *a);
|
||||
int fp_leading_bit(fp_int *a);
|
||||
|
||||
int fp_unsigned_bin_size(fp_int *a);
|
||||
void fp_read_unsigned_bin(fp_int *a, unsigned char *b, int c);
|
||||
void fp_to_unsigned_bin(fp_int *a, unsigned char *b);
|
||||
|
||||
/*int fp_signed_bin_size(fp_int *a);*/
|
||||
/*void fp_read_signed_bin(fp_int *a, unsigned char *b, int c);*/
|
||||
/*void fp_to_signed_bin(fp_int *a, unsigned char *b);*/
|
||||
|
||||
/*int fp_read_radix(fp_int *a, char *str, int radix);*/
|
||||
/*int fp_toradix(fp_int *a, char *str, int radix);*/
|
||||
/*int fp_toradix_n(fp_int * a, char *str, int radix, int maxlen);*/
|
||||
|
||||
|
||||
/* VARIOUS LOW LEVEL STUFFS */
|
||||
void s_fp_add(fp_int *a, fp_int *b, fp_int *c);
|
||||
void s_fp_sub(fp_int *a, fp_int *b, fp_int *c);
|
||||
void fp_reverse(unsigned char *s, int len);
|
||||
|
||||
void fp_mul_comba(fp_int *a, fp_int *b, fp_int *c);
|
||||
|
||||
#ifdef TFM_SMALL_SET
|
||||
void fp_mul_comba_small(fp_int *a, fp_int *b, fp_int *c);
|
||||
#endif
|
||||
|
||||
#ifdef TFM_MUL3
|
||||
void fp_mul_comba3(fp_int *a, fp_int *b, fp_int *c);
|
||||
#endif
|
||||
#ifdef TFM_MUL4
|
||||
void fp_mul_comba4(fp_int *a, fp_int *b, fp_int *c);
|
||||
#endif
|
||||
#ifdef TFM_MUL6
|
||||
void fp_mul_comba6(fp_int *a, fp_int *b, fp_int *c);
|
||||
#endif
|
||||
#ifdef TFM_MUL7
|
||||
void fp_mul_comba7(fp_int *a, fp_int *b, fp_int *c);
|
||||
#endif
|
||||
#ifdef TFM_MUL8
|
||||
void fp_mul_comba8(fp_int *a, fp_int *b, fp_int *c);
|
||||
#endif
|
||||
#ifdef TFM_MUL9
|
||||
void fp_mul_comba9(fp_int *a, fp_int *b, fp_int *c);
|
||||
#endif
|
||||
#ifdef TFM_MUL12
|
||||
void fp_mul_comba12(fp_int *a, fp_int *b, fp_int *c);
|
||||
#endif
|
||||
#ifdef TFM_MUL17
|
||||
void fp_mul_comba17(fp_int *a, fp_int *b, fp_int *c);
|
||||
#endif
|
||||
|
||||
#ifdef TFM_MUL20
|
||||
void fp_mul_comba20(fp_int *a, fp_int *b, fp_int *c);
|
||||
#endif
|
||||
#ifdef TFM_MUL24
|
||||
void fp_mul_comba24(fp_int *a, fp_int *b, fp_int *c);
|
||||
#endif
|
||||
#ifdef TFM_MUL28
|
||||
void fp_mul_comba28(fp_int *a, fp_int *b, fp_int *c);
|
||||
#endif
|
||||
#ifdef TFM_MUL32
|
||||
void fp_mul_comba32(fp_int *a, fp_int *b, fp_int *c);
|
||||
#endif
|
||||
#ifdef TFM_MUL48
|
||||
void fp_mul_comba48(fp_int *a, fp_int *b, fp_int *c);
|
||||
#endif
|
||||
#ifdef TFM_MUL64
|
||||
void fp_mul_comba64(fp_int *a, fp_int *b, fp_int *c);
|
||||
#endif
|
||||
|
||||
void fp_sqr_comba(fp_int *a, fp_int *b);
|
||||
|
||||
#ifdef TFM_SMALL_SET
|
||||
void fp_sqr_comba_small(fp_int *a, fp_int *b);
|
||||
#endif
|
||||
|
||||
#ifdef TFM_SQR3
|
||||
void fp_sqr_comba3(fp_int *a, fp_int *b);
|
||||
#endif
|
||||
#ifdef TFM_SQR4
|
||||
void fp_sqr_comba4(fp_int *a, fp_int *b);
|
||||
#endif
|
||||
#ifdef TFM_SQR6
|
||||
void fp_sqr_comba6(fp_int *a, fp_int *b);
|
||||
#endif
|
||||
#ifdef TFM_SQR7
|
||||
void fp_sqr_comba7(fp_int *a, fp_int *b);
|
||||
#endif
|
||||
#ifdef TFM_SQR8
|
||||
void fp_sqr_comba8(fp_int *a, fp_int *b);
|
||||
#endif
|
||||
#ifdef TFM_SQR9
|
||||
void fp_sqr_comba9(fp_int *a, fp_int *b);
|
||||
#endif
|
||||
#ifdef TFM_SQR12
|
||||
void fp_sqr_comba12(fp_int *a, fp_int *b);
|
||||
#endif
|
||||
#ifdef TFM_SQR17
|
||||
void fp_sqr_comba17(fp_int *a, fp_int *b);
|
||||
#endif
|
||||
|
||||
#ifdef TFM_SQR20
|
||||
void fp_sqr_comba20(fp_int *a, fp_int *b);
|
||||
#endif
|
||||
#ifdef TFM_SQR24
|
||||
void fp_sqr_comba24(fp_int *a, fp_int *b);
|
||||
#endif
|
||||
#ifdef TFM_SQR28
|
||||
void fp_sqr_comba28(fp_int *a, fp_int *b);
|
||||
#endif
|
||||
#ifdef TFM_SQR32
|
||||
void fp_sqr_comba32(fp_int *a, fp_int *b);
|
||||
#endif
|
||||
#ifdef TFM_SQR48
|
||||
void fp_sqr_comba48(fp_int *a, fp_int *b);
|
||||
#endif
|
||||
#ifdef TFM_SQR64
|
||||
void fp_sqr_comba64(fp_int *a, fp_int *b);
|
||||
#endif
|
||||
/*extern const char *fp_s_rmap;*/
|
||||
|
||||
|
||||
/**
|
||||
* Used by CyaSSL
|
||||
*/
|
||||
|
||||
/* Types */
|
||||
typedef fp_digit mp_digit;
|
||||
typedef fp_word mp_word;
|
||||
typedef fp_int mp_int;
|
||||
|
||||
/* Constants */
|
||||
#define MP_LT FP_LT /* less than */
|
||||
#define MP_EQ FP_EQ /* equal to */
|
||||
#define MP_GT FP_GT /* greater than */
|
||||
#define MP_VAL FP_VAL /* invalid */
|
||||
#define MP_OKAY FP_OKAY /* ok result */
|
||||
#define MP_NO FP_NO /* yes/no result */
|
||||
#define MP_YES FP_YES /* yes/no result */
|
||||
|
||||
/* Prototypes */
|
||||
#define mp_zero(a) fp_zero(a)
|
||||
#define mp_iseven(a) fp_iseven(a)
|
||||
int mp_init (mp_int * a);
|
||||
void mp_clear (mp_int * a);
|
||||
int mp_init_multi(mp_int* a, mp_int* b, mp_int* c, mp_int* d, mp_int* e, mp_int* f);
|
||||
|
||||
int mp_add (mp_int * a, mp_int * b, mp_int * c);
|
||||
int mp_sub (mp_int * a, mp_int * b, mp_int * c);
|
||||
int mp_add_d (mp_int * a, mp_digit b, mp_int * c);
|
||||
|
||||
int mp_mul (mp_int * a, mp_int * b, mp_int * c);
|
||||
int mp_mulmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d);
|
||||
int mp_mod(mp_int *a, mp_int *b, mp_int *c);
|
||||
int mp_invmod(mp_int *a, mp_int *b, mp_int *c);
|
||||
int mp_exptmod (mp_int * g, mp_int * x, mp_int * p, mp_int * y);
|
||||
|
||||
int mp_cmp(mp_int *a, mp_int *b);
|
||||
int mp_cmp_d(mp_int *a, mp_digit b);
|
||||
|
||||
int mp_unsigned_bin_size(mp_int * a);
|
||||
int mp_read_unsigned_bin (mp_int * a, const unsigned char *b, int c);
|
||||
int mp_to_unsigned_bin (mp_int * a, unsigned char *b);
|
||||
|
||||
int mp_sub_d(fp_int *a, fp_digit b, fp_int *c);
|
||||
int mp_copy(fp_int* a, fp_int* b);
|
||||
int mp_isodd(mp_int* a);
|
||||
int mp_iszero(mp_int* a);
|
||||
int mp_count_bits(mp_int *a);
|
||||
int mp_leading_bit(mp_int *a);
|
||||
int mp_set_int(fp_int *a, fp_digit b);
|
||||
void mp_rshb(mp_int *a, int x);
|
||||
|
||||
#ifdef HAVE_ECC
|
||||
int mp_read_radix(mp_int* a, const char* str, int radix);
|
||||
int mp_set(fp_int *a, fp_digit b);
|
||||
int mp_sqr(fp_int *a, fp_int *b);
|
||||
int mp_montgomery_reduce(fp_int *a, fp_int *m, fp_digit mp);
|
||||
int mp_montgomery_setup(fp_int *a, fp_digit *rho);
|
||||
int mp_div_2(fp_int * a, fp_int * b);
|
||||
int mp_init_copy(fp_int * a, fp_int * b);
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_ECC) || defined(CYASSL_KEY_GEN)
|
||||
int mp_sqrmod(mp_int* a, mp_int* b, mp_int* c);
|
||||
int mp_montgomery_calc_normalization(mp_int *a, mp_int *b);
|
||||
#endif
|
||||
|
||||
#ifdef CYASSL_KEY_GEN
|
||||
int mp_gcd(fp_int *a, fp_int *b, fp_int *c);
|
||||
int mp_lcm(fp_int *a, fp_int *b, fp_int *c);
|
||||
int mp_prime_is_prime(mp_int* a, int t, int* result);
|
||||
#endif /* CYASSL_KEY_GEN */
|
||||
|
||||
int mp_cnt_lsb(fp_int *a);
|
||||
int mp_div_2d(fp_int *a, int b, fp_int *c, fp_int *d);
|
||||
int mp_mod_d(fp_int* a, fp_digit b, fp_digit* c);
|
||||
|
||||
CYASSL_API word32 CheckRunTimeFastMath(void);
|
||||
|
||||
/* If user uses RSA, DH, DSA, or ECC math lib directly then fast math FP_SIZE
|
||||
must match, return 1 if a match otherwise 0 */
|
||||
#define CheckFastMathSettings() (FP_SIZE == CheckRunTimeFastMath())
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#include <wolfssl/wolfcrypt/tfm.h>
|
||||
|
||||
#endif /* CTAO_CRYPT_TFM_H */
|
||||
|
||||
|
@ -23,7 +23,8 @@
|
||||
#ifndef CTAO_CRYPT_TYPES_H
|
||||
#define CTAO_CRYPT_TYPES_H
|
||||
|
||||
#ifndef HAVE_FIPS
|
||||
#include <cyassl/ctaocrypt/wc_port.h>
|
||||
#include <cyassl/ctaocrypt/settings.h>
|
||||
#include <wolfssl/wolfcrypt/types.h>
|
||||
/* compatibility macros */
|
||||
#define CYASSL_WORD_SIZE WOLFSSL_WORD_SIZE
|
||||
@ -31,309 +32,30 @@
|
||||
#define CYASSL_MAX_16BIT WOLFSSL_MAX_16BIT
|
||||
#define CYASSL_MAX_ERROR_SZ WOLFSSL_MAX_ERROR_SZ
|
||||
#define cyassl_word wolfssl_word
|
||||
#else
|
||||
|
||||
#include <cyassl/ctaocrypt/settings.h>
|
||||
#include <cyassl/ctaocrypt/wc_port.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(WORDS_BIGENDIAN)
|
||||
#define BIG_ENDIAN_ORDER
|
||||
#endif
|
||||
|
||||
#ifndef BIG_ENDIAN_ORDER
|
||||
#define LITTLE_ENDIAN_ORDER
|
||||
#endif
|
||||
|
||||
#ifndef CYASSL_TYPES
|
||||
#ifndef byte
|
||||
typedef unsigned char byte;
|
||||
#endif
|
||||
typedef unsigned short word16;
|
||||
typedef unsigned int word32;
|
||||
#endif
|
||||
|
||||
|
||||
/* try to set SIZEOF_LONG or LONG_LONG if user didn't */
|
||||
#if !defined(_MSC_VER) && !defined(__BCPLUSPLUS__)
|
||||
#if !defined(SIZEOF_LONG_LONG) && !defined(SIZEOF_LONG)
|
||||
#if (defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) \
|
||||
|| defined(__mips64) || defined(__x86_64__))
|
||||
/* long should be 64bit */
|
||||
#define SIZEOF_LONG 8
|
||||
#elif defined(__i386__) || defined(__CORTEX_M3__)
|
||||
/* long long should be 64bit */
|
||||
#define SIZEOF_LONG_LONG 8
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(_MSC_VER) || defined(__BCPLUSPLUS__)
|
||||
#define WORD64_AVAILABLE
|
||||
#define W64LIT(x) x##ui64
|
||||
typedef unsigned __int64 word64;
|
||||
#elif defined(SIZEOF_LONG) && SIZEOF_LONG == 8
|
||||
#define WORD64_AVAILABLE
|
||||
#define W64LIT(x) x##LL
|
||||
typedef unsigned long word64;
|
||||
#elif defined(SIZEOF_LONG_LONG) && SIZEOF_LONG_LONG == 8
|
||||
#define WORD64_AVAILABLE
|
||||
#define W64LIT(x) x##LL
|
||||
typedef unsigned long long word64;
|
||||
#elif defined(__SIZEOF_LONG_LONG__) && __SIZEOF_LONG_LONG__ == 8
|
||||
#define WORD64_AVAILABLE
|
||||
#define W64LIT(x) x##LL
|
||||
typedef unsigned long long word64;
|
||||
#else
|
||||
#define MP_16BIT /* for mp_int, mp_word needs to be twice as big as
|
||||
mp_digit, no 64 bit type so make mp_digit 16 bit */
|
||||
#endif
|
||||
|
||||
|
||||
/* These platforms have 64-bit CPU registers. */
|
||||
#if (defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) || \
|
||||
defined(__mips64) || defined(__x86_64__) || defined(_M_X64))
|
||||
typedef word64 cyassl_word;
|
||||
#else
|
||||
typedef word32 cyassl_word;
|
||||
#ifdef WORD64_AVAILABLE
|
||||
#define CTAOCRYPT_SLOW_WORD64
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
enum {
|
||||
CYASSL_WORD_SIZE = sizeof(cyassl_word),
|
||||
CYASSL_BIT_SIZE = 8,
|
||||
CYASSL_WORD_BITS = CYASSL_WORD_SIZE * CYASSL_BIT_SIZE
|
||||
};
|
||||
|
||||
#define CYASSL_MAX_16BIT 0xffffU
|
||||
|
||||
/* use inlining if compiler allows */
|
||||
#ifndef INLINE
|
||||
#ifndef NO_INLINE
|
||||
#ifdef _MSC_VER
|
||||
#define INLINE __inline
|
||||
#elif defined(__GNUC__)
|
||||
#define INLINE inline
|
||||
#elif defined(__IAR_SYSTEMS_ICC__)
|
||||
#define INLINE inline
|
||||
#elif defined(THREADX)
|
||||
#define INLINE _Inline
|
||||
#else
|
||||
#define INLINE
|
||||
#endif
|
||||
#else
|
||||
#define INLINE
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/* set up rotate style */
|
||||
#if defined(_MSC_VER) || defined(__BCPLUSPLUS__)
|
||||
#define INTEL_INTRINSICS
|
||||
#define FAST_ROTATE
|
||||
#elif defined(__MWERKS__) && TARGET_CPU_PPC
|
||||
#define PPC_INTRINSICS
|
||||
#define FAST_ROTATE
|
||||
#elif defined(__GNUC__) && defined(__i386__)
|
||||
/* GCC does peephole optimizations which should result in using rotate
|
||||
instructions */
|
||||
#define FAST_ROTATE
|
||||
#endif
|
||||
|
||||
|
||||
/* set up thread local storage if available */
|
||||
#ifdef HAVE_THREAD_LS
|
||||
#if defined(_MSC_VER)
|
||||
#define THREAD_LS_T __declspec(thread)
|
||||
#else
|
||||
#define THREAD_LS_T __thread
|
||||
#endif
|
||||
#else
|
||||
#define THREAD_LS_T
|
||||
#endif
|
||||
|
||||
|
||||
/* Micrium will use Visual Studio for compilation but not the Win32 API */
|
||||
#if defined(_WIN32) && !defined(MICRIUM) && !defined(FREERTOS) \
|
||||
&& !defined(EBSNET)
|
||||
#define USE_WINDOWS_API
|
||||
#endif
|
||||
|
||||
|
||||
/* idea to add global alloc override by Moisés Guimarães */
|
||||
/* default to libc stuff */
|
||||
/* XREALLOC is used once in normal math lib, not in fast math lib */
|
||||
/* XFREE on some embeded systems doesn't like free(0) so test */
|
||||
#if defined(XMALLOC_USER)
|
||||
/* prototypes for user heap override functions */
|
||||
#include <stddef.h> /* for size_t */
|
||||
extern void *XMALLOC(size_t n, void* heap, int type);
|
||||
extern void *XREALLOC(void *p, size_t n, void* heap, int type);
|
||||
extern void XFREE(void *p, void* heap, int type);
|
||||
#elif defined(NO_CYASSL_MEMORY)
|
||||
/* just use plain C stdlib stuff if desired */
|
||||
#include <stdlib.h>
|
||||
#define XMALLOC(s, h, t) ((void)h, (void)t, malloc((s)))
|
||||
#define XFREE(p, h, t) {void* xp = (p); if((xp)) free((xp));}
|
||||
#define XREALLOC(p, n, h, t) realloc((p), (n))
|
||||
#elif !defined(MICRIUM_MALLOC) && !defined(EBSNET) \
|
||||
&& !defined(CYASSL_SAFERTOS) && !defined(FREESCALE_MQX) \
|
||||
&& !defined(CYASSL_LEANPSK)
|
||||
/* default C runtime, can install different routines at runtime via cbs */
|
||||
#include <cyassl/ctaocrypt/memory.h>
|
||||
#define XMALLOC(s, h, t) ((void)h, (void)t, CyaSSL_Malloc((s)))
|
||||
#define XFREE(p, h, t) {void* xp = (p); if((xp)) CyaSSL_Free((xp));}
|
||||
#define XREALLOC(p, n, h, t) CyaSSL_Realloc((p), (n))
|
||||
#endif
|
||||
|
||||
#ifndef STRING_USER
|
||||
#include <string.h>
|
||||
char* mystrnstr(const char* s1, const char* s2, unsigned int n);
|
||||
|
||||
#define XMEMCPY(d,s,l) memcpy((d),(s),(l))
|
||||
#define XMEMSET(b,c,l) memset((b),(c),(l))
|
||||
#define XMEMCMP(s1,s2,n) memcmp((s1),(s2),(n))
|
||||
#define XMEMMOVE(d,s,l) memmove((d),(s),(l))
|
||||
|
||||
#define XSTRLEN(s1) strlen((s1))
|
||||
#define XSTRNCPY(s1,s2,n) strncpy((s1),(s2),(n))
|
||||
/* strstr, strncmp, and strncat only used by CyaSSL proper, not required for
|
||||
CTaoCrypt only */
|
||||
#define XSTRSTR(s1,s2) strstr((s1),(s2))
|
||||
#define XSTRNSTR(s1,s2,n) mystrnstr((s1),(s2),(n))
|
||||
#define XSTRNCMP(s1,s2,n) strncmp((s1),(s2),(n))
|
||||
#define XSTRNCAT(s1,s2,n) strncat((s1),(s2),(n))
|
||||
#ifndef USE_WINDOWS_API
|
||||
#define XSTRNCASECMP(s1,s2,n) strncasecmp((s1),(s2),(n))
|
||||
#define XSNPRINTF snprintf
|
||||
#else
|
||||
#define XSTRNCASECMP(s1,s2,n) _strnicmp((s1),(s2),(n))
|
||||
#define XSNPRINTF _snprintf
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef CTYPE_USER
|
||||
#include <ctype.h>
|
||||
#if defined(HAVE_ECC) || defined(HAVE_OCSP)
|
||||
#define XTOUPPER(c) toupper((c))
|
||||
#define XISALPHA(c) isalpha((c))
|
||||
#endif
|
||||
/* needed by CyaSSL_check_domain_name() */
|
||||
#ifdef __CYGWIN__
|
||||
/* Cygwin uses a macro version of tolower() by default, use the
|
||||
* function version. */
|
||||
#undef tolower
|
||||
#endif
|
||||
#define XTOLOWER(c) tolower((c))
|
||||
#endif
|
||||
|
||||
|
||||
/* memory allocation types for user hints */
|
||||
enum {
|
||||
DYNAMIC_TYPE_CA = 1,
|
||||
DYNAMIC_TYPE_CERT = 2,
|
||||
DYNAMIC_TYPE_KEY = 3,
|
||||
DYNAMIC_TYPE_FILE = 4,
|
||||
DYNAMIC_TYPE_SUBJECT_CN = 5,
|
||||
DYNAMIC_TYPE_PUBLIC_KEY = 6,
|
||||
DYNAMIC_TYPE_SIGNER = 7,
|
||||
DYNAMIC_TYPE_NONE = 8,
|
||||
DYNAMIC_TYPE_BIGINT = 9,
|
||||
DYNAMIC_TYPE_RSA = 10,
|
||||
DYNAMIC_TYPE_METHOD = 11,
|
||||
DYNAMIC_TYPE_OUT_BUFFER = 12,
|
||||
DYNAMIC_TYPE_IN_BUFFER = 13,
|
||||
DYNAMIC_TYPE_INFO = 14,
|
||||
DYNAMIC_TYPE_DH = 15,
|
||||
DYNAMIC_TYPE_DOMAIN = 16,
|
||||
DYNAMIC_TYPE_SSL = 17,
|
||||
DYNAMIC_TYPE_CTX = 18,
|
||||
DYNAMIC_TYPE_WRITEV = 19,
|
||||
DYNAMIC_TYPE_OPENSSL = 20,
|
||||
DYNAMIC_TYPE_DSA = 21,
|
||||
DYNAMIC_TYPE_CRL = 22,
|
||||
DYNAMIC_TYPE_REVOKED = 23,
|
||||
DYNAMIC_TYPE_CRL_ENTRY = 24,
|
||||
DYNAMIC_TYPE_CERT_MANAGER = 25,
|
||||
DYNAMIC_TYPE_CRL_MONITOR = 26,
|
||||
DYNAMIC_TYPE_OCSP_STATUS = 27,
|
||||
DYNAMIC_TYPE_OCSP_ENTRY = 28,
|
||||
DYNAMIC_TYPE_ALTNAME = 29,
|
||||
DYNAMIC_TYPE_SUITES = 30,
|
||||
DYNAMIC_TYPE_CIPHER = 31,
|
||||
DYNAMIC_TYPE_RNG = 32,
|
||||
DYNAMIC_TYPE_ARRAYS = 33,
|
||||
DYNAMIC_TYPE_DTLS_POOL = 34,
|
||||
DYNAMIC_TYPE_SOCKADDR = 35,
|
||||
DYNAMIC_TYPE_LIBZ = 36,
|
||||
DYNAMIC_TYPE_ECC = 37,
|
||||
DYNAMIC_TYPE_TMP_BUFFER = 38,
|
||||
DYNAMIC_TYPE_DTLS_MSG = 39,
|
||||
DYNAMIC_TYPE_CAVIUM_TMP = 40,
|
||||
DYNAMIC_TYPE_CAVIUM_RSA = 41,
|
||||
DYNAMIC_TYPE_X509 = 42,
|
||||
DYNAMIC_TYPE_TLSX = 43,
|
||||
DYNAMIC_TYPE_OCSP = 44,
|
||||
DYNAMIC_TYPE_SIGNATURE = 45
|
||||
};
|
||||
|
||||
/* max error buffer string size */
|
||||
enum {
|
||||
CYASSL_MAX_ERROR_SZ = 80
|
||||
};
|
||||
|
||||
/* stack protection */
|
||||
enum {
|
||||
MIN_STACK_BUFFER = 8
|
||||
};
|
||||
|
||||
|
||||
|
||||
/* settings detection for compile vs runtime math incombatibilities */
|
||||
enum {
|
||||
#if !defined(USE_FAST_MATH) && !defined(SIZEOF_LONG) && !defined(SIZEOF_LONG_LONG)
|
||||
CTC_SETTINGS = 0x0
|
||||
#elif !defined(USE_FAST_MATH) && defined(SIZEOF_LONG) && (SIZEOF_LONG == 8)
|
||||
CTC_SETTINGS = 0x1
|
||||
#elif !defined(USE_FAST_MATH) && defined(SIZEOF_LONG_LONG) && (SIZEOF_LONG_LONG == 8)
|
||||
CTC_SETTINGS = 0x2
|
||||
#elif !defined(USE_FAST_MATH) && defined(SIZEOF_LONG_LONG) && (SIZEOF_LONG_LONG == 4)
|
||||
CTC_SETTINGS = 0x4
|
||||
#elif defined(USE_FAST_MATH) && !defined(SIZEOF_LONG) && !defined(SIZEOF_LONG_LONG)
|
||||
CTC_SETTINGS = 0x8
|
||||
#elif defined(USE_FAST_MATH) && defined(SIZEOF_LONG) && (SIZEOF_LONG == 8)
|
||||
CTC_SETTINGS = 0x10
|
||||
#elif defined(USE_FAST_MATH) && defined(SIZEOF_LONG_LONG) && (SIZEOF_LONG_LONG == 8)
|
||||
CTC_SETTINGS = 0x20
|
||||
#elif defined(USE_FAST_MATH) && defined(SIZEOF_LONG_LONG) && (SIZEOF_LONG_LONG == 4)
|
||||
CTC_SETTINGS = 0x40
|
||||
#else
|
||||
#error "bad math long / long long settings"
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
CYASSL_API word32 CheckRunTimeSettings(void);
|
||||
|
||||
/* If user uses RSA, DH, DSA, or ECC math lib directly then fast math and long
|
||||
types need to match at compile time and run time, CheckCtcSettings will
|
||||
return 1 if a match otherwise 0 */
|
||||
#define CheckCtcSettings() (CTC_SETTINGS == CheckRunTimeSettings())
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* HAVE_FIPS */
|
||||
// /* set old macros since this is often called for visibility also */
|
||||
// #ifndef WOLFSSL_API
|
||||
// #define WOLFSSL_API CYASSL_API
|
||||
// #endif
|
||||
// #ifndef WOLFSSL_LOCAL
|
||||
// #define WOLFSSL_LOCAL CYASSL_LOCAL
|
||||
// #endif
|
||||
// #define WOLFSSL_MAX_ERROR_SZ CYASSL_MAX_ERROR_SZ
|
||||
//
|
||||
// #define WOLFSSL_WORD_SIZE CYASSL_WORD_SIZE
|
||||
// #define WOLFSSL_BIT_SIZE CYASSL_BIT_SIZE
|
||||
// #define WOLFSSL_MAX_16BIT CYASSL_MAX_16BIT
|
||||
// #define WOLFSSL_MAX_ERROR_SZ CYASSL_MAX_ERROR_SZ
|
||||
// #define wolfssl_word cyassl_word
|
||||
///* memory macros */
|
||||
// /* when using fips map wolfSSL to CyaSSL*/
|
||||
// #define wolfSSL_Malloc_cb CyaSSL_Malloc_cb
|
||||
// #define wolfSSL_Free_cb CyaSSL_Free_cb
|
||||
// #define wolfSSL_Realloc_cb CyaSSL_Realloc_cb
|
||||
// #define wolfSSL_SetAllocators CyaSSL_SetAllocators
|
||||
//
|
||||
// /* Public in case user app wants to use XMALLOC/XFREE */
|
||||
// #define wolfSSL_Malloc CyaSSL_Malloc
|
||||
// #define wolfSSL_Free CyaSSL_Free
|
||||
// #define wolfSSL_Realloc CyaSSL_Realloc
|
||||
#endif /* CTAO_CRYPT_TYPES_H */
|
||||
|
||||
|
@ -24,56 +24,14 @@
|
||||
#ifndef CTAO_CRYPT_VISIBILITY_H
|
||||
#define CTAO_CRYPT_VISIBILITY_H
|
||||
|
||||
#include <wolfssl/wolfcrypt/visibility.h>
|
||||
/* fips compatibility @wc_fips */
|
||||
#ifndef HAVE_FIPS
|
||||
#ifndef CYASSL_API
|
||||
#define CYASSL_API WOLFSSL_API
|
||||
#endif
|
||||
#ifndef CYASSL_LOCAL
|
||||
#define CYASSL_LOCAL WOLFSSL_LOCAL
|
||||
#endif
|
||||
#include <wolfssl/wolfcrypt/visibility.h>
|
||||
#else
|
||||
#define BUILDING_CYASSL
|
||||
/* CYASSL_API is used for the public API symbols.
|
||||
It either imports or exports (or does nothing for static builds)
|
||||
|
||||
CYASSL_LOCAL is used for non-API symbols (private).
|
||||
*/
|
||||
|
||||
#if defined(BUILDING_CYASSL)
|
||||
#if defined(HAVE_VISIBILITY) && HAVE_VISIBILITY
|
||||
#define CYASSL_API __attribute__ ((visibility("default")))
|
||||
#define CYASSL_LOCAL __attribute__ ((visibility("hidden")))
|
||||
#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
|
||||
#define CYASSL_API __global
|
||||
#define CYASSL_LOCAL __hidden
|
||||
#elif defined(_MSC_VER)
|
||||
#ifdef CYASSL_DLL
|
||||
#define CYASSL_API extern __declspec(dllexport)
|
||||
#else
|
||||
#define CYASSL_API
|
||||
#endif
|
||||
#define CYASSL_LOCAL
|
||||
#else
|
||||
#define CYASSL_API
|
||||
#define CYASSL_LOCAL
|
||||
#endif /* HAVE_VISIBILITY */
|
||||
#else /* BUILDING_CYASSL */
|
||||
#if defined(_MSC_VER)
|
||||
#ifdef CYASSL_DLL
|
||||
#define CYASSL_API extern __declspec(dllimport)
|
||||
#else
|
||||
#define CYASSL_API
|
||||
#endif
|
||||
#define CYASSL_LOCAL
|
||||
#else
|
||||
#define CYASSL_API
|
||||
#define CYASSL_LOCAL
|
||||
#endif
|
||||
#endif /* BUILDING_CYASSL */
|
||||
|
||||
|
||||
#endif /* HAVE_FIPS */
|
||||
//#ifdef HAVE_FIPS
|
||||
// #define WOLFSSL_API CYASSL_API
|
||||
// #define WOLFSSL_LOCAL CYASSL_LOCAL
|
||||
//#else
|
||||
#define CYASSL_API WOLFSSL_API
|
||||
#define CYASSL_LOCAL WOLFSSL_LOCAL
|
||||
//#endif /* HAVE_FIPS */
|
||||
#endif /* CTAO_CRYPT_VISIBILITY_H */
|
||||
|
||||
|
@ -23,178 +23,8 @@
|
||||
#ifndef CTAO_CRYPT_PORT_H
|
||||
#define CTAO_CRYPT_PORT_H
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef USE_WINDOWS_API
|
||||
#ifdef CYASSL_GAME_BUILD
|
||||
#include "system/xtl.h"
|
||||
#else
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#if defined(_WIN32_WCE) || defined(WIN32_LEAN_AND_MEAN)
|
||||
/* On WinCE winsock2.h must be included before windows.h */
|
||||
#include <winsock2.h>
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#elif defined(THREADX)
|
||||
#ifndef SINGLE_THREADED
|
||||
#include "tx_api.h"
|
||||
#endif
|
||||
#elif defined(MICRIUM)
|
||||
/* do nothing, just don't pick Unix */
|
||||
#elif defined(FREERTOS) || defined(CYASSL_SAFERTOS)
|
||||
/* do nothing */
|
||||
#elif defined(EBSNET)
|
||||
/* do nothing */
|
||||
#elif defined(FREESCALE_MQX)
|
||||
/* do nothing */
|
||||
#elif defined(CYASSL_MDK_ARM)
|
||||
#if defined(CYASSL_MDK5)
|
||||
#include "cmsis_os.h"
|
||||
#else
|
||||
#include <rtl.h>
|
||||
#endif
|
||||
#elif defined(CYASSL_CMSIS_RTOS)
|
||||
#include "cmsis_os.h"
|
||||
#elif defined(CYASSL_TIRTOS)
|
||||
#include <ti/sysbios/BIOS.h>
|
||||
#include <ti/sysbios/knl/Semaphore.h>
|
||||
#else
|
||||
#ifndef SINGLE_THREADED
|
||||
#define CYASSL_PTHREADS
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
#if defined(OPENSSL_EXTRA) || defined(GOAHEAD_WS)
|
||||
#include <unistd.h> /* for close of BIO */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef SINGLE_THREADED
|
||||
typedef int CyaSSL_Mutex;
|
||||
#else /* MULTI_THREADED */
|
||||
/* FREERTOS comes first to enable use of FreeRTOS Windows simulator only */
|
||||
#ifdef FREERTOS
|
||||
typedef xSemaphoreHandle CyaSSL_Mutex;
|
||||
#elif defined(CYASSL_SAFERTOS)
|
||||
typedef struct CyaSSL_Mutex {
|
||||
signed char mutexBuffer[portQUEUE_OVERHEAD_BYTES];
|
||||
xSemaphoreHandle mutex;
|
||||
} CyaSSL_Mutex;
|
||||
#elif defined(USE_WINDOWS_API)
|
||||
typedef CRITICAL_SECTION CyaSSL_Mutex;
|
||||
#elif defined(CYASSL_PTHREADS)
|
||||
typedef pthread_mutex_t CyaSSL_Mutex;
|
||||
#elif defined(THREADX)
|
||||
typedef TX_MUTEX CyaSSL_Mutex;
|
||||
#elif defined(MICRIUM)
|
||||
typedef OS_MUTEX CyaSSL_Mutex;
|
||||
#elif defined(EBSNET)
|
||||
typedef RTP_MUTEX CyaSSL_Mutex;
|
||||
#elif defined(FREESCALE_MQX)
|
||||
typedef MUTEX_STRUCT CyaSSL_Mutex;
|
||||
#elif defined(CYASSL_MDK_ARM)
|
||||
#if defined(CYASSL_CMSIS_RTOS)
|
||||
typedef osMutexId CyaSSL_Mutex;
|
||||
#else
|
||||
typedef OS_MUT CyaSSL_Mutex;
|
||||
#endif
|
||||
#elif defined(CYASSL_CMSIS_RTOS)
|
||||
typedef osMutexId CyaSSL_Mutex;
|
||||
#elif defined(CYASSL_TIRTOS)
|
||||
typedef ti_sysbios_knl_Semaphore_Handle CyaSSL_Mutex;
|
||||
#else
|
||||
#error Need a mutex type in multithreaded mode
|
||||
#endif /* USE_WINDOWS_API */
|
||||
#endif /* SINGLE_THREADED */
|
||||
|
||||
CYASSL_LOCAL int InitMutex(CyaSSL_Mutex*);
|
||||
CYASSL_LOCAL int FreeMutex(CyaSSL_Mutex*);
|
||||
CYASSL_LOCAL int LockMutex(CyaSSL_Mutex*);
|
||||
CYASSL_LOCAL int UnLockMutex(CyaSSL_Mutex*);
|
||||
|
||||
|
||||
/* filesystem abstraction layer, used by ssl.c */
|
||||
#ifndef NO_FILESYSTEM
|
||||
|
||||
#if defined(EBSNET)
|
||||
#define XFILE int
|
||||
#define XFOPEN(NAME, MODE) vf_open((const char *)NAME, VO_RDONLY, 0);
|
||||
#define XFSEEK vf_lseek
|
||||
#define XFTELL vf_tell
|
||||
#define XREWIND vf_rewind
|
||||
#define XFREAD(BUF, SZ, AMT, FD) vf_read(FD, BUF, SZ*AMT)
|
||||
#define XFWRITE(BUF, SZ, AMT, FD) vf_write(FD, BUF, SZ*AMT)
|
||||
#define XFCLOSE vf_close
|
||||
#define XSEEK_END VSEEK_END
|
||||
#define XBADFILE -1
|
||||
#elif defined(LSR_FS)
|
||||
#include <fs.h>
|
||||
#define XFILE struct fs_file*
|
||||
#define XFOPEN(NAME, MODE) fs_open((char*)NAME);
|
||||
#define XFSEEK(F, O, W) (void)F
|
||||
#define XFTELL(F) (F)->len
|
||||
#define XREWIND(F) (void)F
|
||||
#define XFREAD(BUF, SZ, AMT, F) fs_read(F, (char*)BUF, SZ*AMT)
|
||||
#define XFWRITE(BUF, SZ, AMT, F) fs_write(F, (char*)BUF, SZ*AMT)
|
||||
#define XFCLOSE fs_close
|
||||
#define XSEEK_END 0
|
||||
#define XBADFILE NULL
|
||||
#elif defined(FREESCALE_MQX)
|
||||
#define XFILE MQX_FILE_PTR
|
||||
#define XFOPEN fopen
|
||||
#define XFSEEK fseek
|
||||
#define XFTELL ftell
|
||||
#define XREWIND(F) fseek(F, 0, IO_SEEK_SET)
|
||||
#define XFREAD fread
|
||||
#define XFWRITE fwrite
|
||||
#define XFCLOSE fclose
|
||||
#define XSEEK_END IO_SEEK_END
|
||||
#define XBADFILE NULL
|
||||
#elif defined(MICRIUM)
|
||||
#include <fs.h>
|
||||
#define XFILE FS_FILE*
|
||||
#define XFOPEN fs_fopen
|
||||
#define XFSEEK fs_fseek
|
||||
#define XFTELL fs_ftell
|
||||
#define XREWIND fs_rewind
|
||||
#define XFREAD fs_fread
|
||||
#define XFWRITE fs_fwrite
|
||||
#define XFCLOSE fs_fclose
|
||||
#define XSEEK_END FS_SEEK_END
|
||||
#define XBADFILE NULL
|
||||
#else
|
||||
/* stdio, default case */
|
||||
#define XFILE FILE*
|
||||
#if defined(CYASSL_MDK_ARM)
|
||||
#include <stdio.h>
|
||||
extern FILE * CyaSSL_fopen(const char *name, const char *mode) ;
|
||||
#define XFOPEN CyaSSL_fopen
|
||||
#else
|
||||
#define XFOPEN fopen
|
||||
#endif
|
||||
#define XFSEEK fseek
|
||||
#define XFTELL ftell
|
||||
#define XREWIND rewind
|
||||
#define XFREAD fread
|
||||
#define XFWRITE fwrite
|
||||
#define XFCLOSE fclose
|
||||
#define XSEEK_END SEEK_END
|
||||
#define XBADFILE NULL
|
||||
#endif
|
||||
|
||||
#endif /* NO_FILESYSTEM */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
#include <wolfssl/wolfcrypt/wc_port.h>
|
||||
#define CyaSSL_Mutex wolfSSL_Mutex
|
||||
|
||||
#endif /* CTAO_CRYPT_PORT_H */
|
||||
|
||||
|
@ -404,12 +404,6 @@
|
||||
*/
|
||||
#define NO_WOLFSSL_ALLOC_ALIGN NO_CYASSL_ALLOC_ALIGN /* @TODO */
|
||||
|
||||
/* for pwdbased reverse compatibility */
|
||||
#ifndef NO_PWDBASED
|
||||
#define PBKDF1 wc_PBKDF1
|
||||
#define PBKDF2 wc_PBKDF2
|
||||
#define PKCS12_PBKDF wc_PKCS12_PBKDF
|
||||
#endif
|
||||
|
||||
/* examples/client/client.h */
|
||||
#define CYASSL_THREAD WOLFSSL_THREAD
|
||||
|
@ -13,7 +13,6 @@ src_libwolfssl_la_CPPFLAGS = -DBUILDING_WOLFSSL $(AM_CPPFLAGS)
|
||||
# fips first file
|
||||
if BUILD_FIPS
|
||||
src_libwolfssl_la_SOURCES += ctaocrypt/src/wolfcrypt_first.c
|
||||
#endif
|
||||
|
||||
src_libwolfssl_la_SOURCES += \
|
||||
ctaocrypt/src/hmac.c \
|
||||
@ -40,13 +39,10 @@ if BUILD_SHA512
|
||||
src_libwolfssl_la_SOURCES += ctaocrypt/src/sha512.c
|
||||
endif
|
||||
|
||||
#if BUILD_FIPS
|
||||
src_libwolfssl_la_SOURCES += ctaocrypt/src/fips.c
|
||||
src_libwolfssl_la_SOURCES += ctaocrypt/src/fips_test.c
|
||||
#endif
|
||||
|
||||
# fips last file
|
||||
#if BUILD_FIPS
|
||||
src_libwolfssl_la_SOURCES += ctaocrypt/src/wolfcrypt_last.c
|
||||
endif
|
||||
|
||||
@ -75,45 +71,26 @@ if BUILD_SHA512
|
||||
src_libwolfssl_la_SOURCES += wolfcrypt/src/sha512.c
|
||||
endif
|
||||
|
||||
if BUILD_FIPS
|
||||
src_libwolfssl_la_SOURCES += \
|
||||
ctaocrypt/src/logging.c \
|
||||
ctaocrypt/src/wc_port.c \
|
||||
wolfcrypt/src/error.c
|
||||
else
|
||||
src_libwolfssl_la_SOURCES += \
|
||||
wolfcrypt/src/logging.c \
|
||||
wolfcrypt/src/wc_port.c \
|
||||
wolfcrypt/src/error.c
|
||||
endif
|
||||
|
||||
if BUILD_MEMORY
|
||||
if BUILD_FIPS
|
||||
src_libwolfssl_la_SOURCES += ctaocrypt/src/memory.c
|
||||
else
|
||||
src_libwolfssl_la_SOURCES += wolfcrypt/src/memory.c
|
||||
endif
|
||||
endif
|
||||
|
||||
if BUILD_DH
|
||||
src_libwolfssl_la_SOURCES += wolfcrypt/src/dh.c
|
||||
endif
|
||||
|
||||
if BUILD_ASN
|
||||
if BUILD_FIPS
|
||||
src_libwolfssl_la_SOURCES += ctaocrypt/src/asn.c
|
||||
else
|
||||
src_libwolfssl_la_SOURCES += wolfcrypt/src/asn.c
|
||||
endif
|
||||
endif
|
||||
|
||||
if BUILD_CODING
|
||||
if BUILD_FIPS
|
||||
src_libwolfssl_la_SOURCES += ctaocrypt/src/coding.c
|
||||
else
|
||||
src_libwolfssl_la_SOURCES += wolfcrypt/src/coding.c
|
||||
endif
|
||||
endif
|
||||
|
||||
if BUILD_POLY1305
|
||||
src_libwolfssl_la_SOURCES += wolfcrypt/src/poly1305.c
|
||||
@ -128,32 +105,20 @@ src_libwolfssl_la_SOURCES += wolfcrypt/src/md4.c
|
||||
endif
|
||||
|
||||
if BUILD_MD5
|
||||
if BUILD_FIPS
|
||||
src_libwolfssl_la_SOURCES += ctaocrypt/src/md5.c
|
||||
else
|
||||
src_libwolfssl_la_SOURCES += wolfcrypt/src/md5.c
|
||||
endif
|
||||
endif
|
||||
|
||||
if BUILD_PWDBASED
|
||||
if BUILD_FIPS
|
||||
src_libwolfssl_la_SOURCES += ctaocrypt/src/pwdbased.c
|
||||
else
|
||||
src_libwolfssl_la_SOURCES += wolfcrypt/src/pwdbased.c
|
||||
endif
|
||||
endif
|
||||
|
||||
if BUILD_DSA
|
||||
src_libwolfssl_la_SOURCES += wolfcrypt/src/dsa.c
|
||||
endif
|
||||
|
||||
if BUILD_AESNI
|
||||
if BUILD_FIPS
|
||||
src_libwolfssl_la_SOURCES += ctaocrypt/src/aes_asm.s
|
||||
else
|
||||
src_libwolfssl_la_SOURCES += wolfcrypt/src/aes_asm.s
|
||||
endif
|
||||
endif
|
||||
|
||||
if BUILD_CAMELLIA
|
||||
src_libwolfssl_la_SOURCES += wolfcrypt/src/camellia.c
|
||||
@ -168,12 +133,8 @@ src_libwolfssl_la_SOURCES += wolfcrypt/src/ripemd.c
|
||||
endif
|
||||
|
||||
if BUILD_BLAKE2
|
||||
if BUILD_FIPS
|
||||
src_libwolfssl_la_SOURCES += ctaocrypt/src/blake2b.c
|
||||
else
|
||||
src_libwolfssl_la_SOURCES += wolfcrypt/src/blake2b.c
|
||||
endif
|
||||
endif
|
||||
|
||||
if BUILD_HC128
|
||||
src_libwolfssl_la_SOURCES += wolfcrypt/src/hc128.c
|
||||
@ -188,48 +149,28 @@ src_libwolfssl_la_SOURCES += wolfcrypt/src/chacha.c
|
||||
endif
|
||||
|
||||
if !BUILD_INLINE
|
||||
if BUILD_FIPS
|
||||
src_libwolfssl_la_SOURCES += ctaocrypt/src/misc.c
|
||||
else
|
||||
src_libwolfssl_la_SOURCES += wolfcrypt/src/misc.c
|
||||
endif
|
||||
endif
|
||||
|
||||
if BUILD_FASTMATH
|
||||
if BUILD_FIPS
|
||||
src_libwolfssl_la_SOURCES += ctaocrypt/src/tfm.c
|
||||
else
|
||||
src_libwolfssl_la_SOURCES += wolfcrypt/src/tfm.c
|
||||
endif
|
||||
endif
|
||||
|
||||
if BUILD_SLOWMATH
|
||||
if BUILD_FIPS
|
||||
src_libwolfssl_la_SOURCES += ctaocrypt/src/integer.c
|
||||
else
|
||||
src_libwolfssl_la_SOURCES += wolfcrypt/src/integer.c
|
||||
endif
|
||||
endif
|
||||
|
||||
if BUILD_ECC
|
||||
src_libwolfssl_la_SOURCES += wolfcrypt/src/ecc.c
|
||||
endif
|
||||
|
||||
if BUILD_LIBZ
|
||||
if BUILD_FIPS
|
||||
src_libwolfssl_la_SOURCES += ctaocrypt/src/compress.c
|
||||
else
|
||||
src_libwolfssl_la_SOURCES += wolfcrypt/src/compress.c
|
||||
endif
|
||||
endif
|
||||
|
||||
if BUILD_PKCS7
|
||||
if BUILD_FIPS
|
||||
src_libwolfssl_la_SOURCES += ctaocrypt/src/pkcs7.c
|
||||
else
|
||||
src_libwolfssl_la_SOURCES += wolfcrypt/src/pkcs7.c
|
||||
endif
|
||||
endif
|
||||
|
||||
# ssl files
|
||||
src_libwolfssl_la_SOURCES += \
|
||||
|
@ -775,7 +775,7 @@ int ToTraditional(byte* input, word32 sz)
|
||||
|
||||
if (GetMyVersion(input, &inOutIdx, &version) < 0)
|
||||
return ASN_PARSE_E;
|
||||
|
||||
|
||||
if (GetAlgoId(input, &inOutIdx, &oid, sz) < 0)
|
||||
return ASN_PARSE_E;
|
||||
|
||||
@ -786,13 +786,13 @@ int ToTraditional(byte* input, word32 sz)
|
||||
return ASN_PARSE_E;
|
||||
inOutIdx += length; /* over sub id, key input will verify */
|
||||
}
|
||||
|
||||
|
||||
if (input[inOutIdx++] != ASN_OCTET_STRING)
|
||||
return ASN_PARSE_E;
|
||||
|
||||
|
||||
if (GetLength(input, &inOutIdx, &length, sz) < 0)
|
||||
return ASN_PARSE_E;
|
||||
|
||||
|
||||
XMEMMOVE(input, input + inOutIdx, length);
|
||||
|
||||
return length;
|
||||
|
@ -89,28 +89,6 @@ int wc_RsaEncryptSize(RsaKey* key)
|
||||
}
|
||||
|
||||
|
||||
int wc_RsaPrivateKeyDecode(const byte* input, word32* inOutIdx, RsaKey* key,
|
||||
word32 sz)
|
||||
{
|
||||
return RsaPrivateKeyDecode(input, inOutIdx, key, sz);
|
||||
}
|
||||
|
||||
|
||||
int wc_RsaPublicKeyDecode(const byte* input, word32* inOutIdx, RsaKey* key,
|
||||
word32 sz)
|
||||
{
|
||||
return RsaPublicKeyDecode(input, inOutIdx, key, sz);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int wc_RsaPublicKeyDecodeRaw(const byte* n, word32 nSz, const byte* e,
|
||||
word32 eSz, RsaKey* key)
|
||||
{
|
||||
return RsaPublicKeyDecodeRaw(n, nSz, e, eSz, key);
|
||||
}
|
||||
|
||||
|
||||
int wc_RsaFlattenPublicKey(RsaKey* key, byte* a, word32* aSz, byte* b,
|
||||
word32* bSz)
|
||||
{
|
||||
|
@ -43,7 +43,47 @@
|
||||
#include <wolfcrypt/src/misc.c>
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_FIPS
|
||||
/* fips wrapper calls, user can call direct */
|
||||
#ifdef HAVE_FIPS
|
||||
int wc_InitSha(Sha* sha)
|
||||
{
|
||||
return InitSha_fips(sha);
|
||||
}
|
||||
|
||||
|
||||
int wc_ShaUpdate(Sha* sha, const byte* data, word32 len)
|
||||
{
|
||||
return ShaUpdate_fips(sha, data, len);
|
||||
}
|
||||
|
||||
|
||||
int wc_ShaFinal(Sha* sha, byte* out)
|
||||
{
|
||||
return ShaFinal_fips(sha,out);
|
||||
}
|
||||
|
||||
int wc_ShaHash(const byte* data, word32 sz, byte* out)
|
||||
{
|
||||
return ShaHash(data, sz, out);
|
||||
}
|
||||
|
||||
|
||||
int wc_InitSha_fips(Sha* sha)
|
||||
{
|
||||
return InitSha_fips(sha);
|
||||
}
|
||||
|
||||
int wc_ShaUpdate_fips(Sha* sha, const byte* data, word32 sz)
|
||||
{
|
||||
return ShaUpdate_fips(sha, data, sz);
|
||||
}
|
||||
|
||||
int wc_ShaFinal_fips(Sha* sha, byte* out)
|
||||
{
|
||||
return ShaFinal_fips(sha, out);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#ifdef FREESCALE_MMCAU
|
||||
#include "cau_api.h"
|
||||
@ -370,20 +410,20 @@ int wc_ShaFinal(Sha* sha, byte* hash)
|
||||
/* ! length ordering dependent on digest endian type ! */
|
||||
XMEMCPY(&local[SHA_PAD_SIZE], &sha->hiLen, sizeof(word32));
|
||||
XMEMCPY(&local[SHA_PAD_SIZE + sizeof(word32)], &sha->loLen, sizeof(word32));
|
||||
|
||||
|
||||
#ifdef FREESCALE_MMCAU
|
||||
/* Kinetis requires only these bytes reversed */
|
||||
ByteReverseWords(&sha->buffer[SHA_PAD_SIZE/sizeof(word32)],
|
||||
&sha->buffer[SHA_PAD_SIZE/sizeof(word32)],
|
||||
2 * sizeof(word32));
|
||||
#endif
|
||||
|
||||
|
||||
XTRANSFORM(sha, local);
|
||||
#ifdef LITTLE_ENDIAN_ORDER
|
||||
ByteReverseWords(sha->digest, sha->digest, SHA_DIGEST_SIZE);
|
||||
#endif
|
||||
XMEMCPY(hash, sha->digest, SHA_DIGEST_SIZE);
|
||||
|
||||
|
||||
return wc_InitSha(sha); /* reset state */
|
||||
}
|
||||
|
||||
@ -420,26 +460,6 @@ int wc_ShaHash(const byte* data, word32 len, byte* hash)
|
||||
return ret;
|
||||
|
||||
}
|
||||
#endif /* not defined HAVE_FIPS */
|
||||
|
||||
/* fips wrapper calls, user can call direct */
|
||||
#ifdef HAVE_FIPS
|
||||
int wc_InitSha_fips(Sha* sha)
|
||||
{
|
||||
return InitSha_fips(sha);
|
||||
}
|
||||
|
||||
|
||||
int wc_ShaUpdate_fips(Sha* sha, const byte* data, word32 len)
|
||||
{
|
||||
return ShaUpdate_fips(sha, data, len);
|
||||
}
|
||||
|
||||
|
||||
int wc_ShaFinal_fips(Sha* sha, byte* out)
|
||||
{
|
||||
return ShaFinal_fips(sha,out);
|
||||
}
|
||||
#endif /* HAVE_FIPS */
|
||||
#endif /* NO_SHA */
|
||||
|
||||
|
@ -34,9 +34,6 @@
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
/* if using fips than the tfm.c from ctaocrypt is used @wc_fips */
|
||||
#ifndef HAVE_FIPS
|
||||
|
||||
/* in case user set USE_FAST_MATH there */
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
|
||||
@ -2540,5 +2537,3 @@ int mp_div_2d(fp_int* a, int b, fp_int* c, fp_int* d)
|
||||
|
||||
#endif /* USE_FAST_MATH */
|
||||
|
||||
#endif /* HAVE_FIPS */
|
||||
|
||||
|
@ -26,6 +26,12 @@
|
||||
|
||||
#include <wolfssl/wolfcrypt/types.h>
|
||||
#include <wolfssl/wolfcrypt/rsa.h>
|
||||
|
||||
/* fips declare of RsaPrivateKeyDecode @wc_fips */
|
||||
#ifdef HAVE_FIPS
|
||||
#include <cyassl/ctaocrypt/rsa.h>
|
||||
#endif
|
||||
|
||||
#include <wolfssl/wolfcrypt/dh.h>
|
||||
#include <wolfssl/wolfcrypt/dsa.h>
|
||||
#include <wolfssl/wolfcrypt/sha.h>
|
||||
|
@ -28,10 +28,6 @@
|
||||
#ifndef WOLF_CRYPT_INTEGER_H
|
||||
#define WOLF_CRYPT_INTEGER_H
|
||||
|
||||
/* for fips compatibility @wc_fips */
|
||||
#ifdef HAVE_FIPS
|
||||
#include <cyassl/ctaocrypt/integer.h>
|
||||
#else
|
||||
/* may optionally use fast math instead, not yet supported on all platforms and
|
||||
may not be faster on all
|
||||
*/
|
||||
@ -324,6 +320,5 @@ int mp_mod_d(mp_int* a, mp_digit b, mp_digit* c);
|
||||
|
||||
#endif /* USE_FAST_MATH */
|
||||
|
||||
#endif /* HAVE_FIPS */
|
||||
#endif /* WOLF_CRYPT_INTEGER_H */
|
||||
|
||||
|
@ -25,55 +25,46 @@
|
||||
#ifndef WOLFSSL_LOGGING_H
|
||||
#define WOLFSSL_LOGGING_H
|
||||
|
||||
/* for reverse compatibility @wc_fips */
|
||||
#ifndef HAVE_FIPS
|
||||
#include <wolfssl/wolfcrypt/types.h>
|
||||
#include <wolfssl/wolfcrypt/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
enum CYA_Log_Levels {
|
||||
ERROR_LOG = 0,
|
||||
INFO_LOG,
|
||||
ENTER_LOG,
|
||||
LEAVE_LOG,
|
||||
OTHER_LOG
|
||||
};
|
||||
enum CYA_Log_Levels {
|
||||
ERROR_LOG = 0,
|
||||
INFO_LOG,
|
||||
ENTER_LOG,
|
||||
LEAVE_LOG,
|
||||
OTHER_LOG
|
||||
};
|
||||
|
||||
typedef void (*wolfSSL_Logging_cb)(const int logLevel,
|
||||
const char *const logMessage);
|
||||
typedef void (*wolfSSL_Logging_cb)(const int logLevel,
|
||||
const char *const logMessage);
|
||||
|
||||
WOLFSSL_API int wolfSSL_SetLoggingCb(wolfSSL_Logging_cb log_function);
|
||||
WOLFSSL_API int wolfSSL_SetLoggingCb(wolfSSL_Logging_cb log_function);
|
||||
|
||||
#ifdef DEBUG_WOLFSSL
|
||||
#ifdef DEBUG_WOLFSSL
|
||||
|
||||
void WOLFSSL_ENTER(const char* msg);
|
||||
void WOLFSSL_LEAVE(const char* msg, int ret);
|
||||
void WOLFSSL_ENTER(const char* msg);
|
||||
void WOLFSSL_LEAVE(const char* msg, int ret);
|
||||
|
||||
void WOLFSSL_ERROR(int);
|
||||
void WOLFSSL_MSG(const char* msg);
|
||||
void WOLFSSL_ERROR(int);
|
||||
void WOLFSSL_MSG(const char* msg);
|
||||
|
||||
#else /* DEBUG_WOLFSSL */
|
||||
#else /* DEBUG_WOLFSSL */
|
||||
|
||||
#define WOLFSSL_ENTER(m)
|
||||
#define WOLFSSL_LEAVE(m, r)
|
||||
#define WOLFSSL_ENTER(m)
|
||||
#define WOLFSSL_LEAVE(m, r)
|
||||
|
||||
#define WOLFSSL_ERROR(e)
|
||||
#define WOLFSSL_MSG(m)
|
||||
#define WOLFSSL_ERROR(e)
|
||||
#define WOLFSSL_MSG(m)
|
||||
|
||||
#endif /* DEBUG_WOLFSSL */
|
||||
#endif /* DEBUG_WOLFSSL */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#else /* if using fips use old logging file */
|
||||
#include <cyassl/ctaocrypt/logging.h>
|
||||
#define WOLFSSL_LEAVE CYASSL_LEAVE
|
||||
#define WOLFSSL_ERROR CYASSL_ERROR
|
||||
#define WOLFSSL_ENTER CYASSL_ENTER
|
||||
#define WOLFSSL_MSG CYASSL_MSG
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* WOLFSSL_LOGGING_H */
|
||||
|
||||
|
@ -26,48 +26,22 @@
|
||||
#define WOLFSSL_MEMORY_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <wolfssl/wolfcrypt/types.h>
|
||||
|
||||
/* compatibility and fips @wc_fips */
|
||||
#ifndef HAVE_FIPS
|
||||
#include <wolfssl/wolfcrypt/types.h>
|
||||
#define CyaSSL_Malloc_cb wolfSSL_Malloc_cb
|
||||
#define CyaSSL_Free_cb wolfSSL_Free_cb
|
||||
#define CyaSSL_Realloc_cb wolfSSL_Realloc_cb
|
||||
#define CyaSSL_SetAllocators wolfSSL_SetAllocators
|
||||
|
||||
/* Public in case user app wants to use XMALLOC/XFREE */
|
||||
#define CyaSSL_Malloc wolfSSL_Malloc
|
||||
#define CyaSSL_Free wolfSSL_Free
|
||||
#define CyaSSL_Realloc wolfSSL_Realloc
|
||||
typedef void *(*wolfSSL_Malloc_cb)(size_t size);
|
||||
typedef void (*wolfSSL_Free_cb)(void *ptr);
|
||||
typedef void *(*wolfSSL_Realloc_cb)(void *ptr, size_t size);
|
||||
|
||||
|
||||
typedef void *(*wolfSSL_Malloc_cb)(size_t size);
|
||||
typedef void (*wolfSSL_Free_cb)(void *ptr);
|
||||
typedef void *(*wolfSSL_Realloc_cb)(void *ptr, size_t size);
|
||||
|
||||
|
||||
/* Public set function */
|
||||
WOLFSSL_API int wolfSSL_SetAllocators(wolfSSL_Malloc_cb malloc_function,
|
||||
wolfSSL_Free_cb free_function,
|
||||
wolfSSL_Realloc_cb realloc_function);
|
||||
|
||||
/* Public in case user app wants to use XMALLOC/XFREE */
|
||||
WOLFSSL_API void* wolfSSL_Malloc(size_t size);
|
||||
WOLFSSL_API void wolfSSL_Free(void *ptr);
|
||||
WOLFSSL_API void* wolfSSL_Realloc(void *ptr, size_t size);
|
||||
#else
|
||||
#include <cyassl/ctaocrypt/memory.h>
|
||||
/* when using fips map wolfSSL to CyaSSL*/
|
||||
#define wolfSSL_Malloc_cb CyaSSL_Malloc_cb
|
||||
#define wolfSSL_Free_cb CyaSSL_Free_cb
|
||||
#define wolfSSL_Realloc_cb CyaSSL_Realloc_cb
|
||||
#define wolfSSL_SetAllocators CyaSSL_SetAllocators
|
||||
|
||||
/* Public in case user app wants to use XMALLOC/XFREE */
|
||||
#define wolfSSL_Malloc CyaSSL_Malloc
|
||||
#define wolfSSL_Free CyaSSL_Free
|
||||
#define wolfSSL_Realloc CyaSSL_Realloc
|
||||
#endif
|
||||
/* Public set function */
|
||||
WOLFSSL_API int wolfSSL_SetAllocators(wolfSSL_Malloc_cb malloc_function,
|
||||
wolfSSL_Free_cb free_function,
|
||||
wolfSSL_Realloc_cb realloc_function);
|
||||
|
||||
/* Public in case user app wants to use XMALLOC/XFREE */
|
||||
WOLFSSL_API void* wolfSSL_Malloc(size_t size);
|
||||
WOLFSSL_API void wolfSSL_Free(void *ptr);
|
||||
WOLFSSL_API void* wolfSSL_Realloc(void *ptr, size_t size);
|
||||
|
||||
#endif /* WOLFSSL_MEMORY_H */
|
||||
|
||||
|
@ -90,12 +90,14 @@ WOLFSSL_API int wc_RsaSSL_Verify(const byte* in, word32 inLen, byte* out,
|
||||
word32 outLen, RsaKey* key);
|
||||
WOLFSSL_API int wc_RsaEncryptSize(RsaKey* key);
|
||||
|
||||
#ifndef HAVE_FIPS /* to avoid asn duplicate symbols @wc_fips */
|
||||
WOLFSSL_API int wc_RsaPrivateKeyDecode(const byte* input, word32* inOutIdx,
|
||||
RsaKey*, word32);
|
||||
WOLFSSL_API int wc_RsaPublicKeyDecode(const byte* input, word32* inOutIdx,
|
||||
RsaKey*, word32);
|
||||
WOLFSSL_API int wc_RsaPublicKeyDecodeRaw(const byte* n, word32 nSz,
|
||||
const byte* e, word32 eSz, RsaKey* key);
|
||||
#endif /* HAVE_FIPS*/
|
||||
WOLFSSL_API int wc_RsaFlattenPublicKey(RsaKey*, byte*, word32*, byte*,
|
||||
word32*);
|
||||
|
||||
|
@ -29,7 +29,11 @@
|
||||
/* since using old code turn on old macros @wc_fips */
|
||||
/* for fips */
|
||||
#ifdef HAVE_FIPS
|
||||
#include <cyassl/ctaocrypt/sha512.h>
|
||||
#define CYASSL_SHA512
|
||||
#if defined(WOLFSSL_SHA384)
|
||||
#define CYASSL_SHA384
|
||||
#endif
|
||||
#include <cyassl/ctaocrypt/sha512.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -71,7 +75,7 @@ enum {
|
||||
SHA384 = 5, /* hash type unique */
|
||||
SHA384_BLOCK_SIZE = 128,
|
||||
SHA384_DIGEST_SIZE = 48,
|
||||
SHA384_PAD_SIZE = 112
|
||||
SHA384_PAD_SIZE = 112
|
||||
};
|
||||
|
||||
|
||||
@ -98,9 +102,9 @@ WOLFSSL_API int wc_Sha384Hash(const byte*, word32, byte*);
|
||||
WOLFSSL_API int wc_Sha512Final_fips(Sha512*, byte*);
|
||||
#ifndef FIPS_NO_WRAPPERS
|
||||
/* if not impl or fips.c impl wrapper force fips calls if fips build */
|
||||
#define InitSha512 InitSha512_fips
|
||||
#define Sha512Update Sha512Update_fips
|
||||
#define Sha512Final Sha512Final_fips
|
||||
#define wc_InitSha512 wc_InitSha512_fips
|
||||
#define wc_Sha512Update wc_Sha512Update_fips
|
||||
#define wc_Sha512Final wc_Sha512Final_fips
|
||||
#endif /* FIPS_NO_WRAPPERS */
|
||||
|
||||
/* fips wrapper calls, user can call direct */
|
||||
@ -109,9 +113,9 @@ WOLFSSL_API int wc_Sha384Hash(const byte*, word32, byte*);
|
||||
WOLFSSL_API int wc_Sha384Final_fips(Sha384*, byte*);
|
||||
#ifndef FIPS_NO_WRAPPERS
|
||||
/* if not impl or fips.c impl wrapper force fips calls if fips build */
|
||||
#define InitSha384 InitSha384_fips
|
||||
#define Sha384Update Sha384Update_fips
|
||||
#define Sha384Final Sha384Final_fips
|
||||
#define wc_InitSha384 wc_InitSha384_fips
|
||||
#define wc_Sha384Update wc_Sha384Update_fips
|
||||
#define wc_Sha384Final wc_Sha384Final_fips
|
||||
#endif /* FIPS_NO_WRAPPERS */
|
||||
|
||||
#endif /* HAVE_FIPS */
|
||||
|
@ -35,11 +35,6 @@
|
||||
#ifndef WOLF_CRYPT_TFM_H
|
||||
#define WOLF_CRYPT_TFM_H
|
||||
|
||||
/* for fips compatibility @wc_fips */
|
||||
#ifdef HAVE_FIPS
|
||||
#include <cyassl/ctaocrypt/tfm.h>
|
||||
#else
|
||||
|
||||
#include <wolfssl/wolfcrypt/types.h>
|
||||
#ifndef CHAR_BIT
|
||||
#include <limits.h>
|
||||
@ -624,7 +619,7 @@ void fp_sqr_comba64(fp_int *a, fp_int *b);
|
||||
|
||||
|
||||
/**
|
||||
* Used by CyaSSL
|
||||
* Used by wolfSSL
|
||||
*/
|
||||
|
||||
/* Types */
|
||||
@ -708,5 +703,5 @@ WOLFSSL_API word32 CheckRunTimeFastMath(void);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* HAVE_FIPS */
|
||||
#endif /* WOLF_CRYPT_TFM_H */
|
||||
|
||||
|
@ -28,37 +28,6 @@
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
#include <wolfssl/wolfcrypt/wc_port.h>
|
||||
|
||||
/* for fips compatiblity @wc_fips */
|
||||
#ifdef HAVE_FIPS
|
||||
#include <cyassl/ctaocrypt/types.h>
|
||||
/* set old macros since this is often called for visibility also */
|
||||
#ifndef WOLFSSL_API
|
||||
#define WOLFSSL_API CYASSL_API
|
||||
#endif
|
||||
#ifndef WOLFSSL_LOCAL
|
||||
#define WOLFSSL_LOCAL CYASSL_LOCAL
|
||||
#endif
|
||||
#define WOLFSSL_MAX_ERROR_SZ CYASSL_MAX_ERROR_SZ
|
||||
|
||||
#define WOLFSSL_WORD_SIZE CYASSL_WORD_SIZE
|
||||
#define WOLFSSL_BIT_SIZE CYASSL_BIT_SIZE
|
||||
#define WOLFSSL_MAX_16BIT CYASSL_MAX_16BIT
|
||||
#define WOLFSSL_MAX_ERROR_SZ CYASSL_MAX_ERROR_SZ
|
||||
#define wolfssl_word cyassl_word
|
||||
/* memory macros */
|
||||
/* when using fips map wolfSSL to CyaSSL*/
|
||||
#define wolfSSL_Malloc_cb CyaSSL_Malloc_cb
|
||||
#define wolfSSL_Free_cb CyaSSL_Free_cb
|
||||
#define wolfSSL_Realloc_cb CyaSSL_Realloc_cb
|
||||
#define wolfSSL_SetAllocators CyaSSL_SetAllocators
|
||||
|
||||
/* Public in case user app wants to use XMALLOC/XFREE */
|
||||
#define wolfSSL_Malloc CyaSSL_Malloc
|
||||
#define wolfSSL_Free CyaSSL_Free
|
||||
#define wolfSSL_Realloc CyaSSL_Realloc
|
||||
|
||||
|
||||
#else
|
||||
/* set old macros since this is often called for visibility also */
|
||||
#ifndef CYASSL_API
|
||||
#define CYASSL_API WOLFSSL_API
|
||||
@ -66,21 +35,21 @@
|
||||
#ifndef CYASSL_LOCAL
|
||||
#define CYASSL_LOCAL WOLFSSL_LOCAL
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
#if defined(WORDS_BIGENDIAN)
|
||||
#define BIG_ENDIAN_ORDER
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef BIG_ENDIAN_ORDER
|
||||
#define LITTLE_ENDIAN_ORDER
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef WOLFSSL_TYPES
|
||||
#ifndef byte
|
||||
typedef unsigned char byte;
|
||||
@ -88,8 +57,8 @@
|
||||
typedef unsigned short word16;
|
||||
typedef unsigned int word32;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
/* try to set SIZEOF_LONG or LONG_LONG if user didn't */
|
||||
#if !defined(_MSC_VER) && !defined(__BCPLUSPLUS__)
|
||||
#if !defined(SIZEOF_LONG_LONG) && !defined(SIZEOF_LONG)
|
||||
@ -103,8 +72,8 @@
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
#if defined(_MSC_VER) || defined(__BCPLUSPLUS__)
|
||||
#define WORD64_AVAILABLE
|
||||
#define W64LIT(x) x##ui64
|
||||
@ -125,8 +94,8 @@
|
||||
#define MP_16BIT /* for mp_int, mp_word needs to be twice as big as
|
||||
mp_digit, no 64 bit type so make mp_digit 16 bit */
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
/* These platforms have 64-bit CPU registers. */
|
||||
#if (defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) || \
|
||||
defined(__mips64) || defined(__x86_64__) || defined(_M_X64))
|
||||
@ -137,16 +106,16 @@
|
||||
#define WOLFCRYPT_SLOW_WORD64
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
enum {
|
||||
WOLFSSL_WORD_SIZE = sizeof(wolfssl_word),
|
||||
WOLFSSL_BIT_SIZE = 8,
|
||||
WOLFSSL_WORD_BITS = WOLFSSL_WORD_SIZE * WOLFSSL_BIT_SIZE
|
||||
};
|
||||
|
||||
|
||||
#define WOLFSSL_MAX_16BIT 0xffffU
|
||||
|
||||
|
||||
/* use inlining if compiler allows */
|
||||
#ifndef INLINE
|
||||
#ifndef NO_INLINE
|
||||
@ -165,8 +134,8 @@
|
||||
#define INLINE
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
/* set up rotate style */
|
||||
#if defined(_MSC_VER) || defined(__BCPLUSPLUS__)
|
||||
#define INTEL_INTRINSICS
|
||||
@ -179,8 +148,8 @@
|
||||
instructions */
|
||||
#define FAST_ROTATE
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
/* set up thread local storage if available */
|
||||
#ifdef HAVE_THREAD_LS
|
||||
#if defined(_MSC_VER)
|
||||
@ -191,15 +160,15 @@
|
||||
#else
|
||||
#define THREAD_LS_T
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
/* Micrium will use Visual Studio for compilation but not the Win32 API */
|
||||
#if defined(_WIN32) && !defined(MICRIUM) && !defined(FREERTOS) \
|
||||
&& !defined(EBSNET)
|
||||
#define USE_WINDOWS_API
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
/* idea to add global alloc override by Moisés Guimarães */
|
||||
/* default to libc stuff */
|
||||
/* XREALLOC is used once in normal math lib, not in fast math lib */
|
||||
@ -225,16 +194,16 @@
|
||||
#define XFREE(p, h, t) {void* xp = (p); if((xp)) wolfSSL_Free((xp));}
|
||||
#define XREALLOC(p, n, h, t) wolfSSL_Realloc((p), (n))
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef STRING_USER
|
||||
#include <string.h>
|
||||
char* mystrnstr(const char* s1, const char* s2, unsigned int n);
|
||||
|
||||
|
||||
#define XMEMCPY(d,s,l) memcpy((d),(s),(l))
|
||||
#define XMEMSET(b,c,l) memset((b),(c),(l))
|
||||
#define XMEMCMP(s1,s2,n) memcmp((s1),(s2),(n))
|
||||
#define XMEMMOVE(d,s,l) memmove((d),(s),(l))
|
||||
|
||||
|
||||
#define XSTRLEN(s1) strlen((s1))
|
||||
#define XSTRNCPY(s1,s2,n) strncpy((s1),(s2),(n))
|
||||
/* strstr, strncmp, and strncat only used by wolfSSL proper, not required for
|
||||
@ -251,7 +220,7 @@
|
||||
#define XSNPRINTF _snprintf
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef CTYPE_USER
|
||||
#include <ctype.h>
|
||||
#if defined(HAVE_ECC) || defined(HAVE_OCSP)
|
||||
@ -266,8 +235,8 @@
|
||||
#endif
|
||||
#define XTOLOWER(c) tolower((c))
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
/* memory allocation types for user hints */
|
||||
enum {
|
||||
DYNAMIC_TYPE_CA = 1,
|
||||
@ -316,19 +285,19 @@
|
||||
DYNAMIC_TYPE_OCSP = 44,
|
||||
DYNAMIC_TYPE_SIGNATURE = 45
|
||||
};
|
||||
|
||||
|
||||
/* max error buffer string size */
|
||||
enum {
|
||||
WOLFSSL_MAX_ERROR_SZ = 80
|
||||
};
|
||||
|
||||
|
||||
/* stack protection */
|
||||
enum {
|
||||
MIN_STACK_BUFFER = 8
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* settings detection for compile vs runtime math incombatibilities */
|
||||
enum {
|
||||
#if !defined(USE_FAST_MATH) && !defined(SIZEOF_LONG) && !defined(SIZEOF_LONG_LONG)
|
||||
@ -351,19 +320,18 @@
|
||||
#error "bad math long / long long settings"
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
WOLFSSL_API word32 CheckRunTimeSettings(void);
|
||||
|
||||
|
||||
/* If user uses RSA, DH, DSA, or ECC math lib directly then fast math and long
|
||||
types need to match at compile time and run time, CheckCtcSettings will
|
||||
return 1 if a match otherwise 0 */
|
||||
#define CheckCtcSettings() (CTC_SETTINGS == CheckRunTimeSettings())
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* HAVE_FIPS */
|
||||
|
||||
#endif /* WOLF_CRYPT_TYPES_H */
|
||||
|
@ -24,13 +24,6 @@
|
||||
#ifndef WOLF_CRYPT_VISIBILITY_H
|
||||
#define WOLF_CRYPT_VISIBILITY_H
|
||||
|
||||
/* fips compatibility @wc_fips */
|
||||
#ifdef HAVE_FIPS
|
||||
#include <cyassl/ctaocrypt/visibility.h>
|
||||
#define WOLFSSL_API CYASSL_API
|
||||
#define WOLFSSL_LOCAL CYASSL_LOCAL
|
||||
#else
|
||||
|
||||
/* WOLFSSL_API is used for the public API symbols.
|
||||
It either imports or exports (or does nothing for static builds)
|
||||
|
||||
@ -70,6 +63,5 @@
|
||||
#endif /* BUILDING_WOLFSSL */
|
||||
|
||||
|
||||
#endif /* HAVE_FIPS */
|
||||
#endif /* WOLF_CRYPT_VISIBILITY_H */
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* port.h
|
||||
/* wc_port.h
|
||||
*
|
||||
* Copyright (C) 2006-2014 wolfSSL Inc.
|
||||
*
|
||||
@ -23,12 +23,6 @@
|
||||
#ifndef WOLF_CRYPT_PORT_H
|
||||
#define WOLF_CRYPT_PORT_H
|
||||
|
||||
/* fips compatibility @wc_fips */
|
||||
#ifdef HAVE_FIPS
|
||||
#include <cyassl/ctaocrypt/wc_port.h>
|
||||
#define wolfSSL_Mutex CyaSSL_Mutex
|
||||
#else
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@ -201,6 +195,5 @@ WOLFSSL_LOCAL int UnLockMutex(wolfSSL_Mutex*);
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* HAVE_FIPS */
|
||||
#endif /* WOLF_CRYPT_PORT_H */
|
||||
|
||||
|
Reference in New Issue
Block a user