Latest update.
This commit is contained in:
+2
-3
@@ -131,9 +131,8 @@ const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory)
|
||||
return 0;
|
||||
}
|
||||
|
||||
strncpy((*ctx)->entry_name, direntry->d_name,
|
||||
sizeof((*ctx)->entry_name) - 1);
|
||||
(*ctx)->entry_name[sizeof((*ctx)->entry_name) - 1] = '\0';
|
||||
OPENSSL_strlcpy((*ctx)->entry_name, direntry->d_name,
|
||||
sizeof((*ctx)->entry_name));
|
||||
#ifdef __VMS
|
||||
if ((*ctx)->expect_file_generations) {
|
||||
char *p = (*ctx)->entry_name + strlen((*ctx)->entry_name);
|
||||
|
||||
@@ -7,6 +7,13 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* AES low level APIs are deprecated for public use, but still ok for internal
|
||||
* use where we're using them to implement the higher level EVP interface, as is
|
||||
* the case here.
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include <openssl/aes.h>
|
||||
#include <openssl/modes.h>
|
||||
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* AES_encrypt is deprecated - but we need to use it to implement these other
|
||||
* deprecated APIs.
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include <openssl/aes.h>
|
||||
#include <openssl/modes.h>
|
||||
|
||||
|
||||
@@ -36,6 +36,13 @@
|
||||
/* Note: rewritten a little bit to provide error control and an OpenSSL-
|
||||
compatible API */
|
||||
|
||||
/*
|
||||
* AES low level APIs are deprecated for public use, but still ok for internal
|
||||
* use where we're using them to implement the higher level EVP interface, as is
|
||||
* the case here.
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -9,6 +9,12 @@
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
/*
|
||||
* AES_encrypt/AES_decrypt are deprecated - but we need to use them to implement
|
||||
* AES_ecb_encrypt
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include <openssl/aes.h>
|
||||
#include "aes_local.h"
|
||||
|
||||
|
||||
@@ -7,9 +7,15 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* AES_encrypt/AES_decrypt are deprecated - but we need to use them to implement
|
||||
* these functions
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include "internal/cryptlib.h"
|
||||
|
||||
#if OPENSSL_API_3
|
||||
#ifdef OPENSSL_NO_DEPRECATED_3_0
|
||||
NON_EMPTY_TRANSLATION_UNIT
|
||||
#else
|
||||
|
||||
|
||||
@@ -11,11 +11,13 @@
|
||||
#include <openssl/aes.h>
|
||||
#include "aes_local.h"
|
||||
|
||||
#ifndef OPENSSL_NO_DEPRECATED_3_0
|
||||
const char *AES_options(void)
|
||||
{
|
||||
#ifdef FULL_UNROLL
|
||||
# ifdef FULL_UNROLL
|
||||
return "aes(full)";
|
||||
#else
|
||||
# else
|
||||
return "aes(partial)";
|
||||
#endif
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
@@ -7,6 +7,12 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* AES_encrypt is deprecated - but we need to use it to implement
|
||||
* AES_ofb128_encrypt
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include <openssl/aes.h>
|
||||
#include <openssl/modes.h>
|
||||
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* AES_encrypt/AES_decrypt are deprecated - but we need to use them to implement
|
||||
* these functions
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include "internal/cryptlib.h"
|
||||
#include <openssl/aes.h>
|
||||
#include <openssl/modes.h>
|
||||
|
||||
@@ -328,6 +328,7 @@ $code.=<<___;
|
||||
.type _x86_64_AES_encrypt,\@abi-omnipotent
|
||||
.align 16
|
||||
_x86_64_AES_encrypt:
|
||||
.cfi_startproc
|
||||
xor 0($key),$s0 # xor with key
|
||||
xor 4($key),$s1
|
||||
xor 8($key),$s2
|
||||
@@ -363,6 +364,7 @@ ___
|
||||
}
|
||||
$code.=<<___;
|
||||
.byte 0xf3,0xc3 # rep ret
|
||||
.cfi_endproc
|
||||
.size _x86_64_AES_encrypt,.-_x86_64_AES_encrypt
|
||||
___
|
||||
|
||||
@@ -912,6 +914,7 @@ $code.=<<___;
|
||||
.type _x86_64_AES_decrypt,\@abi-omnipotent
|
||||
.align 16
|
||||
_x86_64_AES_decrypt:
|
||||
.cfi_startproc
|
||||
xor 0($key),$s0 # xor with key
|
||||
xor 4($key),$s1
|
||||
xor 8($key),$s2
|
||||
@@ -954,6 +957,7 @@ ___
|
||||
}
|
||||
$code.=<<___;
|
||||
.byte 0xf3,0xc3 # rep ret
|
||||
.cfi_endproc
|
||||
.size _x86_64_AES_decrypt,.-_x86_64_AES_decrypt
|
||||
___
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ if (!$avx && $win64 && ($flavour =~ /masm/ || $ENV{ASM} =~ /ml64/) &&
|
||||
$avx = ($1>=10) + ($1>=11);
|
||||
}
|
||||
|
||||
if (!$avx && `$ENV{CC} -v 2>&1` =~ /((?:^clang|LLVM) version|.*based on LLVM) ([3-9]\.[0-9]+)/) {
|
||||
if (!$avx && `$ENV{CC} -v 2>&1` =~ /((?:^clang|LLVM) version|.*based on LLVM) ([0-9]+\.[0-9]+)/) {
|
||||
$avx = ($2>=3.0) + ($2>3.0);
|
||||
}
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ $avx=1 if (!$avx && $win64 && ($flavour =~ /nasm/ || $ENV{ASM} =~ /nasm/) &&
|
||||
$avx=1 if (!$avx && $win64 && ($flavour =~ /masm/ || $ENV{ASM} =~ /ml64/) &&
|
||||
`ml64 2>&1` =~ /Version ([0-9]+)\./ &&
|
||||
$1>=10);
|
||||
$avx=1 if (!$avx && `$ENV{CC} -v 2>&1` =~ /((?:^clang|LLVM) version|.*based on LLVM) ([3-9]\.[0-9]+)/ && $2>=3.0);
|
||||
$avx=1 if (!$avx && `$ENV{CC} -v 2>&1` =~ /((?:^clang|LLVM) version|.*based on LLVM) ([0-9]+\.[0-9]+)/ && $2>=3.0);
|
||||
|
||||
$shaext=1; ### set to zero if compiling for 1.0.1
|
||||
|
||||
@@ -135,6 +135,7 @@ $code.=<<___;
|
||||
.type aesni_cbc_sha1_enc,\@abi-omnipotent
|
||||
.align 32
|
||||
aesni_cbc_sha1_enc:
|
||||
.cfi_startproc
|
||||
# caller should check for SSSE3 and AES-NI bits
|
||||
mov OPENSSL_ia32cap_P+0(%rip),%r10d
|
||||
mov OPENSSL_ia32cap_P+4(%rip),%r11
|
||||
@@ -153,6 +154,7 @@ ___
|
||||
$code.=<<___;
|
||||
jmp aesni_cbc_sha1_enc_ssse3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aesni_cbc_sha1_enc,.-aesni_cbc_sha1_enc
|
||||
___
|
||||
|
||||
@@ -842,6 +844,7 @@ $code.=<<___;
|
||||
.type aesni256_cbc_sha1_dec,\@abi-omnipotent
|
||||
.align 32
|
||||
aesni256_cbc_sha1_dec:
|
||||
.cfi_startproc
|
||||
# caller should check for SSSE3 and AES-NI bits
|
||||
mov OPENSSL_ia32cap_P+0(%rip),%r10d
|
||||
mov OPENSSL_ia32cap_P+4(%rip),%r11d
|
||||
@@ -856,6 +859,7 @@ ___
|
||||
$code.=<<___;
|
||||
jmp aesni256_cbc_sha1_dec_ssse3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aesni256_cbc_sha1_dec,.-aesni256_cbc_sha1_dec
|
||||
|
||||
.type aesni256_cbc_sha1_dec_ssse3,\@function,6
|
||||
@@ -1762,6 +1766,7 @@ $code.=<<___;
|
||||
.type aesni_cbc_sha1_enc_shaext,\@function,6
|
||||
.align 32
|
||||
aesni_cbc_sha1_enc_shaext:
|
||||
.cfi_startproc
|
||||
mov `($win64?56:8)`(%rsp),$inp # load 7th argument
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
@@ -1913,6 +1918,7 @@ $code.=<<___ if ($win64);
|
||||
___
|
||||
$code.=<<___;
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aesni_cbc_sha1_enc_shaext,.-aesni_cbc_sha1_enc_shaext
|
||||
___
|
||||
}}}
|
||||
|
||||
@@ -71,7 +71,7 @@ if (!$avx && $win64 && ($flavour =~ /masm/ || $ENV{ASM} =~ /ml64/) &&
|
||||
$avx = ($1>=10) + ($1>=12);
|
||||
}
|
||||
|
||||
if (!$avx && `$ENV{CC} -v 2>&1` =~ /((?:^clang|LLVM) version|.*based on LLVM) ([3-9]\.[0-9]+)/) {
|
||||
if (!$avx && `$ENV{CC} -v 2>&1` =~ /((?:^clang|LLVM) version|.*based on LLVM) ([0-9]+\.[0-9]+)/) {
|
||||
$avx = ($2>=3.0) + ($2>3.0);
|
||||
}
|
||||
|
||||
@@ -125,6 +125,7 @@ $code=<<___;
|
||||
.type $func,\@abi-omnipotent
|
||||
.align 16
|
||||
$func:
|
||||
.cfi_startproc
|
||||
___
|
||||
if ($avx) {
|
||||
$code.=<<___;
|
||||
@@ -164,6 +165,7 @@ $code.=<<___;
|
||||
ud2
|
||||
.Lprobe:
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size $func,.-$func
|
||||
|
||||
.align 64
|
||||
@@ -1086,7 +1088,23 @@ $code.=<<___;
|
||||
vmovdqa $t0,0x00(%rsp)
|
||||
xor $a1,$a1
|
||||
vmovdqa $t1,0x20(%rsp)
|
||||
___
|
||||
$code.=<<___ if (!$win64);
|
||||
# temporarily use %rsi as frame pointer
|
||||
mov $_rsp,%rsi
|
||||
.cfi_def_cfa %rsi,8
|
||||
___
|
||||
$code.=<<___;
|
||||
lea -$PUSH8(%rsp),%rsp
|
||||
___
|
||||
$code.=<<___ if (!$win64);
|
||||
# the frame info is at $_rsp, but the stack is moving...
|
||||
# so a second frame pointer is saved at -8(%rsp)
|
||||
# that is in the red zone
|
||||
mov %rsi,-8(%rsp)
|
||||
.cfi_cfa_expression %rsp-8,deref,+8
|
||||
___
|
||||
$code.=<<___;
|
||||
mov $B,$a3
|
||||
vmovdqa $t2,0x00(%rsp)
|
||||
xor $C,$a3 # magic
|
||||
@@ -1108,7 +1126,17 @@ my @X = @_;
|
||||
my @insns = (&$body,&$body,&$body,&$body); # 96 instructions
|
||||
my $base = "+2*$PUSH8(%rsp)";
|
||||
|
||||
&lea ("%rsp","-$PUSH8(%rsp)") if (($j%2)==0);
|
||||
if (($j%2)==0) {
|
||||
&lea ("%rsp","-$PUSH8(%rsp)");
|
||||
$code.=<<___ if (!$win64);
|
||||
.cfi_cfa_expression %rsp+`$PUSH8-8`,deref,+8
|
||||
# copy secondary frame pointer to new location again at -8(%rsp)
|
||||
pushq $PUSH8-8(%rsp)
|
||||
.cfi_cfa_expression %rsp,deref,+8
|
||||
lea 8(%rsp),%rsp
|
||||
.cfi_cfa_expression %rsp-8,deref,+8
|
||||
___
|
||||
}
|
||||
foreach (Xupdate_256_AVX()) { # 29 instructions
|
||||
eval;
|
||||
eval(shift(@insns));
|
||||
@@ -1234,26 +1262,28 @@ $code.=<<___;
|
||||
|
||||
jbe .Loop_avx2
|
||||
lea (%rsp),$Tbl
|
||||
# temporarily use $Tbl as index to $_rsp
|
||||
# this avoids the need to save a secondary frame pointer at -8(%rsp)
|
||||
.cfi_cfa_expression $Tbl+`16*$SZ+7*8`,deref,+8
|
||||
|
||||
.Ldone_avx2:
|
||||
lea ($Tbl),%rsp
|
||||
mov $_ivp,$ivp
|
||||
mov $_rsp,%rsi
|
||||
mov 16*$SZ+4*8($Tbl),$ivp
|
||||
mov 16*$SZ+7*8($Tbl),%rsi
|
||||
.cfi_def_cfa %rsi,8
|
||||
vmovdqu $iv,($ivp) # output IV
|
||||
vzeroall
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
movaps `$framesz+16*0`(%rsp),%xmm6
|
||||
movaps `$framesz+16*1`(%rsp),%xmm7
|
||||
movaps `$framesz+16*2`(%rsp),%xmm8
|
||||
movaps `$framesz+16*3`(%rsp),%xmm9
|
||||
movaps `$framesz+16*4`(%rsp),%xmm10
|
||||
movaps `$framesz+16*5`(%rsp),%xmm11
|
||||
movaps `$framesz+16*6`(%rsp),%xmm12
|
||||
movaps `$framesz+16*7`(%rsp),%xmm13
|
||||
movaps `$framesz+16*8`(%rsp),%xmm14
|
||||
movaps `$framesz+16*9`(%rsp),%xmm15
|
||||
movaps `$framesz+16*0`($Tbl),%xmm6
|
||||
movaps `$framesz+16*1`($Tbl),%xmm7
|
||||
movaps `$framesz+16*2`($Tbl),%xmm8
|
||||
movaps `$framesz+16*3`($Tbl),%xmm9
|
||||
movaps `$framesz+16*4`($Tbl),%xmm10
|
||||
movaps `$framesz+16*5`($Tbl),%xmm11
|
||||
movaps `$framesz+16*6`($Tbl),%xmm12
|
||||
movaps `$framesz+16*7`($Tbl),%xmm13
|
||||
movaps `$framesz+16*8`($Tbl),%xmm14
|
||||
movaps `$framesz+16*9`($Tbl),%xmm15
|
||||
___
|
||||
$code.=<<___;
|
||||
mov -48(%rsi),%r15
|
||||
@@ -1341,6 +1371,7 @@ $code.=<<___;
|
||||
.type ${func}_shaext,\@function,6
|
||||
.align 32
|
||||
${func}_shaext:
|
||||
.cfi_startproc
|
||||
mov `($win64?56:8)`(%rsp),$inp # load 7th argument
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
@@ -1557,6 +1588,7 @@ $code.=<<___ if ($win64);
|
||||
___
|
||||
$code.=<<___;
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size ${func}_shaext,.-${func}_shaext
|
||||
___
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
# nothing one can do and the result appears optimal. CCM result is
|
||||
# identical to CBC, because CBC-MAC is essentially CBC encrypt without
|
||||
# saving output. CCM CTR "stays invisible," because it's neatly
|
||||
# interleaved wih CBC-MAC. This provides ~30% improvement over
|
||||
# interleaved with CBC-MAC. This provides ~30% improvement over
|
||||
# "straightforward" CCM implementation with CTR and CBC-MAC performed
|
||||
# disjointly. Parallelizable modes practically achieve the theoretical
|
||||
# limit.
|
||||
@@ -986,6 +986,7 @@ $code.=<<___;
|
||||
.type aesni_ccm64_encrypt_blocks,\@function,6
|
||||
.align 16
|
||||
aesni_ccm64_encrypt_blocks:
|
||||
.cfi_startproc
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
lea -0x58(%rsp),%rsp
|
||||
@@ -1068,6 +1069,7 @@ $code.=<<___ if ($win64);
|
||||
___
|
||||
$code.=<<___;
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aesni_ccm64_encrypt_blocks,.-aesni_ccm64_encrypt_blocks
|
||||
___
|
||||
######################################################################
|
||||
@@ -1076,6 +1078,7 @@ $code.=<<___;
|
||||
.type aesni_ccm64_decrypt_blocks,\@function,6
|
||||
.align 16
|
||||
aesni_ccm64_decrypt_blocks:
|
||||
.cfi_startproc
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
lea -0x58(%rsp),%rsp
|
||||
@@ -1175,6 +1178,7 @@ $code.=<<___ if ($win64);
|
||||
___
|
||||
$code.=<<___;
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aesni_ccm64_decrypt_blocks,.-aesni_ccm64_decrypt_blocks
|
||||
___
|
||||
}
|
||||
@@ -3033,6 +3037,7 @@ $code.=<<___;
|
||||
.type __ocb_encrypt6,\@abi-omnipotent
|
||||
.align 32
|
||||
__ocb_encrypt6:
|
||||
.cfi_startproc
|
||||
pxor $rndkey0l,@offset[5] # offset_i ^ round[0]
|
||||
movdqu ($L_p,$i1),@offset[1]
|
||||
movdqa @offset[0],@offset[2]
|
||||
@@ -3130,11 +3135,13 @@ __ocb_encrypt6:
|
||||
aesenclast @offset[4],$inout4
|
||||
aesenclast @offset[5],$inout5
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size __ocb_encrypt6,.-__ocb_encrypt6
|
||||
|
||||
.type __ocb_encrypt4,\@abi-omnipotent
|
||||
.align 32
|
||||
__ocb_encrypt4:
|
||||
.cfi_startproc
|
||||
pxor $rndkey0l,@offset[5] # offset_i ^ round[0]
|
||||
movdqu ($L_p,$i1),@offset[1]
|
||||
movdqa @offset[0],@offset[2]
|
||||
@@ -3199,11 +3206,13 @@ __ocb_encrypt4:
|
||||
aesenclast @offset[2],$inout2
|
||||
aesenclast @offset[3],$inout3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size __ocb_encrypt4,.-__ocb_encrypt4
|
||||
|
||||
.type __ocb_encrypt1,\@abi-omnipotent
|
||||
.align 32
|
||||
__ocb_encrypt1:
|
||||
.cfi_startproc
|
||||
pxor @offset[5],$inout5 # offset_i
|
||||
pxor $rndkey0l,$inout5 # offset_i ^ round[0]
|
||||
pxor $inout0,$checksum # accumulate checksum
|
||||
@@ -3234,6 +3243,7 @@ __ocb_encrypt1:
|
||||
|
||||
aesenclast $inout5,$inout0
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size __ocb_encrypt1,.-__ocb_encrypt1
|
||||
|
||||
.globl aesni_ocb_decrypt
|
||||
@@ -3515,6 +3525,7 @@ $code.=<<___;
|
||||
.type __ocb_decrypt6,\@abi-omnipotent
|
||||
.align 32
|
||||
__ocb_decrypt6:
|
||||
.cfi_startproc
|
||||
pxor $rndkey0l,@offset[5] # offset_i ^ round[0]
|
||||
movdqu ($L_p,$i1),@offset[1]
|
||||
movdqa @offset[0],@offset[2]
|
||||
@@ -3606,11 +3617,13 @@ __ocb_decrypt6:
|
||||
aesdeclast @offset[4],$inout4
|
||||
aesdeclast @offset[5],$inout5
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size __ocb_decrypt6,.-__ocb_decrypt6
|
||||
|
||||
.type __ocb_decrypt4,\@abi-omnipotent
|
||||
.align 32
|
||||
__ocb_decrypt4:
|
||||
.cfi_startproc
|
||||
pxor $rndkey0l,@offset[5] # offset_i ^ round[0]
|
||||
movdqu ($L_p,$i1),@offset[1]
|
||||
movdqa @offset[0],@offset[2]
|
||||
@@ -3671,11 +3684,13 @@ __ocb_decrypt4:
|
||||
aesdeclast @offset[2],$inout2
|
||||
aesdeclast @offset[3],$inout3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size __ocb_decrypt4,.-__ocb_decrypt4
|
||||
|
||||
.type __ocb_decrypt1,\@abi-omnipotent
|
||||
.align 32
|
||||
__ocb_decrypt1:
|
||||
.cfi_startproc
|
||||
pxor @offset[5],$inout5 # offset_i
|
||||
pxor $rndkey0l,$inout5 # offset_i ^ round[0]
|
||||
pxor $inout5,$inout0 # input ^ round[0] ^ offset_i
|
||||
@@ -3705,6 +3720,7 @@ __ocb_decrypt1:
|
||||
|
||||
aesdeclast $inout5,$inout0
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size __ocb_decrypt1,.-__ocb_decrypt1
|
||||
___
|
||||
} }}
|
||||
@@ -4639,7 +4655,6 @@ __aesni_set_encrypt_key:
|
||||
add \$8,%rsp
|
||||
.cfi_adjust_cfa_offset -8
|
||||
ret
|
||||
.cfi_endproc
|
||||
.LSEH_end_set_encrypt_key:
|
||||
|
||||
.align 16
|
||||
@@ -4710,6 +4725,7 @@ __aesni_set_encrypt_key:
|
||||
shufps \$0b10101010,%xmm1,%xmm1 # critical path
|
||||
xorps %xmm1,%xmm2
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size ${PREFIX}_set_encrypt_key,.-${PREFIX}_set_encrypt_key
|
||||
.size __aesni_set_encrypt_key,.-__aesni_set_encrypt_key
|
||||
___
|
||||
|
||||
@@ -384,6 +384,836 @@ ___
|
||||
&gen_block("en");
|
||||
&gen_block("de");
|
||||
}}}
|
||||
|
||||
# Performance in cycles per byte.
|
||||
# Processed with AES-ECB different key size.
|
||||
# It shows the value before and after optimization as below:
|
||||
# (before/after):
|
||||
#
|
||||
# AES-128-ECB AES-192-ECB AES-256-ECB
|
||||
# Cortex-A57 1.85/0.82 2.16/0.96 2.47/1.10
|
||||
# Cortex-A72 1.64/0.85 1.82/0.99 2.13/1.14
|
||||
|
||||
# Optimization is implemented by loop unrolling and interleaving.
|
||||
# Commonly, we choose the unrolling factor as 5, if the input
|
||||
# data size smaller than 5 blocks, but not smaller than 3 blocks,
|
||||
# choose 3 as the unrolling factor.
|
||||
# If the input data size dsize >= 5*16 bytes, then take 5 blocks
|
||||
# as one iteration, every loop the left size lsize -= 5*16.
|
||||
# If 5*16 > lsize >= 3*16 bytes, take 3 blocks as one iteration,
|
||||
# every loop lsize -=3*16.
|
||||
# If lsize < 3*16 bytes, treat them as the tail, interleave the
|
||||
# two blocks AES instructions.
|
||||
# There is one special case, if the original input data size dsize
|
||||
# = 16 bytes, we will treat it seperately to improve the
|
||||
# performance: one independent code block without LR, FP load and
|
||||
# store, just looks like what the original ECB implementation does.
|
||||
|
||||
{{{
|
||||
my ($inp,$out,$len,$key)=map("x$_",(0..3));
|
||||
my ($enc,$rounds,$cnt,$key_,$step)=("w4","w5","w6","x7","x8");
|
||||
my ($dat0,$dat1,$in0,$in1,$tmp0,$tmp1,$tmp2,$rndlast)=map("q$_",(0..7));
|
||||
|
||||
my ($dat,$tmp,$rndzero_n_last)=($dat0,$tmp0,$tmp1);
|
||||
|
||||
### q7 last round key
|
||||
### q10-q15 q7 Last 7 round keys
|
||||
### q8-q9 preloaded round keys except last 7 keys for big size
|
||||
### q5, q6, q8-q9 preloaded round keys except last 7 keys for only 16 byte
|
||||
|
||||
{
|
||||
my ($dat2,$in2,$tmp2)=map("q$_",(10,11,9));
|
||||
|
||||
my ($dat3,$in3,$tmp3); # used only in 64-bit mode
|
||||
my ($dat4,$in4,$tmp4);
|
||||
if ($flavour =~ /64/) {
|
||||
($dat2,$dat3,$dat4,$in2,$in3,$in4,$tmp3,$tmp4)=map("q$_",(16..23));
|
||||
}
|
||||
|
||||
$code.=<<___;
|
||||
.globl ${prefix}_ecb_encrypt
|
||||
.type ${prefix}_ecb_encrypt,%function
|
||||
.align 5
|
||||
${prefix}_ecb_encrypt:
|
||||
___
|
||||
$code.=<<___ if ($flavour =~ /64/);
|
||||
subs $len,$len,#16
|
||||
// Original input data size bigger than 16, jump to big size processing.
|
||||
b.ne .Lecb_big_size
|
||||
vld1.8 {$dat0},[$inp]
|
||||
cmp $enc,#0 // en- or decrypting?
|
||||
ldr $rounds,[$key,#240]
|
||||
vld1.32 {q5-q6},[$key],#32 // load key schedule...
|
||||
|
||||
b.eq .Lecb_small_dec
|
||||
aese $dat0,q5
|
||||
aesmc $dat0,$dat0
|
||||
vld1.32 {q8-q9},[$key],#32 // load key schedule...
|
||||
aese $dat0,q6
|
||||
aesmc $dat0,$dat0
|
||||
subs $rounds,$rounds,#10 // if rounds==10, jump to aes-128-ecb processing
|
||||
b.eq .Lecb_128_enc
|
||||
.Lecb_round_loop:
|
||||
aese $dat0,q8
|
||||
aesmc $dat0,$dat0
|
||||
vld1.32 {q8},[$key],#16 // load key schedule...
|
||||
aese $dat0,q9
|
||||
aesmc $dat0,$dat0
|
||||
vld1.32 {q9},[$key],#16 // load key schedule...
|
||||
subs $rounds,$rounds,#2 // bias
|
||||
b.gt .Lecb_round_loop
|
||||
.Lecb_128_enc:
|
||||
vld1.32 {q10-q11},[$key],#32 // load key schedule...
|
||||
aese $dat0,q8
|
||||
aesmc $dat0,$dat0
|
||||
aese $dat0,q9
|
||||
aesmc $dat0,$dat0
|
||||
vld1.32 {q12-q13},[$key],#32 // load key schedule...
|
||||
aese $dat0,q10
|
||||
aesmc $dat0,$dat0
|
||||
aese $dat0,q11
|
||||
aesmc $dat0,$dat0
|
||||
vld1.32 {q14-q15},[$key],#32 // load key schedule...
|
||||
aese $dat0,q12
|
||||
aesmc $dat0,$dat0
|
||||
aese $dat0,q13
|
||||
aesmc $dat0,$dat0
|
||||
vld1.32 {$rndlast},[$key]
|
||||
aese $dat0,q14
|
||||
aesmc $dat0,$dat0
|
||||
aese $dat0,q15
|
||||
veor $dat0,$dat0,$rndlast
|
||||
vst1.8 {$dat0},[$out]
|
||||
b .Lecb_Final_abort
|
||||
.Lecb_small_dec:
|
||||
aesd $dat0,q5
|
||||
aesimc $dat0,$dat0
|
||||
vld1.32 {q8-q9},[$key],#32 // load key schedule...
|
||||
aesd $dat0,q6
|
||||
aesimc $dat0,$dat0
|
||||
subs $rounds,$rounds,#10 // bias
|
||||
b.eq .Lecb_128_dec
|
||||
.Lecb_dec_round_loop:
|
||||
aesd $dat0,q8
|
||||
aesimc $dat0,$dat0
|
||||
vld1.32 {q8},[$key],#16 // load key schedule...
|
||||
aesd $dat0,q9
|
||||
aesimc $dat0,$dat0
|
||||
vld1.32 {q9},[$key],#16 // load key schedule...
|
||||
subs $rounds,$rounds,#2 // bias
|
||||
b.gt .Lecb_dec_round_loop
|
||||
.Lecb_128_dec:
|
||||
vld1.32 {q10-q11},[$key],#32 // load key schedule...
|
||||
aesd $dat0,q8
|
||||
aesimc $dat0,$dat0
|
||||
aesd $dat0,q9
|
||||
aesimc $dat0,$dat0
|
||||
vld1.32 {q12-q13},[$key],#32 // load key schedule...
|
||||
aesd $dat0,q10
|
||||
aesimc $dat0,$dat0
|
||||
aesd $dat0,q11
|
||||
aesimc $dat0,$dat0
|
||||
vld1.32 {q14-q15},[$key],#32 // load key schedule...
|
||||
aesd $dat0,q12
|
||||
aesimc $dat0,$dat0
|
||||
aesd $dat0,q13
|
||||
aesimc $dat0,$dat0
|
||||
vld1.32 {$rndlast},[$key]
|
||||
aesd $dat0,q14
|
||||
aesimc $dat0,$dat0
|
||||
aesd $dat0,q15
|
||||
veor $dat0,$dat0,$rndlast
|
||||
vst1.8 {$dat0},[$out]
|
||||
b .Lecb_Final_abort
|
||||
.Lecb_big_size:
|
||||
___
|
||||
$code.=<<___ if ($flavour =~ /64/);
|
||||
stp x29,x30,[sp,#-16]!
|
||||
add x29,sp,#0
|
||||
___
|
||||
$code.=<<___ if ($flavour !~ /64/);
|
||||
mov ip,sp
|
||||
stmdb sp!,{r4-r8,lr}
|
||||
vstmdb sp!,{d8-d15} @ ABI specification says so
|
||||
ldmia ip,{r4-r5} @ load remaining args
|
||||
subs $len,$len,#16
|
||||
___
|
||||
$code.=<<___;
|
||||
mov $step,#16
|
||||
b.lo .Lecb_done
|
||||
cclr $step,eq
|
||||
|
||||
cmp $enc,#0 // en- or decrypting?
|
||||
ldr $rounds,[$key,#240]
|
||||
and $len,$len,#-16
|
||||
vld1.8 {$dat},[$inp],$step
|
||||
|
||||
vld1.32 {q8-q9},[$key] // load key schedule...
|
||||
sub $rounds,$rounds,#6
|
||||
add $key_,$key,x5,lsl#4 // pointer to last 7 round keys
|
||||
sub $rounds,$rounds,#2
|
||||
vld1.32 {q10-q11},[$key_],#32
|
||||
vld1.32 {q12-q13},[$key_],#32
|
||||
vld1.32 {q14-q15},[$key_],#32
|
||||
vld1.32 {$rndlast},[$key_]
|
||||
|
||||
add $key_,$key,#32
|
||||
mov $cnt,$rounds
|
||||
b.eq .Lecb_dec
|
||||
|
||||
vld1.8 {$dat1},[$inp],#16
|
||||
subs $len,$len,#32 // bias
|
||||
add $cnt,$rounds,#2
|
||||
vorr $in1,$dat1,$dat1
|
||||
vorr $dat2,$dat1,$dat1
|
||||
vorr $dat1,$dat,$dat
|
||||
b.lo .Lecb_enc_tail
|
||||
|
||||
vorr $dat1,$in1,$in1
|
||||
vld1.8 {$dat2},[$inp],#16
|
||||
___
|
||||
$code.=<<___ if ($flavour =~ /64/);
|
||||
cmp $len,#32
|
||||
b.lo .Loop3x_ecb_enc
|
||||
|
||||
vld1.8 {$dat3},[$inp],#16
|
||||
vld1.8 {$dat4},[$inp],#16
|
||||
sub $len,$len,#32 // bias
|
||||
mov $cnt,$rounds
|
||||
|
||||
.Loop5x_ecb_enc:
|
||||
aese $dat0,q8
|
||||
aesmc $dat0,$dat0
|
||||
aese $dat1,q8
|
||||
aesmc $dat1,$dat1
|
||||
aese $dat2,q8
|
||||
aesmc $dat2,$dat2
|
||||
aese $dat3,q8
|
||||
aesmc $dat3,$dat3
|
||||
aese $dat4,q8
|
||||
aesmc $dat4,$dat4
|
||||
vld1.32 {q8},[$key_],#16
|
||||
subs $cnt,$cnt,#2
|
||||
aese $dat0,q9
|
||||
aesmc $dat0,$dat0
|
||||
aese $dat1,q9
|
||||
aesmc $dat1,$dat1
|
||||
aese $dat2,q9
|
||||
aesmc $dat2,$dat2
|
||||
aese $dat3,q9
|
||||
aesmc $dat3,$dat3
|
||||
aese $dat4,q9
|
||||
aesmc $dat4,$dat4
|
||||
vld1.32 {q9},[$key_],#16
|
||||
b.gt .Loop5x_ecb_enc
|
||||
|
||||
aese $dat0,q8
|
||||
aesmc $dat0,$dat0
|
||||
aese $dat1,q8
|
||||
aesmc $dat1,$dat1
|
||||
aese $dat2,q8
|
||||
aesmc $dat2,$dat2
|
||||
aese $dat3,q8
|
||||
aesmc $dat3,$dat3
|
||||
aese $dat4,q8
|
||||
aesmc $dat4,$dat4
|
||||
cmp $len,#0x40 // because .Lecb_enc_tail4x
|
||||
sub $len,$len,#0x50
|
||||
|
||||
aese $dat0,q9
|
||||
aesmc $dat0,$dat0
|
||||
aese $dat1,q9
|
||||
aesmc $dat1,$dat1
|
||||
aese $dat2,q9
|
||||
aesmc $dat2,$dat2
|
||||
aese $dat3,q9
|
||||
aesmc $dat3,$dat3
|
||||
aese $dat4,q9
|
||||
aesmc $dat4,$dat4
|
||||
csel x6,xzr,$len,gt // borrow x6, $cnt, "gt" is not typo
|
||||
mov $key_,$key
|
||||
|
||||
aese $dat0,q10
|
||||
aesmc $dat0,$dat0
|
||||
aese $dat1,q10
|
||||
aesmc $dat1,$dat1
|
||||
aese $dat2,q10
|
||||
aesmc $dat2,$dat2
|
||||
aese $dat3,q10
|
||||
aesmc $dat3,$dat3
|
||||
aese $dat4,q10
|
||||
aesmc $dat4,$dat4
|
||||
add $inp,$inp,x6 // $inp is adjusted in such way that
|
||||
// at exit from the loop $dat1-$dat4
|
||||
// are loaded with last "words"
|
||||
add x6,$len,#0x60 // because .Lecb_enc_tail4x
|
||||
|
||||
aese $dat0,q11
|
||||
aesmc $dat0,$dat0
|
||||
aese $dat1,q11
|
||||
aesmc $dat1,$dat1
|
||||
aese $dat2,q11
|
||||
aesmc $dat2,$dat2
|
||||
aese $dat3,q11
|
||||
aesmc $dat3,$dat3
|
||||
aese $dat4,q11
|
||||
aesmc $dat4,$dat4
|
||||
|
||||
aese $dat0,q12
|
||||
aesmc $dat0,$dat0
|
||||
aese $dat1,q12
|
||||
aesmc $dat1,$dat1
|
||||
aese $dat2,q12
|
||||
aesmc $dat2,$dat2
|
||||
aese $dat3,q12
|
||||
aesmc $dat3,$dat3
|
||||
aese $dat4,q12
|
||||
aesmc $dat4,$dat4
|
||||
|
||||
aese $dat0,q13
|
||||
aesmc $dat0,$dat0
|
||||
aese $dat1,q13
|
||||
aesmc $dat1,$dat1
|
||||
aese $dat2,q13
|
||||
aesmc $dat2,$dat2
|
||||
aese $dat3,q13
|
||||
aesmc $dat3,$dat3
|
||||
aese $dat4,q13
|
||||
aesmc $dat4,$dat4
|
||||
|
||||
aese $dat0,q14
|
||||
aesmc $dat0,$dat0
|
||||
aese $dat1,q14
|
||||
aesmc $dat1,$dat1
|
||||
aese $dat2,q14
|
||||
aesmc $dat2,$dat2
|
||||
aese $dat3,q14
|
||||
aesmc $dat3,$dat3
|
||||
aese $dat4,q14
|
||||
aesmc $dat4,$dat4
|
||||
|
||||
aese $dat0,q15
|
||||
vld1.8 {$in0},[$inp],#16
|
||||
aese $dat1,q15
|
||||
vld1.8 {$in1},[$inp],#16
|
||||
aese $dat2,q15
|
||||
vld1.8 {$in2},[$inp],#16
|
||||
aese $dat3,q15
|
||||
vld1.8 {$in3},[$inp],#16
|
||||
aese $dat4,q15
|
||||
vld1.8 {$in4},[$inp],#16
|
||||
cbz x6,.Lecb_enc_tail4x
|
||||
vld1.32 {q8},[$key_],#16 // re-pre-load rndkey[0]
|
||||
veor $tmp0,$rndlast,$dat0
|
||||
vorr $dat0,$in0,$in0
|
||||
veor $tmp1,$rndlast,$dat1
|
||||
vorr $dat1,$in1,$in1
|
||||
veor $tmp2,$rndlast,$dat2
|
||||
vorr $dat2,$in2,$in2
|
||||
veor $tmp3,$rndlast,$dat3
|
||||
vorr $dat3,$in3,$in3
|
||||
veor $tmp4,$rndlast,$dat4
|
||||
vst1.8 {$tmp0},[$out],#16
|
||||
vorr $dat4,$in4,$in4
|
||||
vst1.8 {$tmp1},[$out],#16
|
||||
mov $cnt,$rounds
|
||||
vst1.8 {$tmp2},[$out],#16
|
||||
vld1.32 {q9},[$key_],#16 // re-pre-load rndkey[1]
|
||||
vst1.8 {$tmp3},[$out],#16
|
||||
vst1.8 {$tmp4},[$out],#16
|
||||
b.hs .Loop5x_ecb_enc
|
||||
|
||||
add $len,$len,#0x50
|
||||
cbz $len,.Lecb_done
|
||||
|
||||
add $cnt,$rounds,#2
|
||||
subs $len,$len,#0x30
|
||||
vorr $dat0,$in2,$in2
|
||||
vorr $dat1,$in3,$in3
|
||||
vorr $dat2,$in4,$in4
|
||||
b.lo .Lecb_enc_tail
|
||||
|
||||
b .Loop3x_ecb_enc
|
||||
|
||||
.align 4
|
||||
.Lecb_enc_tail4x:
|
||||
veor $tmp1,$rndlast,$dat1
|
||||
veor $tmp2,$rndlast,$dat2
|
||||
veor $tmp3,$rndlast,$dat3
|
||||
veor $tmp4,$rndlast,$dat4
|
||||
vst1.8 {$tmp1},[$out],#16
|
||||
vst1.8 {$tmp2},[$out],#16
|
||||
vst1.8 {$tmp3},[$out],#16
|
||||
vst1.8 {$tmp4},[$out],#16
|
||||
|
||||
b .Lecb_done
|
||||
.align 4
|
||||
___
|
||||
$code.=<<___;
|
||||
.Loop3x_ecb_enc:
|
||||
aese $dat0,q8
|
||||
aesmc $dat0,$dat0
|
||||
aese $dat1,q8
|
||||
aesmc $dat1,$dat1
|
||||
aese $dat2,q8
|
||||
aesmc $dat2,$dat2
|
||||
vld1.32 {q8},[$key_],#16
|
||||
subs $cnt,$cnt,#2
|
||||
aese $dat0,q9
|
||||
aesmc $dat0,$dat0
|
||||
aese $dat1,q9
|
||||
aesmc $dat1,$dat1
|
||||
aese $dat2,q9
|
||||
aesmc $dat2,$dat2
|
||||
vld1.32 {q9},[$key_],#16
|
||||
b.gt .Loop3x_ecb_enc
|
||||
|
||||
aese $dat0,q8
|
||||
aesmc $dat0,$dat0
|
||||
aese $dat1,q8
|
||||
aesmc $dat1,$dat1
|
||||
aese $dat2,q8
|
||||
aesmc $dat2,$dat2
|
||||
subs $len,$len,#0x30
|
||||
mov.lo x6,$len // x6, $cnt, is zero at this point
|
||||
aese $dat0,q9
|
||||
aesmc $dat0,$dat0
|
||||
aese $dat1,q9
|
||||
aesmc $dat1,$dat1
|
||||
aese $dat2,q9
|
||||
aesmc $dat2,$dat2
|
||||
add $inp,$inp,x6 // $inp is adjusted in such way that
|
||||
// at exit from the loop $dat1-$dat2
|
||||
// are loaded with last "words"
|
||||
mov $key_,$key
|
||||
aese $dat0,q12
|
||||
aesmc $dat0,$dat0
|
||||
aese $dat1,q12
|
||||
aesmc $dat1,$dat1
|
||||
aese $dat2,q12
|
||||
aesmc $dat2,$dat2
|
||||
vld1.8 {$in0},[$inp],#16
|
||||
aese $dat0,q13
|
||||
aesmc $dat0,$dat0
|
||||
aese $dat1,q13
|
||||
aesmc $dat1,$dat1
|
||||
aese $dat2,q13
|
||||
aesmc $dat2,$dat2
|
||||
vld1.8 {$in1},[$inp],#16
|
||||
aese $dat0,q14
|
||||
aesmc $dat0,$dat0
|
||||
aese $dat1,q14
|
||||
aesmc $dat1,$dat1
|
||||
aese $dat2,q14
|
||||
aesmc $dat2,$dat2
|
||||
vld1.8 {$in2},[$inp],#16
|
||||
aese $dat0,q15
|
||||
aese $dat1,q15
|
||||
aese $dat2,q15
|
||||
vld1.32 {q8},[$key_],#16 // re-pre-load rndkey[0]
|
||||
add $cnt,$rounds,#2
|
||||
veor $tmp0,$rndlast,$dat0
|
||||
veor $tmp1,$rndlast,$dat1
|
||||
veor $dat2,$dat2,$rndlast
|
||||
vld1.32 {q9},[$key_],#16 // re-pre-load rndkey[1]
|
||||
vst1.8 {$tmp0},[$out],#16
|
||||
vorr $dat0,$in0,$in0
|
||||
vst1.8 {$tmp1},[$out],#16
|
||||
vorr $dat1,$in1,$in1
|
||||
vst1.8 {$dat2},[$out],#16
|
||||
vorr $dat2,$in2,$in2
|
||||
b.hs .Loop3x_ecb_enc
|
||||
|
||||
cmn $len,#0x30
|
||||
b.eq .Lecb_done
|
||||
nop
|
||||
|
||||
.Lecb_enc_tail:
|
||||
aese $dat1,q8
|
||||
aesmc $dat1,$dat1
|
||||
aese $dat2,q8
|
||||
aesmc $dat2,$dat2
|
||||
vld1.32 {q8},[$key_],#16
|
||||
subs $cnt,$cnt,#2
|
||||
aese $dat1,q9
|
||||
aesmc $dat1,$dat1
|
||||
aese $dat2,q9
|
||||
aesmc $dat2,$dat2
|
||||
vld1.32 {q9},[$key_],#16
|
||||
b.gt .Lecb_enc_tail
|
||||
|
||||
aese $dat1,q8
|
||||
aesmc $dat1,$dat1
|
||||
aese $dat2,q8
|
||||
aesmc $dat2,$dat2
|
||||
aese $dat1,q9
|
||||
aesmc $dat1,$dat1
|
||||
aese $dat2,q9
|
||||
aesmc $dat2,$dat2
|
||||
aese $dat1,q12
|
||||
aesmc $dat1,$dat1
|
||||
aese $dat2,q12
|
||||
aesmc $dat2,$dat2
|
||||
cmn $len,#0x20
|
||||
aese $dat1,q13
|
||||
aesmc $dat1,$dat1
|
||||
aese $dat2,q13
|
||||
aesmc $dat2,$dat2
|
||||
aese $dat1,q14
|
||||
aesmc $dat1,$dat1
|
||||
aese $dat2,q14
|
||||
aesmc $dat2,$dat2
|
||||
aese $dat1,q15
|
||||
aese $dat2,q15
|
||||
b.eq .Lecb_enc_one
|
||||
veor $tmp1,$rndlast,$dat1
|
||||
veor $tmp2,$rndlast,$dat2
|
||||
vst1.8 {$tmp1},[$out],#16
|
||||
vst1.8 {$tmp2},[$out],#16
|
||||
b .Lecb_done
|
||||
|
||||
.Lecb_enc_one:
|
||||
veor $tmp1,$rndlast,$dat2
|
||||
vst1.8 {$tmp1},[$out],#16
|
||||
b .Lecb_done
|
||||
___
|
||||
|
||||
$code.=<<___;
|
||||
.align 5
|
||||
.Lecb_dec:
|
||||
vld1.8 {$dat1},[$inp],#16
|
||||
subs $len,$len,#32 // bias
|
||||
add $cnt,$rounds,#2
|
||||
vorr $in1,$dat1,$dat1
|
||||
vorr $dat2,$dat1,$dat1
|
||||
vorr $dat1,$dat,$dat
|
||||
b.lo .Lecb_dec_tail
|
||||
|
||||
vorr $dat1,$in1,$in1
|
||||
vld1.8 {$dat2},[$inp],#16
|
||||
___
|
||||
$code.=<<___ if ($flavour =~ /64/);
|
||||
cmp $len,#32
|
||||
b.lo .Loop3x_ecb_dec
|
||||
|
||||
vld1.8 {$dat3},[$inp],#16
|
||||
vld1.8 {$dat4},[$inp],#16
|
||||
sub $len,$len,#32 // bias
|
||||
mov $cnt,$rounds
|
||||
|
||||
.Loop5x_ecb_dec:
|
||||
aesd $dat0,q8
|
||||
aesimc $dat0,$dat0
|
||||
aesd $dat1,q8
|
||||
aesimc $dat1,$dat1
|
||||
aesd $dat2,q8
|
||||
aesimc $dat2,$dat2
|
||||
aesd $dat3,q8
|
||||
aesimc $dat3,$dat3
|
||||
aesd $dat4,q8
|
||||
aesimc $dat4,$dat4
|
||||
vld1.32 {q8},[$key_],#16
|
||||
subs $cnt,$cnt,#2
|
||||
aesd $dat0,q9
|
||||
aesimc $dat0,$dat0
|
||||
aesd $dat1,q9
|
||||
aesimc $dat1,$dat1
|
||||
aesd $dat2,q9
|
||||
aesimc $dat2,$dat2
|
||||
aesd $dat3,q9
|
||||
aesimc $dat3,$dat3
|
||||
aesd $dat4,q9
|
||||
aesimc $dat4,$dat4
|
||||
vld1.32 {q9},[$key_],#16
|
||||
b.gt .Loop5x_ecb_dec
|
||||
|
||||
aesd $dat0,q8
|
||||
aesimc $dat0,$dat0
|
||||
aesd $dat1,q8
|
||||
aesimc $dat1,$dat1
|
||||
aesd $dat2,q8
|
||||
aesimc $dat2,$dat2
|
||||
aesd $dat3,q8
|
||||
aesimc $dat3,$dat3
|
||||
aesd $dat4,q8
|
||||
aesimc $dat4,$dat4
|
||||
cmp $len,#0x40 // because .Lecb_tail4x
|
||||
sub $len,$len,#0x50
|
||||
|
||||
aesd $dat0,q9
|
||||
aesimc $dat0,$dat0
|
||||
aesd $dat1,q9
|
||||
aesimc $dat1,$dat1
|
||||
aesd $dat2,q9
|
||||
aesimc $dat2,$dat2
|
||||
aesd $dat3,q9
|
||||
aesimc $dat3,$dat3
|
||||
aesd $dat4,q9
|
||||
aesimc $dat4,$dat4
|
||||
csel x6,xzr,$len,gt // borrow x6, $cnt, "gt" is not typo
|
||||
mov $key_,$key
|
||||
|
||||
aesd $dat0,q10
|
||||
aesimc $dat0,$dat0
|
||||
aesd $dat1,q10
|
||||
aesimc $dat1,$dat1
|
||||
aesd $dat2,q10
|
||||
aesimc $dat2,$dat2
|
||||
aesd $dat3,q10
|
||||
aesimc $dat3,$dat3
|
||||
aesd $dat4,q10
|
||||
aesimc $dat4,$dat4
|
||||
add $inp,$inp,x6 // $inp is adjusted in such way that
|
||||
// at exit from the loop $dat1-$dat4
|
||||
// are loaded with last "words"
|
||||
add x6,$len,#0x60 // because .Lecb_tail4x
|
||||
|
||||
aesd $dat0,q11
|
||||
aesimc $dat0,$dat0
|
||||
aesd $dat1,q11
|
||||
aesimc $dat1,$dat1
|
||||
aesd $dat2,q11
|
||||
aesimc $dat2,$dat2
|
||||
aesd $dat3,q11
|
||||
aesimc $dat3,$dat3
|
||||
aesd $dat4,q11
|
||||
aesimc $dat4,$dat4
|
||||
|
||||
aesd $dat0,q12
|
||||
aesimc $dat0,$dat0
|
||||
aesd $dat1,q12
|
||||
aesimc $dat1,$dat1
|
||||
aesd $dat2,q12
|
||||
aesimc $dat2,$dat2
|
||||
aesd $dat3,q12
|
||||
aesimc $dat3,$dat3
|
||||
aesd $dat4,q12
|
||||
aesimc $dat4,$dat4
|
||||
|
||||
aesd $dat0,q13
|
||||
aesimc $dat0,$dat0
|
||||
aesd $dat1,q13
|
||||
aesimc $dat1,$dat1
|
||||
aesd $dat2,q13
|
||||
aesimc $dat2,$dat2
|
||||
aesd $dat3,q13
|
||||
aesimc $dat3,$dat3
|
||||
aesd $dat4,q13
|
||||
aesimc $dat4,$dat4
|
||||
|
||||
aesd $dat0,q14
|
||||
aesimc $dat0,$dat0
|
||||
aesd $dat1,q14
|
||||
aesimc $dat1,$dat1
|
||||
aesd $dat2,q14
|
||||
aesimc $dat2,$dat2
|
||||
aesd $dat3,q14
|
||||
aesimc $dat3,$dat3
|
||||
aesd $dat4,q14
|
||||
aesimc $dat4,$dat4
|
||||
|
||||
aesd $dat0,q15
|
||||
vld1.8 {$in0},[$inp],#16
|
||||
aesd $dat1,q15
|
||||
vld1.8 {$in1},[$inp],#16
|
||||
aesd $dat2,q15
|
||||
vld1.8 {$in2},[$inp],#16
|
||||
aesd $dat3,q15
|
||||
vld1.8 {$in3},[$inp],#16
|
||||
aesd $dat4,q15
|
||||
vld1.8 {$in4},[$inp],#16
|
||||
cbz x6,.Lecb_tail4x
|
||||
vld1.32 {q8},[$key_],#16 // re-pre-load rndkey[0]
|
||||
veor $tmp0,$rndlast,$dat0
|
||||
vorr $dat0,$in0,$in0
|
||||
veor $tmp1,$rndlast,$dat1
|
||||
vorr $dat1,$in1,$in1
|
||||
veor $tmp2,$rndlast,$dat2
|
||||
vorr $dat2,$in2,$in2
|
||||
veor $tmp3,$rndlast,$dat3
|
||||
vorr $dat3,$in3,$in3
|
||||
veor $tmp4,$rndlast,$dat4
|
||||
vst1.8 {$tmp0},[$out],#16
|
||||
vorr $dat4,$in4,$in4
|
||||
vst1.8 {$tmp1},[$out],#16
|
||||
mov $cnt,$rounds
|
||||
vst1.8 {$tmp2},[$out],#16
|
||||
vld1.32 {q9},[$key_],#16 // re-pre-load rndkey[1]
|
||||
vst1.8 {$tmp3},[$out],#16
|
||||
vst1.8 {$tmp4},[$out],#16
|
||||
b.hs .Loop5x_ecb_dec
|
||||
|
||||
add $len,$len,#0x50
|
||||
cbz $len,.Lecb_done
|
||||
|
||||
add $cnt,$rounds,#2
|
||||
subs $len,$len,#0x30
|
||||
vorr $dat0,$in2,$in2
|
||||
vorr $dat1,$in3,$in3
|
||||
vorr $dat2,$in4,$in4
|
||||
b.lo .Lecb_dec_tail
|
||||
|
||||
b .Loop3x_ecb_dec
|
||||
|
||||
.align 4
|
||||
.Lecb_tail4x:
|
||||
veor $tmp1,$rndlast,$dat1
|
||||
veor $tmp2,$rndlast,$dat2
|
||||
veor $tmp3,$rndlast,$dat3
|
||||
veor $tmp4,$rndlast,$dat4
|
||||
vst1.8 {$tmp1},[$out],#16
|
||||
vst1.8 {$tmp2},[$out],#16
|
||||
vst1.8 {$tmp3},[$out],#16
|
||||
vst1.8 {$tmp4},[$out],#16
|
||||
|
||||
b .Lecb_done
|
||||
.align 4
|
||||
___
|
||||
$code.=<<___;
|
||||
.Loop3x_ecb_dec:
|
||||
aesd $dat0,q8
|
||||
aesimc $dat0,$dat0
|
||||
aesd $dat1,q8
|
||||
aesimc $dat1,$dat1
|
||||
aesd $dat2,q8
|
||||
aesimc $dat2,$dat2
|
||||
vld1.32 {q8},[$key_],#16
|
||||
subs $cnt,$cnt,#2
|
||||
aesd $dat0,q9
|
||||
aesimc $dat0,$dat0
|
||||
aesd $dat1,q9
|
||||
aesimc $dat1,$dat1
|
||||
aesd $dat2,q9
|
||||
aesimc $dat2,$dat2
|
||||
vld1.32 {q9},[$key_],#16
|
||||
b.gt .Loop3x_ecb_dec
|
||||
|
||||
aesd $dat0,q8
|
||||
aesimc $dat0,$dat0
|
||||
aesd $dat1,q8
|
||||
aesimc $dat1,$dat1
|
||||
aesd $dat2,q8
|
||||
aesimc $dat2,$dat2
|
||||
subs $len,$len,#0x30
|
||||
mov.lo x6,$len // x6, $cnt, is zero at this point
|
||||
aesd $dat0,q9
|
||||
aesimc $dat0,$dat0
|
||||
aesd $dat1,q9
|
||||
aesimc $dat1,$dat1
|
||||
aesd $dat2,q9
|
||||
aesimc $dat2,$dat2
|
||||
add $inp,$inp,x6 // $inp is adjusted in such way that
|
||||
// at exit from the loop $dat1-$dat2
|
||||
// are loaded with last "words"
|
||||
mov $key_,$key
|
||||
aesd $dat0,q12
|
||||
aesimc $dat0,$dat0
|
||||
aesd $dat1,q12
|
||||
aesimc $dat1,$dat1
|
||||
aesd $dat2,q12
|
||||
aesimc $dat2,$dat2
|
||||
vld1.8 {$in0},[$inp],#16
|
||||
aesd $dat0,q13
|
||||
aesimc $dat0,$dat0
|
||||
aesd $dat1,q13
|
||||
aesimc $dat1,$dat1
|
||||
aesd $dat2,q13
|
||||
aesimc $dat2,$dat2
|
||||
vld1.8 {$in1},[$inp],#16
|
||||
aesd $dat0,q14
|
||||
aesimc $dat0,$dat0
|
||||
aesd $dat1,q14
|
||||
aesimc $dat1,$dat1
|
||||
aesd $dat2,q14
|
||||
aesimc $dat2,$dat2
|
||||
vld1.8 {$in2},[$inp],#16
|
||||
aesd $dat0,q15
|
||||
aesd $dat1,q15
|
||||
aesd $dat2,q15
|
||||
vld1.32 {q8},[$key_],#16 // re-pre-load rndkey[0]
|
||||
add $cnt,$rounds,#2
|
||||
veor $tmp0,$rndlast,$dat0
|
||||
veor $tmp1,$rndlast,$dat1
|
||||
veor $dat2,$dat2,$rndlast
|
||||
vld1.32 {q9},[$key_],#16 // re-pre-load rndkey[1]
|
||||
vst1.8 {$tmp0},[$out],#16
|
||||
vorr $dat0,$in0,$in0
|
||||
vst1.8 {$tmp1},[$out],#16
|
||||
vorr $dat1,$in1,$in1
|
||||
vst1.8 {$dat2},[$out],#16
|
||||
vorr $dat2,$in2,$in2
|
||||
b.hs .Loop3x_ecb_dec
|
||||
|
||||
cmn $len,#0x30
|
||||
b.eq .Lecb_done
|
||||
nop
|
||||
|
||||
.Lecb_dec_tail:
|
||||
aesd $dat1,q8
|
||||
aesimc $dat1,$dat1
|
||||
aesd $dat2,q8
|
||||
aesimc $dat2,$dat2
|
||||
vld1.32 {q8},[$key_],#16
|
||||
subs $cnt,$cnt,#2
|
||||
aesd $dat1,q9
|
||||
aesimc $dat1,$dat1
|
||||
aesd $dat2,q9
|
||||
aesimc $dat2,$dat2
|
||||
vld1.32 {q9},[$key_],#16
|
||||
b.gt .Lecb_dec_tail
|
||||
|
||||
aesd $dat1,q8
|
||||
aesimc $dat1,$dat1
|
||||
aesd $dat2,q8
|
||||
aesimc $dat2,$dat2
|
||||
aesd $dat1,q9
|
||||
aesimc $dat1,$dat1
|
||||
aesd $dat2,q9
|
||||
aesimc $dat2,$dat2
|
||||
aesd $dat1,q12
|
||||
aesimc $dat1,$dat1
|
||||
aesd $dat2,q12
|
||||
aesimc $dat2,$dat2
|
||||
cmn $len,#0x20
|
||||
aesd $dat1,q13
|
||||
aesimc $dat1,$dat1
|
||||
aesd $dat2,q13
|
||||
aesimc $dat2,$dat2
|
||||
aesd $dat1,q14
|
||||
aesimc $dat1,$dat1
|
||||
aesd $dat2,q14
|
||||
aesimc $dat2,$dat2
|
||||
aesd $dat1,q15
|
||||
aesd $dat2,q15
|
||||
b.eq .Lecb_dec_one
|
||||
veor $tmp1,$rndlast,$dat1
|
||||
veor $tmp2,$rndlast,$dat2
|
||||
vst1.8 {$tmp1},[$out],#16
|
||||
vst1.8 {$tmp2},[$out],#16
|
||||
b .Lecb_done
|
||||
|
||||
.Lecb_dec_one:
|
||||
veor $tmp1,$rndlast,$dat2
|
||||
vst1.8 {$tmp1},[$out],#16
|
||||
|
||||
.Lecb_done:
|
||||
___
|
||||
}
|
||||
$code.=<<___ if ($flavour !~ /64/);
|
||||
vldmia sp!,{d8-d15}
|
||||
ldmia sp!,{r4-r8,pc}
|
||||
___
|
||||
$code.=<<___ if ($flavour =~ /64/);
|
||||
ldr x29,[sp],#16
|
||||
___
|
||||
$code.=<<___ if ($flavour =~ /64/);
|
||||
.Lecb_Final_abort:
|
||||
ret
|
||||
___
|
||||
$code.=<<___;
|
||||
.size ${prefix}_ecb_encrypt,.-${prefix}_ecb_encrypt
|
||||
___
|
||||
}}}
|
||||
{{{
|
||||
my ($inp,$out,$len,$key,$ivp)=map("x$_",(0..4)); my $enc="w5";
|
||||
my ($rounds,$cnt,$key_,$step,$step1)=($enc,"w6","x7","x8","x12");
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
# - code was made position-independent;
|
||||
# - rounds were folded into a loop resulting in >5x size reduction
|
||||
# from 12.5KB to 2.2KB;
|
||||
# - above was possibile thanks to mixcolumns() modification that
|
||||
# - above was possible thanks to mixcolumns() modification that
|
||||
# allowed to feed its output back to aesenc[last], this was
|
||||
# achieved at cost of two additional inter-registers moves;
|
||||
# - some instruction reordering and interleaving;
|
||||
|
||||
@@ -68,8 +68,6 @@ SOURCE[../../providers/libfips.a]=$COMMON
|
||||
DEFINE[../../libcrypto]=$AESDEF
|
||||
DEFINE[../../providers/libfips.a]=$AESDEF
|
||||
DEFINE[../../providers/libimplementations.a]=$AESDEF
|
||||
# fipsprov.c needs access to AESNI.
|
||||
DEFINE[../../providers/fips]=$AESDEF
|
||||
|
||||
GENERATE[aes-ia64.s]=asm/aes-ia64.S
|
||||
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
#include "internal/cryptlib.h"
|
||||
#include <openssl/asn1.h>
|
||||
#include "asn1_local.h"
|
||||
#include <openssl/asn1t.h>
|
||||
|
||||
IMPLEMENT_ASN1_DUP_FUNCTION(ASN1_GENERALIZEDTIME)
|
||||
|
||||
/* This is the primary function used to parse ASN1_GENERALIZEDTIME */
|
||||
int asn1_generalizedtime_to_tm(struct tm *tm, const ASN1_GENERALIZEDTIME *d)
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
IMPLEMENT_ASN1_MSTRING(ASN1_TIME, B_ASN1_TIME)
|
||||
|
||||
IMPLEMENT_ASN1_FUNCTIONS(ASN1_TIME)
|
||||
IMPLEMENT_ASN1_DUP_FUNCTION(ASN1_TIME)
|
||||
|
||||
static int is_utc(const int year)
|
||||
{
|
||||
|
||||
@@ -12,6 +12,9 @@
|
||||
#include "internal/cryptlib.h"
|
||||
#include <openssl/asn1.h>
|
||||
#include "asn1_local.h"
|
||||
#include <openssl/asn1t.h>
|
||||
|
||||
IMPLEMENT_ASN1_DUP_FUNCTION(ASN1_UTCTIME)
|
||||
|
||||
/* This is the primary function used to parse ASN1_UTCTIME */
|
||||
int asn1_utctime_to_tm(struct tm *tm, const ASN1_UTCTIME *d)
|
||||
|
||||
@@ -78,7 +78,7 @@ static ASN1_ITEM_EXP *asn1_item_list[] = {
|
||||
ASN1_ITEM_ref(IPAddressRange),
|
||||
#endif
|
||||
ASN1_ITEM_ref(ISSUING_DIST_POINT),
|
||||
#if !OPENSSL_API_3
|
||||
#ifndef OPENSSL_NO_DEPRECATED_3_0
|
||||
ASN1_ITEM_ref(LONG),
|
||||
#endif
|
||||
ASN1_ITEM_ref(NAME_CONSTRAINTS),
|
||||
@@ -164,7 +164,7 @@ static ASN1_ITEM_EXP *asn1_item_list[] = {
|
||||
ASN1_ITEM_ref(X509_SIG),
|
||||
ASN1_ITEM_ref(X509_VAL),
|
||||
ASN1_ITEM_ref(X509),
|
||||
#if !OPENSSL_API_3
|
||||
#ifndef OPENSSL_NO_DEPRECATED_3_0
|
||||
ASN1_ITEM_ref(ZLONG),
|
||||
#endif
|
||||
ASN1_ITEM_ref(INT32),
|
||||
|
||||
@@ -383,7 +383,7 @@ const unsigned char *ASN1_STRING_get0_data(const ASN1_STRING *x)
|
||||
return x->data;
|
||||
}
|
||||
|
||||
# if !OPENSSL_API_1_1_0
|
||||
# ifndef OPENSSL_NO_DEPRECATED_1_1_0
|
||||
unsigned char *ASN1_STRING_data(ASN1_STRING *x)
|
||||
{
|
||||
return x->data;
|
||||
|
||||
+58
-40
@@ -17,25 +17,44 @@
|
||||
#define ASN1_PARSE_MAXDEPTH 128
|
||||
#endif
|
||||
|
||||
static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed,
|
||||
int indent);
|
||||
static int asn1_parse2(BIO *bp, const unsigned char **pp, long length,
|
||||
int offset, int depth, int indent, int dump);
|
||||
static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed,
|
||||
int indent)
|
||||
static int asn1_print_info(BIO *bp, long offset, int depth, int hl, long len,
|
||||
int tag, int xclass, int constructed, int indent)
|
||||
{
|
||||
static const char fmt[] = "%-18s";
|
||||
char str[128];
|
||||
const char *p;
|
||||
int pop_f_prefix = 0;
|
||||
long saved_indent = -1;
|
||||
int i = 0;
|
||||
|
||||
if (constructed & V_ASN1_CONSTRUCTED)
|
||||
p = "cons: ";
|
||||
else
|
||||
p = "prim: ";
|
||||
if (BIO_write(bp, p, 6) < 6)
|
||||
if (constructed != (V_ASN1_CONSTRUCTED | 1)) {
|
||||
if (BIO_snprintf(str, sizeof(str), "%5ld:d=%-2d hl=%ld l=%4ld %s",
|
||||
offset, depth, (long)hl, len, p) <= 0)
|
||||
goto err;
|
||||
} else {
|
||||
if (BIO_snprintf(str, sizeof(str), "%5ld:d=%-2d hl=%ld l=inf %s",
|
||||
offset, depth, (long)hl, p) <= 0)
|
||||
goto err;
|
||||
}
|
||||
if (BIO_set_prefix(bp, str) <= 0) {
|
||||
if ((bp = BIO_push(BIO_new(BIO_f_prefix()), bp)) == NULL)
|
||||
goto err;
|
||||
pop_f_prefix = 1;
|
||||
}
|
||||
saved_indent = BIO_get_indent(bp);
|
||||
if (BIO_set_prefix(bp, str) <= 0
|
||||
|| BIO_set_indent(bp, indent) < 0)
|
||||
goto err;
|
||||
BIO_indent(bp, indent, 128);
|
||||
|
||||
/*
|
||||
* BIO_set_prefix made a copy of |str|, so we can safely use it for
|
||||
* something else, ASN.1 tag printout.
|
||||
*/
|
||||
p = str;
|
||||
if ((xclass & V_ASN1_PRIVATE) == V_ASN1_PRIVATE)
|
||||
BIO_snprintf(str, sizeof(str), "priv [ %d ] ", tag);
|
||||
@@ -48,11 +67,17 @@ static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed,
|
||||
else
|
||||
p = ASN1_tag2str(tag);
|
||||
|
||||
if (BIO_printf(bp, fmt, p) <= 0)
|
||||
goto err;
|
||||
return 1;
|
||||
i = (BIO_printf(bp, "%-18s", p) > 0);
|
||||
err:
|
||||
return 0;
|
||||
if (saved_indent >= 0)
|
||||
BIO_set_indent(bp, saved_indent);
|
||||
if (pop_f_prefix) {
|
||||
BIO *next = BIO_pop(bp);
|
||||
|
||||
BIO_free(bp);
|
||||
bp = next;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
int ASN1_parse(BIO *bp, const unsigned char *pp, long len, int indent)
|
||||
@@ -75,6 +100,8 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length,
|
||||
int nl, hl, j, r;
|
||||
ASN1_OBJECT *o = NULL;
|
||||
ASN1_OCTET_STRING *os = NULL;
|
||||
ASN1_INTEGER *ai = NULL;
|
||||
ASN1_ENUMERATED *ae = NULL;
|
||||
/* ASN1_BMPSTRING *bmp=NULL; */
|
||||
int dump_indent, dump_cont = 0;
|
||||
|
||||
@@ -100,19 +127,8 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length,
|
||||
/*
|
||||
* if j == 0x21 it is a constructed indefinite length object
|
||||
*/
|
||||
if (BIO_printf(bp, "%5ld:", (long)offset + (long)(op - *pp))
|
||||
<= 0)
|
||||
goto end;
|
||||
|
||||
if (j != (V_ASN1_CONSTRUCTED | 1)) {
|
||||
if (BIO_printf(bp, "d=%-2d hl=%ld l=%4ld ",
|
||||
depth, (long)hl, len) <= 0)
|
||||
goto end;
|
||||
} else {
|
||||
if (BIO_printf(bp, "d=%-2d hl=%ld l=inf ", depth, (long)hl) <= 0)
|
||||
goto end;
|
||||
}
|
||||
if (!asn1_print_info(bp, tag, xclass, j, (indent) ? depth : 0))
|
||||
if (!asn1_print_info(bp, (long)offset + (long)(op - *pp), depth,
|
||||
hl, len, tag, xclass, j, (indent) ? depth : 0))
|
||||
goto end;
|
||||
if (j & V_ASN1_CONSTRUCTED) {
|
||||
const unsigned char *sp = p;
|
||||
@@ -250,22 +266,21 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length,
|
||||
ASN1_OCTET_STRING_free(os);
|
||||
os = NULL;
|
||||
} else if (tag == V_ASN1_INTEGER) {
|
||||
ASN1_INTEGER *bs;
|
||||
int i;
|
||||
|
||||
opp = op;
|
||||
bs = d2i_ASN1_INTEGER(NULL, &opp, len + hl);
|
||||
if (bs != NULL) {
|
||||
ai = d2i_ASN1_INTEGER(NULL, &opp, len + hl);
|
||||
if (ai != NULL) {
|
||||
if (BIO_write(bp, ":", 1) <= 0)
|
||||
goto end;
|
||||
if (bs->type == V_ASN1_NEG_INTEGER)
|
||||
if (ai->type == V_ASN1_NEG_INTEGER)
|
||||
if (BIO_write(bp, "-", 1) <= 0)
|
||||
goto end;
|
||||
for (i = 0; i < bs->length; i++) {
|
||||
if (BIO_printf(bp, "%02X", bs->data[i]) <= 0)
|
||||
for (i = 0; i < ai->length; i++) {
|
||||
if (BIO_printf(bp, "%02X", ai->data[i]) <= 0)
|
||||
goto end;
|
||||
}
|
||||
if (bs->length == 0) {
|
||||
if (ai->length == 0) {
|
||||
if (BIO_write(bp, "00", 2) <= 0)
|
||||
goto end;
|
||||
}
|
||||
@@ -274,24 +289,24 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length,
|
||||
goto end;
|
||||
dump_cont = 1;
|
||||
}
|
||||
ASN1_INTEGER_free(bs);
|
||||
ASN1_INTEGER_free(ai);
|
||||
ai = NULL;
|
||||
} else if (tag == V_ASN1_ENUMERATED) {
|
||||
ASN1_ENUMERATED *bs;
|
||||
int i;
|
||||
|
||||
opp = op;
|
||||
bs = d2i_ASN1_ENUMERATED(NULL, &opp, len + hl);
|
||||
if (bs != NULL) {
|
||||
ae = d2i_ASN1_ENUMERATED(NULL, &opp, len + hl);
|
||||
if (ae != NULL) {
|
||||
if (BIO_write(bp, ":", 1) <= 0)
|
||||
goto end;
|
||||
if (bs->type == V_ASN1_NEG_ENUMERATED)
|
||||
if (ae->type == V_ASN1_NEG_ENUMERATED)
|
||||
if (BIO_write(bp, "-", 1) <= 0)
|
||||
goto end;
|
||||
for (i = 0; i < bs->length; i++) {
|
||||
if (BIO_printf(bp, "%02X", bs->data[i]) <= 0)
|
||||
for (i = 0; i < ae->length; i++) {
|
||||
if (BIO_printf(bp, "%02X", ae->data[i]) <= 0)
|
||||
goto end;
|
||||
}
|
||||
if (bs->length == 0) {
|
||||
if (ae->length == 0) {
|
||||
if (BIO_write(bp, "00", 2) <= 0)
|
||||
goto end;
|
||||
}
|
||||
@@ -300,7 +315,8 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length,
|
||||
goto end;
|
||||
dump_cont = 1;
|
||||
}
|
||||
ASN1_ENUMERATED_free(bs);
|
||||
ASN1_ENUMERATED_free(ae);
|
||||
ae = NULL;
|
||||
} else if (len > 0 && dump) {
|
||||
if (!nl) {
|
||||
if (BIO_write(bp, "\n", 1) <= 0)
|
||||
@@ -341,6 +357,8 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length,
|
||||
end:
|
||||
ASN1_OBJECT_free(o);
|
||||
ASN1_OCTET_STRING_free(os);
|
||||
ASN1_INTEGER_free(ai);
|
||||
ASN1_ENUMERATED_free(ae);
|
||||
*pp = p;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* WARNING: do not edit!
|
||||
* Generated by crypto/asn1/charmap.pl
|
||||
*
|
||||
* Copyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
|
||||
@@ -82,8 +82,8 @@ $arr[ord("?")] |= $PSTRING_CHAR;
|
||||
|
||||
# Now generate the C code
|
||||
|
||||
# Output year depends on the year of the script.
|
||||
my $YEAR = [localtime([stat($0)]->[9])]->[5] + 1900;
|
||||
# Year the file was generated.
|
||||
my $YEAR = [localtime()]->[5] + 1900;
|
||||
print <<EOF;
|
||||
/*
|
||||
* WARNING: do not edit!
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "internal/cryptlib.h"
|
||||
#include <openssl/asn1t.h>
|
||||
|
||||
#if OPENSSL_API_3
|
||||
#ifdef OPENSSL_NO_DEPRECATED_3_0
|
||||
NON_EMPTY_TRANSLATION_UNIT
|
||||
#else
|
||||
|
||||
|
||||
+1
-1
@@ -99,7 +99,7 @@ int encode_der_integer(WPACKET *pkt, const BIGNUM *n)
|
||||
/*
|
||||
* Outputs the DER encoding of a DSA-Sig-Value or ECDSA-Sig-Value to pkt. pkt
|
||||
* may be initialised with a NULL buffer which enables pkt to be used to
|
||||
* calulate how many bytes would be needed.
|
||||
* calculate how many bytes would be needed.
|
||||
*
|
||||
* Returns 1 on success or 0 on error.
|
||||
*/
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* BF low level APIs are deprecated for public use, but still ok for internal
|
||||
* use.
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include <openssl/blowfish.h>
|
||||
#include "bf_local.h"
|
||||
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* BF low level APIs are deprecated for public use, but still ok for internal
|
||||
* use.
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include <openssl/blowfish.h>
|
||||
#include "bf_local.h"
|
||||
#include <openssl/opensslv.h>
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* BF low level APIs are deprecated for public use, but still ok for internal
|
||||
* use.
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include <openssl/blowfish.h>
|
||||
#include "bf_local.h"
|
||||
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* BF low level APIs are deprecated for public use, but still ok for internal
|
||||
* use.
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include <openssl/blowfish.h>
|
||||
#include "bf_local.h"
|
||||
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* BF low level APIs are deprecated for public use, but still ok for internal
|
||||
* use.
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <openssl/blowfish.h>
|
||||
|
||||
+3
-3
@@ -24,7 +24,7 @@
|
||||
static int wsa_init_done = 0;
|
||||
# endif
|
||||
|
||||
# if !OPENSSL_API_1_1_0
|
||||
# ifndef OPENSSL_NO_DEPRECATED_1_1_0
|
||||
int BIO_get_host_ip(const char *str, unsigned char *ip)
|
||||
{
|
||||
BIO_ADDRINFO *res = NULL;
|
||||
@@ -103,7 +103,7 @@ int BIO_sock_error(int sock)
|
||||
return j;
|
||||
}
|
||||
|
||||
# if !OPENSSL_API_1_1_0
|
||||
# ifndef OPENSSL_NO_DEPRECATED_1_1_0
|
||||
struct hostent *BIO_gethostbyname(const char *name)
|
||||
{
|
||||
/*
|
||||
@@ -195,7 +195,7 @@ int BIO_socket_ioctl(int fd, long type, void *arg)
|
||||
return i;
|
||||
}
|
||||
|
||||
# if !OPENSSL_API_1_1_0
|
||||
# ifndef OPENSSL_NO_DEPRECATED_1_1_0
|
||||
int BIO_get_accept_socket(char *host, int bind_mode)
|
||||
{
|
||||
int s = INVALID_SOCKET;
|
||||
|
||||
@@ -0,0 +1,207 @@
|
||||
/*
|
||||
* Copyright 2018-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include "bio_local.h"
|
||||
|
||||
static int prefix_write(BIO *b, const char *out, size_t outl,
|
||||
size_t *numwritten);
|
||||
static int prefix_read(BIO *b, char *buf, size_t size, size_t *numread);
|
||||
static int prefix_puts(BIO *b, const char *str);
|
||||
static int prefix_gets(BIO *b, char *str, int size);
|
||||
static long prefix_ctrl(BIO *b, int cmd, long arg1, void *arg2);
|
||||
static int prefix_create(BIO *b);
|
||||
static int prefix_destroy(BIO *b);
|
||||
static long prefix_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp);
|
||||
|
||||
static const BIO_METHOD prefix_meth = {
|
||||
BIO_TYPE_BUFFER,
|
||||
"prefix",
|
||||
prefix_write,
|
||||
NULL,
|
||||
prefix_read,
|
||||
NULL,
|
||||
prefix_puts,
|
||||
prefix_gets,
|
||||
prefix_ctrl,
|
||||
prefix_create,
|
||||
prefix_destroy,
|
||||
prefix_callback_ctrl,
|
||||
};
|
||||
|
||||
const BIO_METHOD *BIO_f_prefix(void)
|
||||
{
|
||||
return &prefix_meth;
|
||||
}
|
||||
|
||||
typedef struct prefix_ctx_st {
|
||||
char *prefix; /* Text prefix, given by user */
|
||||
unsigned int indent; /* Indentation amount, given by user */
|
||||
|
||||
int linestart; /* flag to indicate we're at the line start */
|
||||
} PREFIX_CTX;
|
||||
|
||||
static int prefix_create(BIO *b)
|
||||
{
|
||||
PREFIX_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
|
||||
|
||||
if (ctx == NULL)
|
||||
return 0;
|
||||
|
||||
ctx->prefix = NULL;
|
||||
ctx->indent = 0;
|
||||
ctx->linestart = 1;
|
||||
BIO_set_data(b, ctx);
|
||||
BIO_set_init(b, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int prefix_destroy(BIO *b)
|
||||
{
|
||||
PREFIX_CTX *ctx = BIO_get_data(b);
|
||||
|
||||
OPENSSL_free(ctx->prefix);
|
||||
OPENSSL_free(ctx);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int prefix_read(BIO *b, char *in, size_t size, size_t *numread)
|
||||
{
|
||||
return BIO_read_ex(BIO_next(b), in, size, numread);
|
||||
}
|
||||
|
||||
static int prefix_write(BIO *b, const char *out, size_t outl,
|
||||
size_t *numwritten)
|
||||
{
|
||||
PREFIX_CTX *ctx = BIO_get_data(b);
|
||||
|
||||
if (ctx == NULL)
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* If no prefix is set or if it's empty, and no indentation amount is set,
|
||||
* we've got nothing to do here
|
||||
*/
|
||||
if ((ctx->prefix == NULL || *ctx->prefix == '\0')
|
||||
&& ctx->indent == 0) {
|
||||
/*
|
||||
* We do note if what comes next will be a new line, though, so we're
|
||||
* prepared to handle prefix and indentation the next time around.
|
||||
*/
|
||||
if (outl > 0)
|
||||
ctx->linestart = (out[outl-1] == '\n');
|
||||
return BIO_write_ex(BIO_next(b), out, outl, numwritten);
|
||||
}
|
||||
|
||||
*numwritten = 0;
|
||||
|
||||
while (outl > 0) {
|
||||
size_t i;
|
||||
char c;
|
||||
|
||||
/*
|
||||
* If we know that we're at the start of the line, output prefix and
|
||||
* indentation.
|
||||
*/
|
||||
if (ctx->linestart) {
|
||||
size_t dontcare;
|
||||
|
||||
if (ctx->prefix != NULL
|
||||
&& !BIO_write_ex(BIO_next(b), ctx->prefix, strlen(ctx->prefix),
|
||||
&dontcare))
|
||||
return 0;
|
||||
BIO_printf(BIO_next(b), "%*s", ctx->indent, "");
|
||||
ctx->linestart = 0;
|
||||
}
|
||||
|
||||
/* Now, go look for the next LF, or the end of the string */
|
||||
for (i = 0, c = '\0'; i < outl && (c = out[i]) != '\n'; i++)
|
||||
continue;
|
||||
if (c == '\n')
|
||||
i++;
|
||||
|
||||
/* Output what we found so far */
|
||||
while (i > 0) {
|
||||
size_t num = 0;
|
||||
|
||||
if (!BIO_write_ex(BIO_next(b), out, i, &num))
|
||||
return 0;
|
||||
out += num;
|
||||
outl -= num;
|
||||
*numwritten += num;
|
||||
i -= num;
|
||||
}
|
||||
|
||||
/* If we found a LF, what follows is a new line, so take note */
|
||||
if (c == '\n')
|
||||
ctx->linestart = 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static long prefix_ctrl(BIO *b, int cmd, long num, void *ptr)
|
||||
{
|
||||
long ret = 0;
|
||||
PREFIX_CTX *ctx = BIO_get_data(b);
|
||||
|
||||
if (ctx == NULL)
|
||||
return -1;
|
||||
|
||||
switch (cmd) {
|
||||
case BIO_CTRL_SET_PREFIX:
|
||||
OPENSSL_free(ctx->prefix);
|
||||
if (ptr == NULL) {
|
||||
ctx->prefix = NULL;
|
||||
ret = 1;
|
||||
} else {
|
||||
ctx->prefix = OPENSSL_strdup((const char *)ptr);
|
||||
ret = ctx->prefix != NULL;
|
||||
}
|
||||
break;
|
||||
case BIO_CTRL_SET_INDENT:
|
||||
if (num >= 0) {
|
||||
ctx->indent = (unsigned int)num;
|
||||
ret = 1;
|
||||
}
|
||||
break;
|
||||
case BIO_CTRL_GET_INDENT:
|
||||
ret = (long)ctx->indent;
|
||||
break;
|
||||
default:
|
||||
/* Commands that we intercept before passing them along */
|
||||
switch (cmd) {
|
||||
case BIO_C_FILE_SEEK:
|
||||
case BIO_CTRL_RESET:
|
||||
ctx->linestart = 1;
|
||||
break;
|
||||
}
|
||||
if (BIO_next(b) != NULL)
|
||||
ret = BIO_ctrl(BIO_next(b), cmd, num, ptr);
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static long prefix_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp)
|
||||
{
|
||||
return BIO_callback_ctrl(BIO_next(b), cmd, fp);
|
||||
}
|
||||
|
||||
static int prefix_gets(BIO *b, char *buf, int size)
|
||||
{
|
||||
return BIO_gets(BIO_next(b), buf, size);
|
||||
}
|
||||
|
||||
static int prefix_puts(BIO *b, const char *str)
|
||||
{
|
||||
return BIO_write(b, str, strlen(str));
|
||||
}
|
||||
@@ -432,7 +432,7 @@ static long acpt_ctrl(BIO *b, int cmd, long num, void *ptr)
|
||||
b->init = 1;
|
||||
} else if (num == 1) {
|
||||
OPENSSL_free(data->param_serv);
|
||||
data->param_serv = BUF_strdup(ptr);
|
||||
data->param_serv = OPENSSL_strdup(ptr);
|
||||
b->init = 1;
|
||||
} else if (num == 2) {
|
||||
data->bind_mode |= BIO_SOCK_NONBLOCK;
|
||||
|
||||
@@ -54,6 +54,7 @@ void BIO_CONNECT_free(BIO_CONNECT *a);
|
||||
#define BIO_CONN_S_CONNECT 4
|
||||
#define BIO_CONN_S_OK 5
|
||||
#define BIO_CONN_S_BLOCKED_CONNECT 6
|
||||
#define BIO_CONN_S_CONNECT_ERROR 7
|
||||
|
||||
static const BIO_METHOD methods_connectp = {
|
||||
BIO_TYPE_CONNECT,
|
||||
@@ -172,7 +173,8 @@ static int conn_state(BIO *b, BIO_CONNECT *c)
|
||||
ERR_raise_data(ERR_LIB_SYS, get_last_socket_error(),
|
||||
"calling connect(%s, %s)",
|
||||
c->param_hostname, c->param_service);
|
||||
BIOerr(BIO_F_CONN_STATE, BIO_R_CONNECT_ERROR);
|
||||
c->state = BIO_CONN_S_CONNECT_ERROR;
|
||||
break;
|
||||
}
|
||||
goto exit_loop;
|
||||
} else {
|
||||
@@ -194,6 +196,11 @@ static int conn_state(BIO *b, BIO_CONNECT *c)
|
||||
c->state = BIO_CONN_S_OK;
|
||||
break;
|
||||
|
||||
case BIO_CONN_S_CONNECT_ERROR:
|
||||
BIOerr(BIO_F_CONN_STATE, BIO_R_CONNECT_ERROR);
|
||||
ret = 0;
|
||||
goto exit_loop;
|
||||
|
||||
case BIO_CONN_S_OK:
|
||||
ret = 1;
|
||||
goto exit_loop;
|
||||
@@ -411,7 +418,7 @@ static long conn_ctrl(BIO *b, int cmd, long num, void *ptr)
|
||||
OPENSSL_free(hold_service);
|
||||
} else if (num == 1) {
|
||||
OPENSSL_free(data->param_service);
|
||||
data->param_service = BUF_strdup(ptr);
|
||||
data->param_service = OPENSSL_strdup(ptr);
|
||||
} else if (num == 2) {
|
||||
const BIO_ADDR *addr = (const BIO_ADDR *)ptr;
|
||||
if (ret) {
|
||||
|
||||
@@ -1009,7 +1009,6 @@ static int dgram_sctp_read(BIO *b, char *out, int outl)
|
||||
int ret = 0, n = 0, i, optval;
|
||||
socklen_t optlen;
|
||||
bio_dgram_sctp_data *data = (bio_dgram_sctp_data *) b->ptr;
|
||||
union sctp_notification *snp;
|
||||
struct msghdr msg;
|
||||
struct iovec iov;
|
||||
struct cmsghdr *cmsg;
|
||||
@@ -1075,8 +1074,10 @@ static int dgram_sctp_read(BIO *b, char *out, int outl)
|
||||
}
|
||||
|
||||
if (msg.msg_flags & MSG_NOTIFICATION) {
|
||||
snp = (union sctp_notification *)out;
|
||||
if (snp->sn_header.sn_type == SCTP_SENDER_DRY_EVENT) {
|
||||
union sctp_notification snp;
|
||||
|
||||
memcpy(&snp, out, sizeof(snp));
|
||||
if (snp.sn_header.sn_type == SCTP_SENDER_DRY_EVENT) {
|
||||
# ifdef SCTP_EVENT
|
||||
struct sctp_event event;
|
||||
# else
|
||||
@@ -1116,17 +1117,19 @@ static int dgram_sctp_read(BIO *b, char *out, int outl)
|
||||
# endif
|
||||
}
|
||||
# ifdef SCTP_AUTHENTICATION_EVENT
|
||||
if (snp->sn_header.sn_type == SCTP_AUTHENTICATION_EVENT)
|
||||
dgram_sctp_handle_auth_free_key_event(b, snp);
|
||||
if (snp.sn_header.sn_type == SCTP_AUTHENTICATION_EVENT)
|
||||
dgram_sctp_handle_auth_free_key_event(b, &snp);
|
||||
# endif
|
||||
|
||||
if (data->handle_notifications != NULL)
|
||||
data->handle_notifications(b, data->notification_context,
|
||||
(void *)out);
|
||||
|
||||
memset(&snp, 0, sizeof(snp));
|
||||
memset(out, 0, outl);
|
||||
} else
|
||||
} else {
|
||||
ret += n;
|
||||
}
|
||||
}
|
||||
while ((msg.msg_flags & MSG_NOTIFICATION) && (msg.msg_flags & MSG_EOR)
|
||||
&& (ret < outl));
|
||||
|
||||
@@ -152,7 +152,11 @@ static long sock_ctrl(BIO *b, int cmd, long num, void *ptr)
|
||||
long ret = 1;
|
||||
int *ip;
|
||||
# ifndef OPENSSL_NO_KTLS
|
||||
# ifdef __FreeBSD__
|
||||
struct tls_enable *crypto_info;
|
||||
# else
|
||||
struct tls12_crypto_info_aes_gcm_128 *crypto_info;
|
||||
# endif
|
||||
# endif
|
||||
|
||||
switch (cmd) {
|
||||
@@ -183,7 +187,11 @@ static long sock_ctrl(BIO *b, int cmd, long num, void *ptr)
|
||||
break;
|
||||
# ifndef OPENSSL_NO_KTLS
|
||||
case BIO_CTRL_SET_KTLS:
|
||||
# ifdef __FreeBSD__
|
||||
crypto_info = (struct tls_enable *)ptr;
|
||||
# else
|
||||
crypto_info = (struct tls12_crypto_info_aes_gcm_128 *)ptr;
|
||||
# endif
|
||||
ret = ktls_start(b->num, crypto_info, sizeof(*crypto_info), num);
|
||||
if (ret)
|
||||
BIO_set_ktls_flag(b, num);
|
||||
|
||||
+15
-5
@@ -1,8 +1,18 @@
|
||||
LIBS=../../libcrypto
|
||||
|
||||
# Base library
|
||||
SOURCE[../../libcrypto]=\
|
||||
bio_lib.c bio_cb.c bio_err.c \
|
||||
bss_mem.c bss_null.c bss_fd.c \
|
||||
bss_file.c bss_sock.c bss_conn.c \
|
||||
bf_null.c bf_buff.c b_print.c b_dump.c b_addr.c \
|
||||
b_sock.c b_sock2.c bss_acpt.c bf_nbio.c bss_log.c bss_bio.c \
|
||||
bss_dgram.c bio_meth.c bf_lbuf.c
|
||||
b_print.c b_dump.c b_addr.c \
|
||||
b_sock.c b_sock2.c \
|
||||
bio_meth.c
|
||||
|
||||
# Source / sink implementations
|
||||
SOURCE[../../libcrypto]=\
|
||||
bss_null.c bss_mem.c bss_bio.c bss_fd.c bss_file.c \
|
||||
bss_sock.c bss_conn.c bss_acpt.c bss_dgram.c \
|
||||
bss_log.c
|
||||
|
||||
# Filters
|
||||
SOURCE[../../libcrypto]=\
|
||||
bf_null.c bf_buff.c bf_lbuf.c bf_nbio.c bf_prefix.c
|
||||
@@ -1,2 +0,0 @@
|
||||
LIBS=../../libcrypto
|
||||
SOURCE[../../libcrypto]=m_blake2b.c m_blake2s.c
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#ifndef OPENSSL_NO_BLAKE2
|
||||
|
||||
# include <stddef.h>
|
||||
# include <openssl/obj_mac.h>
|
||||
# include "crypto/evp.h"
|
||||
# include "prov/blake2.h"
|
||||
|
||||
static int init(EVP_MD_CTX *ctx)
|
||||
{
|
||||
return blake2b512_init(EVP_MD_CTX_md_data(ctx));
|
||||
}
|
||||
|
||||
static int update(EVP_MD_CTX *ctx, const void *data, size_t count)
|
||||
{
|
||||
return blake2b_update(EVP_MD_CTX_md_data(ctx), data, count);
|
||||
}
|
||||
|
||||
static int final(EVP_MD_CTX *ctx, unsigned char *md)
|
||||
{
|
||||
return blake2b_final(md, EVP_MD_CTX_md_data(ctx));
|
||||
}
|
||||
|
||||
static const EVP_MD blake2b_md = {
|
||||
NID_blake2b512,
|
||||
0,
|
||||
BLAKE2B_DIGEST_LENGTH,
|
||||
0,
|
||||
init,
|
||||
update,
|
||||
final,
|
||||
NULL,
|
||||
NULL,
|
||||
BLAKE2B_BLOCKBYTES,
|
||||
sizeof(BLAKE2B_CTX),
|
||||
};
|
||||
|
||||
const EVP_MD *EVP_blake2b512(void)
|
||||
{
|
||||
return &blake2b_md;
|
||||
}
|
||||
#endif /* OPENSSL_NO_BLAKE2 */
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#ifndef OPENSSL_NO_BLAKE2
|
||||
|
||||
# include <stddef.h>
|
||||
# include <openssl/obj_mac.h>
|
||||
# include "crypto/evp.h"
|
||||
# include "prov/blake2.h"
|
||||
|
||||
static int init(EVP_MD_CTX *ctx)
|
||||
{
|
||||
return blake2s256_init(EVP_MD_CTX_md_data(ctx));
|
||||
}
|
||||
|
||||
static int update(EVP_MD_CTX *ctx, const void *data, size_t count)
|
||||
{
|
||||
return blake2s_update(EVP_MD_CTX_md_data(ctx), data, count);
|
||||
}
|
||||
|
||||
static int final(EVP_MD_CTX *ctx, unsigned char *md)
|
||||
{
|
||||
return blake2s_final(md, EVP_MD_CTX_md_data(ctx));
|
||||
}
|
||||
|
||||
static const EVP_MD blake2s_md = {
|
||||
NID_blake2s256,
|
||||
0,
|
||||
BLAKE2S_DIGEST_LENGTH,
|
||||
0,
|
||||
init,
|
||||
update,
|
||||
final,
|
||||
NULL,
|
||||
NULL,
|
||||
BLAKE2S_BLOCKBYTES,
|
||||
sizeof(BLAKE2S_CTX),
|
||||
};
|
||||
|
||||
const EVP_MD *EVP_blake2s256(void)
|
||||
{
|
||||
return &blake2s_md;
|
||||
}
|
||||
#endif /* OPENSSL_NO_BLAKE2 */
|
||||
@@ -67,7 +67,7 @@ if (!$avx && $win64 && ($flavour =~ /masm/ || $ENV{ASM} =~ /ml64/) &&
|
||||
$addx = ($1>=11);
|
||||
}
|
||||
|
||||
if (!$avx && `$ENV{CC} -v 2>&1` =~ /((?:^clang|LLVM) version|based on LLVM) ([3-9])\.([0-9]+)/) {
|
||||
if (!$avx && `$ENV{CC} -v 2>&1` =~ /((?:^clang|LLVM) version|based on LLVM) ([0-9]+)\.([0-9]+)/) {
|
||||
my $ver = $2 + $3/100.0; # 3.1->3.01, 3.10->3.10
|
||||
$avx = ($ver>=3.0) + ($ver>=3.01);
|
||||
$addx = ($ver>=3.03);
|
||||
|
||||
+216
-189
@@ -83,7 +83,7 @@ if (!$addx && $win64 && ($flavour =~ /masm/ || $ENV{ASM} =~ /ml64/) &&
|
||||
$addx = ($1>=12);
|
||||
}
|
||||
|
||||
if (!$addx && `$ENV{CC} -v 2>&1` =~ /((?:^clang|LLVM) version|.*based on LLVM) ([3-9])\.([0-9]+)/) {
|
||||
if (!$addx && `$ENV{CC} -v 2>&1` =~ /((?:^clang|LLVM) version|.*based on LLVM) ([0-9]+)\.([0-9]+)/) {
|
||||
my $ver = $2 + $3/100.0; # 3.1->3.01, 3.10->3.10
|
||||
$addx = ($ver>=3.03);
|
||||
}
|
||||
@@ -118,7 +118,7 @@ rsaz_512_sqr: # 25-29% faster than rsaz_512_mul
|
||||
subq \$128+24, %rsp
|
||||
.cfi_adjust_cfa_offset 128+24
|
||||
.Lsqr_body:
|
||||
movq $mod, %rbp # common argument
|
||||
movq $mod, %xmm1 # common off-load
|
||||
movq ($inp), %rdx
|
||||
movq 8($inp), %rax
|
||||
movq $n0, 128(%rsp)
|
||||
@@ -136,7 +136,8 @@ $code.=<<___;
|
||||
.Loop_sqr:
|
||||
movl $times,128+8(%rsp)
|
||||
#first iteration
|
||||
movq %rdx, %rbx
|
||||
movq %rdx, %rbx # 0($inp)
|
||||
mov %rax, %rbp # 8($inp)
|
||||
mulq %rdx
|
||||
movq %rax, %r8
|
||||
movq 16($inp), %rax
|
||||
@@ -175,31 +176,29 @@ $code.=<<___;
|
||||
mulq %rbx
|
||||
addq %rax, %r14
|
||||
movq %rbx, %rax
|
||||
movq %rdx, %r15
|
||||
adcq \$0, %r15
|
||||
adcq \$0, %rdx
|
||||
|
||||
addq %r8, %r8 #shlq \$1, %r8
|
||||
movq %r9, %rcx
|
||||
adcq %r9, %r9 #shld \$1, %r8, %r9
|
||||
xorq %rcx,%rcx # rcx:r8 = r8 << 1
|
||||
addq %r8, %r8
|
||||
movq %rdx, %r15
|
||||
adcq \$0, %rcx
|
||||
|
||||
mulq %rax
|
||||
movq %rax, (%rsp)
|
||||
addq %rdx, %r8
|
||||
adcq \$0, %r9
|
||||
addq %r8, %rdx
|
||||
adcq \$0, %rcx
|
||||
|
||||
movq %r8, 8(%rsp)
|
||||
shrq \$63, %rcx
|
||||
movq %rax, (%rsp)
|
||||
movq %rdx, 8(%rsp)
|
||||
|
||||
#second iteration
|
||||
movq 8($inp), %r8
|
||||
movq 16($inp), %rax
|
||||
mulq %r8
|
||||
mulq %rbp
|
||||
addq %rax, %r10
|
||||
movq 24($inp), %rax
|
||||
movq %rdx, %rbx
|
||||
adcq \$0, %rbx
|
||||
|
||||
mulq %r8
|
||||
mulq %rbp
|
||||
addq %rax, %r11
|
||||
movq 32($inp), %rax
|
||||
adcq \$0, %rdx
|
||||
@@ -207,7 +206,7 @@ $code.=<<___;
|
||||
movq %rdx, %rbx
|
||||
adcq \$0, %rbx
|
||||
|
||||
mulq %r8
|
||||
mulq %rbp
|
||||
addq %rax, %r12
|
||||
movq 40($inp), %rax
|
||||
adcq \$0, %rdx
|
||||
@@ -215,7 +214,7 @@ $code.=<<___;
|
||||
movq %rdx, %rbx
|
||||
adcq \$0, %rbx
|
||||
|
||||
mulq %r8
|
||||
mulq %rbp
|
||||
addq %rax, %r13
|
||||
movq 48($inp), %rax
|
||||
adcq \$0, %rdx
|
||||
@@ -223,7 +222,7 @@ $code.=<<___;
|
||||
movq %rdx, %rbx
|
||||
adcq \$0, %rbx
|
||||
|
||||
mulq %r8
|
||||
mulq %rbp
|
||||
addq %rax, %r14
|
||||
movq 56($inp), %rax
|
||||
adcq \$0, %rdx
|
||||
@@ -231,39 +230,39 @@ $code.=<<___;
|
||||
movq %rdx, %rbx
|
||||
adcq \$0, %rbx
|
||||
|
||||
mulq %r8
|
||||
mulq %rbp
|
||||
addq %rax, %r15
|
||||
movq %r8, %rax
|
||||
movq %rbp, %rax
|
||||
adcq \$0, %rdx
|
||||
addq %rbx, %r15
|
||||
movq %rdx, %r8
|
||||
movq %r10, %rdx
|
||||
adcq \$0, %r8
|
||||
adcq \$0, %rdx
|
||||
|
||||
add %rdx, %rdx
|
||||
lea (%rcx,%r10,2), %r10 #shld \$1, %rcx, %r10
|
||||
movq %r11, %rbx
|
||||
adcq %r11, %r11 #shld \$1, %r10, %r11
|
||||
xorq %rbx, %rbx # rbx:r10:r9 = r10:r9 << 1
|
||||
addq %r9, %r9
|
||||
movq %rdx, %r8
|
||||
adcq %r10, %r10
|
||||
adcq \$0, %rbx
|
||||
|
||||
mulq %rax
|
||||
# rcx <= 2 and rax <= 0xFFFF..F9, so carry must be zero here
|
||||
addq %rcx, %rax
|
||||
movq 16($inp), %rbp
|
||||
addq %rax, %r9
|
||||
movq 24($inp), %rax
|
||||
adcq %rdx, %r10
|
||||
adcq \$0, %r11
|
||||
adcq \$0, %rbx
|
||||
|
||||
movq %r9, 16(%rsp)
|
||||
movq %r10, 24(%rsp)
|
||||
shrq \$63, %rbx
|
||||
|
||||
#third iteration
|
||||
movq 16($inp), %r9
|
||||
movq 24($inp), %rax
|
||||
mulq %r9
|
||||
mulq %rbp
|
||||
addq %rax, %r12
|
||||
movq 32($inp), %rax
|
||||
movq %rdx, %rcx
|
||||
adcq \$0, %rcx
|
||||
|
||||
mulq %r9
|
||||
mulq %rbp
|
||||
addq %rax, %r13
|
||||
movq 40($inp), %rax
|
||||
adcq \$0, %rdx
|
||||
@@ -271,7 +270,7 @@ $code.=<<___;
|
||||
movq %rdx, %rcx
|
||||
adcq \$0, %rcx
|
||||
|
||||
mulq %r9
|
||||
mulq %rbp
|
||||
addq %rax, %r14
|
||||
movq 48($inp), %rax
|
||||
adcq \$0, %rdx
|
||||
@@ -279,9 +278,7 @@ $code.=<<___;
|
||||
movq %rdx, %rcx
|
||||
adcq \$0, %rcx
|
||||
|
||||
mulq %r9
|
||||
movq %r12, %r10
|
||||
lea (%rbx,%r12,2), %r12 #shld \$1, %rbx, %r12
|
||||
mulq %rbp
|
||||
addq %rax, %r15
|
||||
movq 56($inp), %rax
|
||||
adcq \$0, %rdx
|
||||
@@ -289,36 +286,40 @@ $code.=<<___;
|
||||
movq %rdx, %rcx
|
||||
adcq \$0, %rcx
|
||||
|
||||
mulq %r9
|
||||
shrq \$63, %r10
|
||||
mulq %rbp
|
||||
addq %rax, %r8
|
||||
movq %r9, %rax
|
||||
movq %rbp, %rax
|
||||
adcq \$0, %rdx
|
||||
addq %rcx, %r8
|
||||
movq %rdx, %r9
|
||||
adcq \$0, %r9
|
||||
adcq \$0, %rdx
|
||||
|
||||
movq %r13, %rcx
|
||||
leaq (%r10,%r13,2), %r13 #shld \$1, %r12, %r13
|
||||
xorq %rcx, %rcx # rcx:r12:r11 = r12:r11 << 1
|
||||
addq %r11, %r11
|
||||
movq %rdx, %r9
|
||||
adcq %r12, %r12
|
||||
adcq \$0, %rcx
|
||||
|
||||
mulq %rax
|
||||
# rbx <= 2 and rax <= 0xFFFF..F9, so carry must be zero here
|
||||
addq %rbx, %rax
|
||||
movq 24($inp), %r10
|
||||
addq %rax, %r11
|
||||
movq 32($inp), %rax
|
||||
adcq %rdx, %r12
|
||||
adcq \$0, %r13
|
||||
adcq \$0, %rcx
|
||||
|
||||
movq %r11, 32(%rsp)
|
||||
movq %r12, 40(%rsp)
|
||||
shrq \$63, %rcx
|
||||
|
||||
#fourth iteration
|
||||
movq 24($inp), %r10
|
||||
movq 32($inp), %rax
|
||||
mov %rax, %r11 # 32($inp)
|
||||
mulq %r10
|
||||
addq %rax, %r14
|
||||
movq 40($inp), %rax
|
||||
movq %rdx, %rbx
|
||||
adcq \$0, %rbx
|
||||
|
||||
mov %rax, %r12 # 40($inp)
|
||||
mulq %r10
|
||||
addq %rax, %r15
|
||||
movq 48($inp), %rax
|
||||
@@ -327,9 +328,8 @@ $code.=<<___;
|
||||
movq %rdx, %rbx
|
||||
adcq \$0, %rbx
|
||||
|
||||
mov %rax, %rbp # 48($inp)
|
||||
mulq %r10
|
||||
movq %r14, %r12
|
||||
leaq (%rcx,%r14,2), %r14 #shld \$1, %rcx, %r14
|
||||
addq %rax, %r8
|
||||
movq 56($inp), %rax
|
||||
adcq \$0, %rdx
|
||||
@@ -338,32 +338,33 @@ $code.=<<___;
|
||||
adcq \$0, %rbx
|
||||
|
||||
mulq %r10
|
||||
shrq \$63, %r12
|
||||
addq %rax, %r9
|
||||
movq %r10, %rax
|
||||
adcq \$0, %rdx
|
||||
addq %rbx, %r9
|
||||
movq %rdx, %r10
|
||||
adcq \$0, %r10
|
||||
adcq \$0, %rdx
|
||||
|
||||
movq %r15, %rbx
|
||||
leaq (%r12,%r15,2),%r15 #shld \$1, %r14, %r15
|
||||
xorq %rbx, %rbx # rbx:r13:r14 = r13:r14 << 1
|
||||
addq %r13, %r13
|
||||
movq %rdx, %r10
|
||||
adcq %r14, %r14
|
||||
adcq \$0, %rbx
|
||||
|
||||
mulq %rax
|
||||
# rcx <= 2 and rax <= 0xFFFF..F9, so carry must be zero here
|
||||
addq %rcx, %rax
|
||||
addq %rax, %r13
|
||||
movq %r12, %rax # 40($inp)
|
||||
adcq %rdx, %r14
|
||||
adcq \$0, %r15
|
||||
adcq \$0, %rbx
|
||||
|
||||
movq %r13, 48(%rsp)
|
||||
movq %r14, 56(%rsp)
|
||||
shrq \$63, %rbx
|
||||
|
||||
#fifth iteration
|
||||
movq 32($inp), %r11
|
||||
movq 40($inp), %rax
|
||||
mulq %r11
|
||||
addq %rax, %r8
|
||||
movq 48($inp), %rax
|
||||
movq %rbp, %rax # 48($inp)
|
||||
movq %rdx, %rcx
|
||||
adcq \$0, %rcx
|
||||
|
||||
@@ -371,97 +372,99 @@ $code.=<<___;
|
||||
addq %rax, %r9
|
||||
movq 56($inp), %rax
|
||||
adcq \$0, %rdx
|
||||
movq %r8, %r12
|
||||
leaq (%rbx,%r8,2), %r8 #shld \$1, %rbx, %r8
|
||||
addq %rcx, %r9
|
||||
movq %rdx, %rcx
|
||||
adcq \$0, %rcx
|
||||
|
||||
mov %rax, %r14 # 56($inp)
|
||||
mulq %r11
|
||||
shrq \$63, %r12
|
||||
addq %rax, %r10
|
||||
movq %r11, %rax
|
||||
adcq \$0, %rdx
|
||||
addq %rcx, %r10
|
||||
movq %rdx, %r11
|
||||
adcq \$0, %r11
|
||||
adcq \$0, %rdx
|
||||
|
||||
movq %r9, %rcx
|
||||
leaq (%r12,%r9,2), %r9 #shld \$1, %r8, %r9
|
||||
xorq %rcx, %rcx # rcx:r8:r15 = r8:r15 << 1
|
||||
addq %r15, %r15
|
||||
movq %rdx, %r11
|
||||
adcq %r8, %r8
|
||||
adcq \$0, %rcx
|
||||
|
||||
mulq %rax
|
||||
# rbx <= 2 and rax <= 0xFFFF..F9, so carry must be zero here
|
||||
addq %rbx, %rax
|
||||
addq %rax, %r15
|
||||
movq %rbp, %rax # 48($inp)
|
||||
adcq %rdx, %r8
|
||||
adcq \$0, %r9
|
||||
adcq \$0, %rcx
|
||||
|
||||
movq %r15, 64(%rsp)
|
||||
movq %r8, 72(%rsp)
|
||||
shrq \$63, %rcx
|
||||
|
||||
#sixth iteration
|
||||
movq 40($inp), %r12
|
||||
movq 48($inp), %rax
|
||||
mulq %r12
|
||||
addq %rax, %r10
|
||||
movq 56($inp), %rax
|
||||
movq %r14, %rax # 56($inp)
|
||||
movq %rdx, %rbx
|
||||
adcq \$0, %rbx
|
||||
|
||||
mulq %r12
|
||||
addq %rax, %r11
|
||||
movq %r12, %rax
|
||||
movq %r10, %r15
|
||||
leaq (%rcx,%r10,2), %r10 #shld \$1, %rcx, %r10
|
||||
adcq \$0, %rdx
|
||||
shrq \$63, %r15
|
||||
addq %rbx, %r11
|
||||
movq %rdx, %r12
|
||||
adcq \$0, %r12
|
||||
adcq \$0, %rdx
|
||||
|
||||
movq %r11, %rbx
|
||||
leaq (%r15,%r11,2), %r11 #shld \$1, %r10, %r11
|
||||
xorq %rbx, %rbx # rbx:r10:r9 = r10:r9 << 1
|
||||
addq %r9, %r9
|
||||
movq %rdx, %r12
|
||||
adcq %r10, %r10
|
||||
adcq \$0, %rbx
|
||||
|
||||
mulq %rax
|
||||
# rcx <= 2 and rax <= 0xFFFF..F9, so carry must be zero here
|
||||
addq %rcx, %rax
|
||||
addq %rax, %r9
|
||||
movq %r14, %rax # 56($inp)
|
||||
adcq %rdx, %r10
|
||||
adcq \$0, %r11
|
||||
adcq \$0, %rbx
|
||||
|
||||
movq %r9, 80(%rsp)
|
||||
movq %r10, 88(%rsp)
|
||||
|
||||
#seventh iteration
|
||||
movq 48($inp), %r13
|
||||
movq 56($inp), %rax
|
||||
mulq %r13
|
||||
mulq %rbp
|
||||
addq %rax, %r12
|
||||
movq %r13, %rax
|
||||
movq %rdx, %r13
|
||||
adcq \$0, %r13
|
||||
movq %rbp, %rax
|
||||
adcq \$0, %rdx
|
||||
|
||||
xorq %r14, %r14
|
||||
shlq \$1, %rbx
|
||||
adcq %r12, %r12 #shld \$1, %rbx, %r12
|
||||
adcq %r13, %r13 #shld \$1, %r12, %r13
|
||||
adcq %r14, %r14 #shld \$1, %r13, %r14
|
||||
xorq %rcx, %rcx # rcx:r12:r11 = r12:r11 << 1
|
||||
addq %r11, %r11
|
||||
movq %rdx, %r13
|
||||
adcq %r12, %r12
|
||||
adcq \$0, %rcx
|
||||
|
||||
mulq %rax
|
||||
# rbx <= 2 and rax <= 0xFFFF..F9, so carry must be zero here
|
||||
addq %rbx, %rax
|
||||
addq %rax, %r11
|
||||
movq %r14, %rax # 56($inp)
|
||||
adcq %rdx, %r12
|
||||
adcq \$0, %r13
|
||||
adcq \$0, %rcx
|
||||
|
||||
movq %r11, 96(%rsp)
|
||||
movq %r12, 104(%rsp)
|
||||
|
||||
#eighth iteration
|
||||
movq 56($inp), %rax
|
||||
xorq %rbx, %rbx # rbx:r13 = r13 << 1
|
||||
addq %r13, %r13
|
||||
adcq \$0, %rbx
|
||||
|
||||
mulq %rax
|
||||
addq %rax, %r13
|
||||
adcq \$0, %rdx
|
||||
|
||||
addq %rdx, %r14
|
||||
|
||||
movq %r13, 112(%rsp)
|
||||
movq %r14, 120(%rsp)
|
||||
# rcx <= 2 and rax <= 0xFFFF..F9, so carry must be zero here
|
||||
addq %rcx, %rax
|
||||
addq %r13, %rax
|
||||
adcq %rbx, %rdx
|
||||
|
||||
movq (%rsp), %r8
|
||||
movq 8(%rsp), %r9
|
||||
@@ -471,6 +474,10 @@ $code.=<<___;
|
||||
movq 40(%rsp), %r13
|
||||
movq 48(%rsp), %r14
|
||||
movq 56(%rsp), %r15
|
||||
movq %xmm1, %rbp
|
||||
|
||||
movq %rax, 112(%rsp)
|
||||
movq %rdx, 120(%rsp)
|
||||
|
||||
call __rsaz_512_reduce
|
||||
|
||||
@@ -502,9 +509,9 @@ $code.=<<___;
|
||||
.Loop_sqrx:
|
||||
movl $times,128+8(%rsp)
|
||||
movq $out, %xmm0 # off-load
|
||||
movq %rbp, %xmm1 # off-load
|
||||
#first iteration
|
||||
mulx %rax, %r8, %r9
|
||||
mov %rax, %rbx
|
||||
|
||||
mulx 16($inp), %rcx, %r10
|
||||
xor %rbp, %rbp # cf=0, of=0
|
||||
@@ -512,40 +519,39 @@ $code.=<<___;
|
||||
mulx 24($inp), %rax, %r11
|
||||
adcx %rcx, %r9
|
||||
|
||||
mulx 32($inp), %rcx, %r12
|
||||
.byte 0xc4,0x62,0xf3,0xf6,0xa6,0x20,0x00,0x00,0x00 # mulx 32($inp), %rcx, %r12
|
||||
adcx %rax, %r10
|
||||
|
||||
mulx 40($inp), %rax, %r13
|
||||
.byte 0xc4,0x62,0xfb,0xf6,0xae,0x28,0x00,0x00,0x00 # mulx 40($inp), %rax, %r13
|
||||
adcx %rcx, %r11
|
||||
|
||||
.byte 0xc4,0x62,0xf3,0xf6,0xb6,0x30,0x00,0x00,0x00 # mulx 48($inp), %rcx, %r14
|
||||
mulx 48($inp), %rcx, %r14
|
||||
adcx %rax, %r12
|
||||
adcx %rcx, %r13
|
||||
|
||||
.byte 0xc4,0x62,0xfb,0xf6,0xbe,0x38,0x00,0x00,0x00 # mulx 56($inp), %rax, %r15
|
||||
mulx 56($inp), %rax, %r15
|
||||
adcx %rax, %r14
|
||||
adcx %rbp, %r15 # %rbp is 0
|
||||
|
||||
mov %r9, %rcx
|
||||
shld \$1, %r8, %r9
|
||||
shl \$1, %r8
|
||||
|
||||
xor %ebp, %ebp
|
||||
mulx %rdx, %rax, %rdx
|
||||
adcx %rdx, %r8
|
||||
mov 8($inp), %rdx
|
||||
adcx %rbp, %r9
|
||||
mulx %rdx, %rax, $out
|
||||
mov %rbx, %rdx # 8($inp)
|
||||
xor %rcx, %rcx
|
||||
adox %r8, %r8
|
||||
adcx $out, %r8
|
||||
adox %rbp, %rcx
|
||||
adcx %rbp, %rcx
|
||||
|
||||
mov %rax, (%rsp)
|
||||
mov %r8, 8(%rsp)
|
||||
|
||||
#second iteration
|
||||
mulx 16($inp), %rax, %rbx
|
||||
.byte 0xc4,0xe2,0xfb,0xf6,0x9e,0x10,0x00,0x00,0x00 # mulx 16($inp), %rax, %rbx
|
||||
adox %rax, %r10
|
||||
adcx %rbx, %r11
|
||||
|
||||
.byte 0xc4,0x62,0xc3,0xf6,0x86,0x18,0x00,0x00,0x00 # mulx 24($inp), $out, %r8
|
||||
mulx 24($inp), $out, %r8
|
||||
adox $out, %r11
|
||||
.byte 0x66
|
||||
adcx %r8, %r12
|
||||
|
||||
mulx 32($inp), %rax, %rbx
|
||||
@@ -563,24 +569,25 @@ $code.=<<___;
|
||||
.byte 0xc4,0x62,0xc3,0xf6,0x86,0x38,0x00,0x00,0x00 # mulx 56($inp), $out, %r8
|
||||
adox $out, %r15
|
||||
adcx %rbp, %r8
|
||||
mulx %rdx, %rax, $out
|
||||
adox %rbp, %r8
|
||||
.byte 0x48,0x8b,0x96,0x10,0x00,0x00,0x00 # mov 16($inp), %rdx
|
||||
|
||||
mov %r11, %rbx
|
||||
shld \$1, %r10, %r11
|
||||
shld \$1, %rcx, %r10
|
||||
|
||||
xor %ebp,%ebp
|
||||
mulx %rdx, %rax, %rcx
|
||||
mov 16($inp), %rdx
|
||||
xor %rbx, %rbx
|
||||
adox %r9, %r9
|
||||
# rcx <= 2 and rax <= 0xFFFF..F9, so carry must be zero here
|
||||
adcx %rcx, %rax
|
||||
adox %r10, %r10
|
||||
adcx %rax, %r9
|
||||
adcx %rcx, %r10
|
||||
adcx %rbp, %r11
|
||||
adox %rbp, %rbx
|
||||
adcx $out, %r10
|
||||
adcx %rbp, %rbx
|
||||
|
||||
mov %r9, 16(%rsp)
|
||||
.byte 0x4c,0x89,0x94,0x24,0x18,0x00,0x00,0x00 # mov %r10, 24(%rsp)
|
||||
|
||||
#third iteration
|
||||
.byte 0xc4,0x62,0xc3,0xf6,0x8e,0x18,0x00,0x00,0x00 # mulx 24($inp), $out, %r9
|
||||
mulx 24($inp), $out, %r9
|
||||
adox $out, %r12
|
||||
adcx %r9, %r13
|
||||
|
||||
@@ -588,7 +595,7 @@ $code.=<<___;
|
||||
adox %rax, %r13
|
||||
adcx %rcx, %r14
|
||||
|
||||
mulx 40($inp), $out, %r9
|
||||
.byte 0xc4,0x62,0xc3,0xf6,0x8e,0x28,0x00,0x00,0x00 # mulx 40($inp), $out, %r9
|
||||
adox $out, %r14
|
||||
adcx %r9, %r15
|
||||
|
||||
@@ -596,27 +603,28 @@ $code.=<<___;
|
||||
adox %rax, %r15
|
||||
adcx %rcx, %r8
|
||||
|
||||
.byte 0xc4,0x62,0xc3,0xf6,0x8e,0x38,0x00,0x00,0x00 # mulx 56($inp), $out, %r9
|
||||
mulx 56($inp), $out, %r9
|
||||
adox $out, %r8
|
||||
adcx %rbp, %r9
|
||||
mulx %rdx, %rax, $out
|
||||
adox %rbp, %r9
|
||||
|
||||
mov %r13, %rcx
|
||||
shld \$1, %r12, %r13
|
||||
shld \$1, %rbx, %r12
|
||||
|
||||
xor %ebp, %ebp
|
||||
mulx %rdx, %rax, %rdx
|
||||
adcx %rax, %r11
|
||||
adcx %rdx, %r12
|
||||
mov 24($inp), %rdx
|
||||
adcx %rbp, %r13
|
||||
|
||||
xor %rcx, %rcx
|
||||
adox %r11, %r11
|
||||
# rbx <= 2 and rax <= 0xFFFF..F9, so carry must be zero here
|
||||
adcx %rbx, %rax
|
||||
adox %r12, %r12
|
||||
adcx %rax, %r11
|
||||
adox %rbp, %rcx
|
||||
adcx $out, %r12
|
||||
adcx %rbp, %rcx
|
||||
|
||||
mov %r11, 32(%rsp)
|
||||
.byte 0x4c,0x89,0xa4,0x24,0x28,0x00,0x00,0x00 # mov %r12, 40(%rsp)
|
||||
mov %r12, 40(%rsp)
|
||||
|
||||
#fourth iteration
|
||||
.byte 0xc4,0xe2,0xfb,0xf6,0x9e,0x20,0x00,0x00,0x00 # mulx 32($inp), %rax, %rbx
|
||||
mulx 32($inp), %rax, %rbx
|
||||
adox %rax, %r14
|
||||
adcx %rbx, %r15
|
||||
|
||||
@@ -631,25 +639,25 @@ $code.=<<___;
|
||||
mulx 56($inp), $out, %r10
|
||||
adox $out, %r9
|
||||
adcx %rbp, %r10
|
||||
mulx %rdx, %rax, $out
|
||||
adox %rbp, %r10
|
||||
|
||||
.byte 0x66
|
||||
mov %r15, %rbx
|
||||
shld \$1, %r14, %r15
|
||||
shld \$1, %rcx, %r14
|
||||
|
||||
xor %ebp, %ebp
|
||||
mulx %rdx, %rax, %rdx
|
||||
adcx %rax, %r13
|
||||
adcx %rdx, %r14
|
||||
mov 32($inp), %rdx
|
||||
adcx %rbp, %r15
|
||||
|
||||
xor %rbx, %rbx
|
||||
adox %r13, %r13
|
||||
# rcx <= 2 and rax <= 0xFFFF..F9, so carry must be zero here
|
||||
adcx %rcx, %rax
|
||||
adox %r14, %r14
|
||||
adcx %rax, %r13
|
||||
adox %rbp, %rbx
|
||||
adcx $out, %r14
|
||||
adcx %rbp, %rbx
|
||||
|
||||
mov %r13, 48(%rsp)
|
||||
mov %r14, 56(%rsp)
|
||||
|
||||
#fifth iteration
|
||||
.byte 0xc4,0x62,0xc3,0xf6,0x9e,0x28,0x00,0x00,0x00 # mulx 40($inp), $out, %r11
|
||||
mulx 40($inp), $out, %r11
|
||||
adox $out, %r8
|
||||
adcx %r11, %r9
|
||||
|
||||
@@ -660,18 +668,19 @@ $code.=<<___;
|
||||
mulx 56($inp), $out, %r11
|
||||
adox $out, %r10
|
||||
adcx %rbp, %r11
|
||||
mulx %rdx, %rax, $out
|
||||
mov 40($inp), %rdx
|
||||
adox %rbp, %r11
|
||||
|
||||
mov %r9, %rcx
|
||||
shld \$1, %r8, %r9
|
||||
shld \$1, %rbx, %r8
|
||||
|
||||
xor %ebp, %ebp
|
||||
mulx %rdx, %rax, %rdx
|
||||
xor %rcx, %rcx
|
||||
adox %r15, %r15
|
||||
# rbx <= 2 and rax <= 0xFFFF..F9, so carry must be zero here
|
||||
adcx %rbx, %rax
|
||||
adox %r8, %r8
|
||||
adcx %rax, %r15
|
||||
adcx %rdx, %r8
|
||||
mov 40($inp), %rdx
|
||||
adcx %rbp, %r9
|
||||
adox %rbp, %rcx
|
||||
adcx $out, %r8
|
||||
adcx %rbp, %rcx
|
||||
|
||||
mov %r15, 64(%rsp)
|
||||
mov %r8, 72(%rsp)
|
||||
@@ -684,18 +693,19 @@ $code.=<<___;
|
||||
.byte 0xc4,0x62,0xc3,0xf6,0xa6,0x38,0x00,0x00,0x00 # mulx 56($inp), $out, %r12
|
||||
adox $out, %r11
|
||||
adcx %rbp, %r12
|
||||
mulx %rdx, %rax, $out
|
||||
adox %rbp, %r12
|
||||
|
||||
mov %r11, %rbx
|
||||
shld \$1, %r10, %r11
|
||||
shld \$1, %rcx, %r10
|
||||
|
||||
xor %ebp, %ebp
|
||||
mulx %rdx, %rax, %rdx
|
||||
adcx %rax, %r9
|
||||
adcx %rdx, %r10
|
||||
mov 48($inp), %rdx
|
||||
adcx %rbp, %r11
|
||||
|
||||
xor %rbx, %rbx
|
||||
adox %r9, %r9
|
||||
# rcx <= 2 and rax <= 0xFFFF..F9, so carry must be zero here
|
||||
adcx %rcx, %rax
|
||||
adox %r10, %r10
|
||||
adcx %rax, %r9
|
||||
adcx $out, %r10
|
||||
adox %rbp, %rbx
|
||||
adcx %rbp, %rbx
|
||||
|
||||
mov %r9, 80(%rsp)
|
||||
mov %r10, 88(%rsp)
|
||||
@@ -705,31 +715,31 @@ $code.=<<___;
|
||||
adox %rax, %r12
|
||||
adox %rbp, %r13
|
||||
|
||||
xor %r14, %r14
|
||||
shld \$1, %r13, %r14
|
||||
shld \$1, %r12, %r13
|
||||
shld \$1, %rbx, %r12
|
||||
|
||||
xor %ebp, %ebp
|
||||
mulx %rdx, %rax, %rdx
|
||||
adcx %rax, %r11
|
||||
adcx %rdx, %r12
|
||||
mulx %rdx, %rax, $out
|
||||
xor %rcx, %rcx
|
||||
mov 56($inp), %rdx
|
||||
adcx %rbp, %r13
|
||||
adox %r11, %r11
|
||||
# rbx <= 2 and rax <= 0xFFFF..F9, so carry must be zero here
|
||||
adcx %rbx, %rax
|
||||
adox %r12, %r12
|
||||
adcx %rax, %r11
|
||||
adox %rbp, %rcx
|
||||
adcx $out, %r12
|
||||
adcx %rbp, %rcx
|
||||
|
||||
.byte 0x4c,0x89,0x9c,0x24,0x60,0x00,0x00,0x00 # mov %r11, 96(%rsp)
|
||||
.byte 0x4c,0x89,0xa4,0x24,0x68,0x00,0x00,0x00 # mov %r12, 104(%rsp)
|
||||
|
||||
#eighth iteration
|
||||
mulx %rdx, %rax, %rdx
|
||||
adox %rax, %r13
|
||||
adox %rbp, %rdx
|
||||
xor %rbx, %rbx
|
||||
adox %r13, %r13
|
||||
# rcx <= 2 and rax <= 0xFFFF..F9, so carry must be zero here
|
||||
adcx %rcx, %rax
|
||||
adox %rbp, %rbx
|
||||
adcx %r13, %rax
|
||||
adcx %rdx, %rbx
|
||||
|
||||
.byte 0x66
|
||||
add %rdx, %r14
|
||||
|
||||
movq %r13, 112(%rsp)
|
||||
movq %r14, 120(%rsp)
|
||||
movq %xmm0, $out
|
||||
movq %xmm1, %rbp
|
||||
|
||||
@@ -743,6 +753,9 @@ $code.=<<___;
|
||||
movq 48(%rsp), %r14
|
||||
movq 56(%rsp), %r15
|
||||
|
||||
movq %rax, 112(%rsp)
|
||||
movq %rbx, 120(%rsp)
|
||||
|
||||
call __rsaz_512_reducex
|
||||
|
||||
addq 64(%rsp), %r8
|
||||
@@ -1608,6 +1621,7 @@ $code.=<<___;
|
||||
.type __rsaz_512_reduce,\@abi-omnipotent
|
||||
.align 32
|
||||
__rsaz_512_reduce:
|
||||
.cfi_startproc
|
||||
movq %r8, %rbx
|
||||
imulq 128+8(%rsp), %rbx
|
||||
movq 0(%rbp), %rax
|
||||
@@ -1687,6 +1701,7 @@ __rsaz_512_reduce:
|
||||
jne .Lreduction_loop
|
||||
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size __rsaz_512_reduce,.-__rsaz_512_reduce
|
||||
___
|
||||
}
|
||||
@@ -1700,6 +1715,7 @@ $code.=<<___;
|
||||
.type __rsaz_512_reducex,\@abi-omnipotent
|
||||
.align 32
|
||||
__rsaz_512_reducex:
|
||||
.cfi_startproc
|
||||
#movq 128+8(%rsp), %rdx # pull $n0
|
||||
imulq %r8, %rdx
|
||||
xorq %rsi, %rsi # cf=0,of=0
|
||||
@@ -1752,6 +1768,7 @@ __rsaz_512_reducex:
|
||||
jne .Lreduction_loopx
|
||||
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size __rsaz_512_reducex,.-__rsaz_512_reducex
|
||||
___
|
||||
}
|
||||
@@ -1763,6 +1780,7 @@ $code.=<<___;
|
||||
.type __rsaz_512_subtract,\@abi-omnipotent
|
||||
.align 32
|
||||
__rsaz_512_subtract:
|
||||
.cfi_startproc
|
||||
movq %r8, ($out)
|
||||
movq %r9, 8($out)
|
||||
movq %r10, 16($out)
|
||||
@@ -1816,6 +1834,7 @@ __rsaz_512_subtract:
|
||||
movq %r15, 56($out)
|
||||
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size __rsaz_512_subtract,.-__rsaz_512_subtract
|
||||
___
|
||||
}
|
||||
@@ -1829,6 +1848,7 @@ $code.=<<___;
|
||||
.type __rsaz_512_mul,\@abi-omnipotent
|
||||
.align 32
|
||||
__rsaz_512_mul:
|
||||
.cfi_startproc
|
||||
leaq 8(%rsp), %rdi
|
||||
|
||||
movq ($ap), %rax
|
||||
@@ -1967,6 +1987,7 @@ __rsaz_512_mul:
|
||||
movq %r15, 56(%rdi)
|
||||
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size __rsaz_512_mul,.-__rsaz_512_mul
|
||||
___
|
||||
}
|
||||
@@ -1981,6 +2002,7 @@ $code.=<<___;
|
||||
.type __rsaz_512_mulx,\@abi-omnipotent
|
||||
.align 32
|
||||
__rsaz_512_mulx:
|
||||
.cfi_startproc
|
||||
mulx ($ap), %rbx, %r8 # initial %rdx preloaded by caller
|
||||
mov \$-6, %rcx
|
||||
|
||||
@@ -2097,6 +2119,7 @@ __rsaz_512_mulx:
|
||||
mov %r15, 8+64+56(%rsp)
|
||||
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size __rsaz_512_mulx,.-__rsaz_512_mulx
|
||||
___
|
||||
}
|
||||
@@ -2107,6 +2130,7 @@ $code.=<<___;
|
||||
.type rsaz_512_scatter4,\@abi-omnipotent
|
||||
.align 16
|
||||
rsaz_512_scatter4:
|
||||
.cfi_startproc
|
||||
leaq ($out,$power,8), $out
|
||||
movl \$8, %r9d
|
||||
jmp .Loop_scatter
|
||||
@@ -2119,12 +2143,14 @@ rsaz_512_scatter4:
|
||||
decl %r9d
|
||||
jnz .Loop_scatter
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size rsaz_512_scatter4,.-rsaz_512_scatter4
|
||||
|
||||
.globl rsaz_512_gather4
|
||||
.type rsaz_512_gather4,\@abi-omnipotent
|
||||
.align 16
|
||||
rsaz_512_gather4:
|
||||
.cfi_startproc
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
.LSEH_begin_rsaz_512_gather4:
|
||||
@@ -2219,6 +2245,7 @@ ___
|
||||
$code.=<<___;
|
||||
ret
|
||||
.LSEH_end_rsaz_512_gather4:
|
||||
.cfi_endproc
|
||||
.size rsaz_512_gather4,.-rsaz_512_gather4
|
||||
|
||||
.align 64
|
||||
|
||||
@@ -147,7 +147,7 @@ $code.=<<___;
|
||||
lghi $NHI,0
|
||||
alcgr $NHI,$nhi
|
||||
|
||||
la $j,8(%r0) # j=1
|
||||
la $j,8 # j=1
|
||||
lr $count,$num
|
||||
|
||||
.align 16
|
||||
@@ -199,7 +199,7 @@ $code.=<<___;
|
||||
lghi $NHI,0
|
||||
alcgr $NHI,$nhi
|
||||
|
||||
la $j,8(%r0) # j=1
|
||||
la $j,8 # j=1
|
||||
lr $count,$num
|
||||
|
||||
.align 16
|
||||
@@ -243,7 +243,7 @@ $code.=<<___;
|
||||
la $ap,$stdframe($sp)
|
||||
ahi $num,1 # restore $num, incidentally clears "borrow"
|
||||
|
||||
la $j,0(%r0)
|
||||
la $j,0
|
||||
lr $count,$num
|
||||
.Lsub: lg $alo,0($j,$ap)
|
||||
lg $nlo,0($j,$np)
|
||||
@@ -257,7 +257,7 @@ $code.=<<___;
|
||||
lghi $NHI,-1
|
||||
xgr $NHI,$AHI
|
||||
|
||||
la $j,0(%r0)
|
||||
la $j,0
|
||||
lgr $count,$num
|
||||
.Lcopy: lg $ahi,$stdframe($j,$sp) # conditional copy
|
||||
lg $alo,0($j,$rp)
|
||||
|
||||
@@ -511,7 +511,7 @@ bn_mul_comba4:
|
||||
lghi zero,0
|
||||
|
||||
mul_add_c(0,0,c1,c2,c3);
|
||||
stg c1,0*8(%r3)
|
||||
stg c1,0*8(%r2)
|
||||
lghi c1,0
|
||||
|
||||
mul_add_c(0,1,c2,c3,c1);
|
||||
|
||||
@@ -77,7 +77,7 @@ if (!$addx && $win64 && ($flavour =~ /masm/ || $ENV{ASM} =~ /ml64/) &&
|
||||
$addx = ($1>=12);
|
||||
}
|
||||
|
||||
if (!$addx && `$ENV{CC} -v 2>&1` =~ /((?:^clang|LLVM) version|.*based on LLVM) ([3-9])\.([0-9]+)/) {
|
||||
if (!$addx && `$ENV{CC} -v 2>&1` =~ /((?:^clang|LLVM) version|.*based on LLVM) ([0-9]+)\.([0-9]+)/) {
|
||||
my $ver = $2 + $3/100.0; # 3.1->3.01, 3.10->3.10
|
||||
$addx = ($ver>=3.03);
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ if (!$addx && $win64 && ($flavour =~ /masm/ || $ENV{ASM} =~ /ml64/) &&
|
||||
$addx = ($1>=12);
|
||||
}
|
||||
|
||||
if (!$addx && `$ENV{CC} -v 2>&1` =~ /((?:^clang|LLVM) version|.*based on LLVM) ([3-9])\.([0-9]+)/) {
|
||||
if (!$addx && `$ENV{CC} -v 2>&1` =~ /((?:^clang|LLVM) version|.*based on LLVM) ([0-9]+)\.([0-9]+)/) {
|
||||
my $ver = $2 + $3/100.0; # 3.1->3.01, 3.10->3.10
|
||||
$addx = ($ver>=3.03);
|
||||
}
|
||||
@@ -582,6 +582,7 @@ $code.=<<___;
|
||||
.type mul4x_internal,\@abi-omnipotent
|
||||
.align 32
|
||||
mul4x_internal:
|
||||
.cfi_startproc
|
||||
shl \$5,$num # $num was in bytes
|
||||
movd `($win64?56:8)`(%rax),%xmm5 # load 7th argument, index
|
||||
lea .Linc(%rip),%rax
|
||||
@@ -1076,6 +1077,7 @@ $code.=<<___
|
||||
___
|
||||
}
|
||||
$code.=<<___;
|
||||
.cfi_endproc
|
||||
.size mul4x_internal,.-mul4x_internal
|
||||
___
|
||||
}}}
|
||||
@@ -1241,6 +1243,7 @@ $code.=<<___;
|
||||
.align 32
|
||||
bn_sqr8x_internal:
|
||||
__bn_sqr8x_internal:
|
||||
.cfi_startproc
|
||||
##############################################################
|
||||
# Squaring part:
|
||||
#
|
||||
@@ -2032,6 +2035,7 @@ __bn_sqr8x_reduction:
|
||||
cmp %rdx,$tptr # end of t[]?
|
||||
jb .L8x_reduction_loop
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size bn_sqr8x_internal,.-bn_sqr8x_internal
|
||||
___
|
||||
}
|
||||
@@ -2044,6 +2048,7 @@ $code.=<<___;
|
||||
.type __bn_post4x_internal,\@abi-omnipotent
|
||||
.align 32
|
||||
__bn_post4x_internal:
|
||||
.cfi_startproc
|
||||
mov 8*0($nptr),%r12
|
||||
lea (%rdi,$num),$tptr # %rdi was $tptr above
|
||||
mov $num,%rcx
|
||||
@@ -2094,6 +2099,7 @@ __bn_post4x_internal:
|
||||
mov $num,%r10 # prepare for back-to-back call
|
||||
neg $num # restore $num
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size __bn_post4x_internal,.-__bn_post4x_internal
|
||||
___
|
||||
}
|
||||
@@ -2103,10 +2109,12 @@ $code.=<<___;
|
||||
.type bn_from_montgomery,\@abi-omnipotent
|
||||
.align 32
|
||||
bn_from_montgomery:
|
||||
.cfi_startproc
|
||||
testl \$7,`($win64?"48(%rsp)":"%r9d")`
|
||||
jz bn_from_mont8x
|
||||
xor %eax,%eax
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size bn_from_montgomery,.-bn_from_montgomery
|
||||
|
||||
.type bn_from_mont8x,\@function,6
|
||||
@@ -2402,6 +2410,7 @@ bn_mulx4x_mont_gather5:
|
||||
.type mulx4x_internal,\@abi-omnipotent
|
||||
.align 32
|
||||
mulx4x_internal:
|
||||
.cfi_startproc
|
||||
mov $num,8(%rsp) # save -$num (it was in bytes)
|
||||
mov $num,%r10
|
||||
neg $num # restore $num
|
||||
@@ -2752,6 +2761,7 @@ $code.=<<___;
|
||||
mov 8*2(%rbp),%r14
|
||||
mov 8*3(%rbp),%r15
|
||||
jmp .Lsqrx4x_sub_entry # common post-condition
|
||||
.cfi_endproc
|
||||
.size mulx4x_internal,.-mulx4x_internal
|
||||
___
|
||||
}{
|
||||
@@ -3557,6 +3567,7 @@ my ($rptr,$nptr)=("%rdx","%rbp");
|
||||
$code.=<<___;
|
||||
.align 32
|
||||
__bn_postx4x_internal:
|
||||
.cfi_startproc
|
||||
mov 8*0($nptr),%r12
|
||||
mov %rcx,%r10 # -$num
|
||||
mov %rcx,%r9 # -$num
|
||||
@@ -3604,6 +3615,7 @@ __bn_postx4x_internal:
|
||||
neg %r9 # restore $num
|
||||
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size __bn_postx4x_internal,.-__bn_postx4x_internal
|
||||
___
|
||||
}
|
||||
@@ -3620,6 +3632,7 @@ $code.=<<___;
|
||||
.type bn_get_bits5,\@abi-omnipotent
|
||||
.align 16
|
||||
bn_get_bits5:
|
||||
.cfi_startproc
|
||||
lea 0($inp),%r10
|
||||
lea 1($inp),%r11
|
||||
mov $num,%ecx
|
||||
@@ -3633,12 +3646,14 @@ bn_get_bits5:
|
||||
shrl %cl,%eax
|
||||
and \$31,%eax
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size bn_get_bits5,.-bn_get_bits5
|
||||
|
||||
.globl bn_scatter5
|
||||
.type bn_scatter5,\@abi-omnipotent
|
||||
.align 16
|
||||
bn_scatter5:
|
||||
.cfi_startproc
|
||||
cmp \$0, $num
|
||||
jz .Lscatter_epilogue
|
||||
lea ($tbl,$idx,8),$tbl
|
||||
@@ -3651,6 +3666,7 @@ bn_scatter5:
|
||||
jnz .Lscatter
|
||||
.Lscatter_epilogue:
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size bn_scatter5,.-bn_scatter5
|
||||
|
||||
.globl bn_gather5
|
||||
@@ -3658,6 +3674,7 @@ bn_scatter5:
|
||||
.align 32
|
||||
bn_gather5:
|
||||
.LSEH_begin_bn_gather5: # Win64 thing, but harmless in other cases
|
||||
.cfi_startproc
|
||||
# I can't trust assembler to use specific encoding:-(
|
||||
.byte 0x4c,0x8d,0x14,0x24 #lea (%rsp),%r10
|
||||
.byte 0x48,0x81,0xec,0x08,0x01,0x00,0x00 #sub $0x108,%rsp
|
||||
@@ -3742,6 +3759,7 @@ $code.=<<___;
|
||||
lea (%r10),%rsp
|
||||
ret
|
||||
.LSEH_end_bn_gather5:
|
||||
.cfi_endproc
|
||||
.size bn_gather5,.-bn_gather5
|
||||
___
|
||||
}
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@
|
||||
*/
|
||||
|
||||
#include <openssl/opensslconf.h>
|
||||
#if OPENSSL_API_0_9_8
|
||||
#ifdef OPENSSL_NO_DEPRECATED_0_9_8
|
||||
NON_EMPTY_TRANSLATION_UNIT
|
||||
#else
|
||||
|
||||
|
||||
+7
-2
@@ -593,7 +593,9 @@ int BN_gcd(BIGNUM *r, const BIGNUM *in_a, const BIGNUM *in_b, BN_CTX *ctx)
|
||||
|
||||
for (i = 0; i < m; i++) {
|
||||
/* conditionally flip signs if delta is positive and g is odd */
|
||||
cond = (-delta >> (8 * sizeof(delta) - 1)) & g->d[0] & 1;
|
||||
cond = (-delta >> (8 * sizeof(delta) - 1)) & g->d[0] & 1
|
||||
/* make sure g->top > 0 (i.e. if top == 0 then g == 0 always) */
|
||||
& (~((g->top - 1) >> (sizeof(g->top) * 8 - 1)));
|
||||
delta = (-cond & -delta) | ((cond - 1) & delta);
|
||||
r->neg ^= cond;
|
||||
/* swap */
|
||||
@@ -603,7 +605,10 @@ int BN_gcd(BIGNUM *r, const BIGNUM *in_a, const BIGNUM *in_b, BN_CTX *ctx)
|
||||
delta++;
|
||||
if (!BN_add(temp, g, r))
|
||||
goto err;
|
||||
BN_consttime_swap(g->d[0] & 1, g, temp, top);
|
||||
BN_consttime_swap(g->d[0] & 1 /* g is odd */
|
||||
/* make sure g->top > 0 (i.e. if top == 0 then g == 0 always) */
|
||||
& (~((g->top - 1) >> (sizeof(g->top) * 8 - 1))),
|
||||
g, temp, top);
|
||||
if (!BN_rshift1(g, g))
|
||||
goto err;
|
||||
}
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
#include "internal/constant_time.h"
|
||||
|
||||
/* This stuff appears to be completely unused, so is deprecated */
|
||||
#if !OPENSSL_API_0_9_8
|
||||
#ifndef OPENSSL_NO_DEPRECATED_0_9_8
|
||||
/*-
|
||||
* For a 32 bit machine
|
||||
* 2 - 4 == 128
|
||||
|
||||
@@ -224,7 +224,7 @@ int BN_generate_prime_ex(BIGNUM *ret, int bits, int safe,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !OPENSSL_API_3
|
||||
#ifndef OPENSSL_NO_DEPRECATED_3_0
|
||||
int BN_is_prime_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed,
|
||||
BN_GENCB *cb)
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* WARNING: do not edit!
|
||||
* Generated by crypto/bn/bn_prime.pl
|
||||
*
|
||||
* Copyright 1998-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1998-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
# in the file LICENSE in the source distribution or at
|
||||
# https://www.openssl.org/source/license.html
|
||||
|
||||
# Output year depends on the year of the script.
|
||||
my $YEAR = [localtime([stat($0)]->[9])]->[5] + 1900;
|
||||
# The year the output file is generated.
|
||||
my $YEAR = [localtime()]->[5] + 1900;
|
||||
print <<"EOF";
|
||||
/*
|
||||
* WARNING: do not edit!
|
||||
|
||||
@@ -31,6 +31,27 @@
|
||||
#include <openssl/bn.h>
|
||||
#include "bn_local.h"
|
||||
#include "crypto/bn.h"
|
||||
#include "internal/nelem.h"
|
||||
|
||||
#if BN_BITS2 == 64
|
||||
# define BN_DEF(lo, hi) (BN_ULONG)hi<<32|lo
|
||||
#else
|
||||
# define BN_DEF(lo, hi) lo, hi
|
||||
#endif
|
||||
|
||||
/* 1 / sqrt(2) * 2^256, rounded up */
|
||||
static const BN_ULONG inv_sqrt_2_val[] = {
|
||||
BN_DEF(0x83339916UL, 0xED17AC85UL), BN_DEF(0x893BA84CUL, 0x1D6F60BAUL),
|
||||
BN_DEF(0x754ABE9FUL, 0x597D89B3UL), BN_DEF(0xF9DE6484UL, 0xB504F333UL)
|
||||
};
|
||||
|
||||
const BIGNUM bn_inv_sqrt_2 = {
|
||||
(BN_ULONG *)inv_sqrt_2_val,
|
||||
OSSL_NELEM(inv_sqrt_2_val),
|
||||
OSSL_NELEM(inv_sqrt_2_val),
|
||||
0,
|
||||
BN_FLG_STATIC_DATA
|
||||
};
|
||||
|
||||
/*
|
||||
* FIPS 186-4 Table B.1. "Min length of auxiliary primes p1, p2, q1, q2".
|
||||
@@ -221,9 +242,12 @@ int bn_rsa_fips186_4_derive_prime(BIGNUM *Y, BIGNUM *X, const BIGNUM *Xin,
|
||||
int i, imax;
|
||||
int bits = nlen >> 1;
|
||||
BIGNUM *tmp, *R, *r1r2x2, *y1, *r1x2;
|
||||
BIGNUM *base, *range;
|
||||
|
||||
BN_CTX_start(ctx);
|
||||
|
||||
base = BN_CTX_get(ctx);
|
||||
range = BN_CTX_get(ctx);
|
||||
R = BN_CTX_get(ctx);
|
||||
tmp = BN_CTX_get(ctx);
|
||||
r1r2x2 = BN_CTX_get(ctx);
|
||||
@@ -235,6 +259,24 @@ int bn_rsa_fips186_4_derive_prime(BIGNUM *Y, BIGNUM *X, const BIGNUM *Xin,
|
||||
if (Xin != NULL && BN_copy(X, Xin) == NULL)
|
||||
goto err;
|
||||
|
||||
/*
|
||||
* We need to generate a random number X in the range
|
||||
* 1/sqrt(2) * 2^(nlen/2) <= X < 2^(nlen/2).
|
||||
* We can rewrite that as:
|
||||
* base = 1/sqrt(2) * 2^(nlen/2)
|
||||
* range = ((2^(nlen/2))) - (1/sqrt(2) * 2^(nlen/2))
|
||||
* X = base + random(range)
|
||||
* We only have the first 256 bit of 1/sqrt(2)
|
||||
*/
|
||||
if (Xin == NULL) {
|
||||
if (bits < BN_num_bits(&bn_inv_sqrt_2))
|
||||
goto err;
|
||||
if (!BN_lshift(base, &bn_inv_sqrt_2, bits - BN_num_bits(&bn_inv_sqrt_2))
|
||||
|| !BN_lshift(range, BN_value_one(), bits)
|
||||
|| !BN_sub(range, range, base))
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!(BN_lshift1(r1x2, r1)
|
||||
/* (Step 1) GCD(2r1, r2) = 1 */
|
||||
&& BN_gcd(tmp, r1x2, r2, ctx)
|
||||
@@ -257,16 +299,9 @@ int bn_rsa_fips186_4_derive_prime(BIGNUM *Y, BIGNUM *X, const BIGNUM *Xin,
|
||||
if (Xin == NULL) {
|
||||
/*
|
||||
* (Step 3) Choose Random X such that
|
||||
* sqrt(2) * 2^(nlen/2-1) < Random X < (2^(nlen/2)) - 1.
|
||||
*
|
||||
* For the lower bound:
|
||||
* sqrt(2) * 2^(nlen/2 - 1) == sqrt(2)/2 * 2^(nlen/2)
|
||||
* where sqrt(2)/2 = 0.70710678.. = 0.B504FC33F9DE...
|
||||
* so largest number will have B5... as the top byte
|
||||
* Setting the top 2 bits gives 0xC0.
|
||||
* sqrt(2) * 2^(nlen/2-1) <= Random X <= (2^(nlen/2)) - 1.
|
||||
*/
|
||||
if (!BN_priv_rand_ex(X, bits, BN_RAND_TOP_TWO, BN_RAND_BOTTOM_ANY,
|
||||
ctx))
|
||||
if (!BN_priv_rand_range_ex(X, range, ctx) || !BN_add(X, X, base))
|
||||
goto end;
|
||||
}
|
||||
/* (Step 4) Y = X + ((R - X) mod 2r1r2) */
|
||||
|
||||
+10
-13
@@ -34,12 +34,10 @@ int BN_lshift1(BIGNUM *r, const BIGNUM *a)
|
||||
for (i = 0; i < a->top; i++) {
|
||||
t = *(ap++);
|
||||
*(rp++) = ((t << 1) | c) & BN_MASK2;
|
||||
c = (t & BN_TBIT) ? 1 : 0;
|
||||
}
|
||||
if (c) {
|
||||
*rp = 1;
|
||||
r->top++;
|
||||
c = t >> (BN_BITS2 - 1);
|
||||
}
|
||||
*rp = c;
|
||||
r->top += c;
|
||||
bn_check_top(r);
|
||||
return 1;
|
||||
}
|
||||
@@ -47,7 +45,7 @@ int BN_lshift1(BIGNUM *r, const BIGNUM *a)
|
||||
int BN_rshift1(BIGNUM *r, const BIGNUM *a)
|
||||
{
|
||||
BN_ULONG *ap, *rp, t, c;
|
||||
int i, j;
|
||||
int i;
|
||||
|
||||
bn_check_top(r);
|
||||
bn_check_top(a);
|
||||
@@ -58,23 +56,22 @@ int BN_rshift1(BIGNUM *r, const BIGNUM *a)
|
||||
}
|
||||
i = a->top;
|
||||
ap = a->d;
|
||||
j = i - (ap[i - 1] == 1);
|
||||
if (a != r) {
|
||||
if (bn_wexpand(r, j) == NULL)
|
||||
if (bn_wexpand(r, i) == NULL)
|
||||
return 0;
|
||||
r->neg = a->neg;
|
||||
}
|
||||
rp = r->d;
|
||||
r->top = i;
|
||||
t = ap[--i];
|
||||
c = (t & 1) ? BN_TBIT : 0;
|
||||
if (t >>= 1)
|
||||
rp[i] = t;
|
||||
rp[i] = t >> 1;
|
||||
c = t << (BN_BITS2 - 1);
|
||||
r->top -= (t == 1);
|
||||
while (i > 0) {
|
||||
t = ap[--i];
|
||||
rp[i] = ((t >> 1) & BN_MASK2) | c;
|
||||
c = (t & 1) ? BN_TBIT : 0;
|
||||
c = t << (BN_BITS2 - 1);
|
||||
}
|
||||
r->top = j;
|
||||
if (!r->top)
|
||||
r->neg = 0; /* don't allow negative zero */
|
||||
bn_check_top(r);
|
||||
|
||||
+6
-5
@@ -1,11 +1,11 @@
|
||||
# Note that these directories are filtered in Configure. Look for %skipdir
|
||||
# there for further explanations.
|
||||
SUBDIRS=objects buffer bio stack lhash rand evp asn1 pem x509 conf \
|
||||
txt_db pkcs7 pkcs12 ui store property \
|
||||
md2 md4 md5 sha mdc2 hmac ripemd whrlpool poly1305 blake2 \
|
||||
txt_db pkcs7 pkcs12 ui kdf store property \
|
||||
md2 md4 md5 sha mdc2 hmac ripemd whrlpool poly1305 \
|
||||
siphash sm3 des aes rc2 rc4 rc5 idea aria bf cast camellia \
|
||||
seed sm4 chacha modes bn ec rsa dsa dh sm2 dso engine \
|
||||
err comp ocsp cms ts srp cmac ct async ess crmf cmp
|
||||
err comp ocsp cms ts srp cmac ct async ess crmf cmp serializer
|
||||
|
||||
LIBS=../libcrypto
|
||||
|
||||
@@ -62,7 +62,7 @@ ENDIF
|
||||
$CORE_COMMON=provider_core.c provider_predefined.c \
|
||||
core_fetch.c core_algorithm.c core_namemap.c
|
||||
|
||||
SOURCE[../libcrypto]=$CORE_COMMON provider_conf.c
|
||||
SOURCE[../libcrypto]=$CORE_COMMON provider_conf.c self_test_core.c
|
||||
SOURCE[../providers/libfips.a]=$CORE_COMMON
|
||||
|
||||
# Central utilities
|
||||
@@ -73,7 +73,7 @@ $UTIL_COMMON=\
|
||||
$UTIL_DEFINE=$CPUIDDEF
|
||||
|
||||
SOURCE[../libcrypto]=$UTIL_COMMON \
|
||||
mem.c mem_sec.c mem_dbg.c \
|
||||
mem.c mem_sec.c \
|
||||
cversion.c info.c cpt_err.c ebcdic.c uid.c o_time.c o_dir.c \
|
||||
o_fopen.c getenv.c o_init.c o_fips.c init.c trace.c provider.c \
|
||||
$UPLINKSRC
|
||||
@@ -85,6 +85,7 @@ DEFINE[../libcrypto]=$UTIL_DEFINE $UPLINKDEF
|
||||
DEFINE[../providers/libfips.a]=$UTIL_DEFINE
|
||||
DEFINE[../providers/fips]=$UTIL_DEFINE
|
||||
DEFINE[../providers/libimplementations.a]=$UTIL_DEFINE
|
||||
DEFINE[../providers/libcommon.a]=$UTIL_DEFINE
|
||||
|
||||
DEPEND[info.o]=buildinf.h
|
||||
DEPEND[cversion.o]=buildinf.h
|
||||
|
||||
@@ -127,11 +127,13 @@ $code=<<___;
|
||||
.type Camellia_EncryptBlock,\@abi-omnipotent
|
||||
.align 16
|
||||
Camellia_EncryptBlock:
|
||||
.cfi_startproc
|
||||
movl \$128,%eax
|
||||
subl $arg0d,%eax
|
||||
movl \$3,$arg0d
|
||||
adcl \$0,$arg0d # keyBitLength==128?3:4
|
||||
jmp .Lenc_rounds
|
||||
.cfi_endproc
|
||||
.size Camellia_EncryptBlock,.-Camellia_EncryptBlock
|
||||
# V2
|
||||
.globl Camellia_EncryptBlock_Rounds
|
||||
@@ -200,6 +202,7 @@ Camellia_EncryptBlock_Rounds:
|
||||
.type _x86_64_Camellia_encrypt,\@abi-omnipotent
|
||||
.align 16
|
||||
_x86_64_Camellia_encrypt:
|
||||
.cfi_startproc
|
||||
xor 0($key),@S[1]
|
||||
xor 4($key),@S[0] # ^=key[0-3]
|
||||
xor 8($key),@S[3]
|
||||
@@ -243,6 +246,7 @@ $code.=<<___;
|
||||
mov $t3,@S[3]
|
||||
|
||||
.byte 0xf3,0xc3 # rep ret
|
||||
.cfi_endproc
|
||||
.size _x86_64_Camellia_encrypt,.-_x86_64_Camellia_encrypt
|
||||
|
||||
# V1.x API
|
||||
@@ -250,11 +254,13 @@ $code.=<<___;
|
||||
.type Camellia_DecryptBlock,\@abi-omnipotent
|
||||
.align 16
|
||||
Camellia_DecryptBlock:
|
||||
.cfi_startproc
|
||||
movl \$128,%eax
|
||||
subl $arg0d,%eax
|
||||
movl \$3,$arg0d
|
||||
adcl \$0,$arg0d # keyBitLength==128?3:4
|
||||
jmp .Ldec_rounds
|
||||
.cfi_endproc
|
||||
.size Camellia_DecryptBlock,.-Camellia_DecryptBlock
|
||||
# V2
|
||||
.globl Camellia_DecryptBlock_Rounds
|
||||
@@ -323,6 +329,7 @@ Camellia_DecryptBlock_Rounds:
|
||||
.type _x86_64_Camellia_decrypt,\@abi-omnipotent
|
||||
.align 16
|
||||
_x86_64_Camellia_decrypt:
|
||||
.cfi_startproc
|
||||
xor 0($key),@S[1]
|
||||
xor 4($key),@S[0] # ^=key[0-3]
|
||||
xor 8($key),@S[3]
|
||||
@@ -367,6 +374,7 @@ $code.=<<___;
|
||||
mov $t1,@S[3]
|
||||
|
||||
.byte 0xf3,0xc3 # rep ret
|
||||
.cfi_endproc
|
||||
.size _x86_64_Camellia_decrypt,.-_x86_64_Camellia_decrypt
|
||||
___
|
||||
|
||||
|
||||
@@ -10,10 +10,12 @@ IF[{- !$disabled{asm} -}]
|
||||
# appropriate one
|
||||
IF[$CMLLASM_{- $target{asm_arch} -}]
|
||||
$CMLLASM=$CMLLASM_{- $target{asm_arch} -}
|
||||
$CMLLDEF=CMLL_ASM
|
||||
ENDIF
|
||||
ENDIF
|
||||
|
||||
SOURCE[../../libcrypto]=cmll_ecb.c cmll_ofb.c cmll_cfb.c cmll_ctr.c $CMLLASM
|
||||
DEFINE[../../libcrypto]=$CMLLDEF
|
||||
|
||||
GENERATE[cmll-x86.s]=asm/cmll-x86.pl
|
||||
DEPEND[cmll-x86.s]=../perlasm/x86asm.pl
|
||||
|
||||
@@ -39,6 +39,12 @@
|
||||
* words reasonable performance even with not so modern compilers.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Camellia low level APIs are deprecated for public use, but still ok for
|
||||
* internal use.
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include <openssl/camellia.h>
|
||||
#include "cmll_local.h"
|
||||
#include <string.h>
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* Camellia low level APIs are deprecated for public use, but still ok for
|
||||
* internal use.
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include <openssl/camellia.h>
|
||||
#include <openssl/modes.h>
|
||||
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* Camellia low level APIs are deprecated for public use, but still ok for
|
||||
* internal use.
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include <openssl/camellia.h>
|
||||
#include <openssl/modes.h>
|
||||
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* Camellia low level APIs are deprecated for public use, but still ok for
|
||||
* internal use.
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include <openssl/camellia.h>
|
||||
#include <openssl/modes.h>
|
||||
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* Camellia low level APIs are deprecated for public use, but still ok for
|
||||
* internal use.
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include <openssl/camellia.h>
|
||||
#include "cmll_local.h"
|
||||
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* Camellia low level APIs are deprecated for public use, but still ok for
|
||||
* internal use.
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include <openssl/opensslv.h>
|
||||
#include <openssl/camellia.h>
|
||||
#include "cmll_local.h"
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* Camellia low level APIs are deprecated for public use, but still ok for
|
||||
* internal use.
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include <openssl/camellia.h>
|
||||
#include <openssl/modes.h>
|
||||
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* CAST low level APIs are deprecated for public use, but still ok for
|
||||
* internal use.
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include <openssl/cast.h>
|
||||
#include "cast_local.h"
|
||||
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* CAST low level APIs are deprecated for public use, but still ok for
|
||||
* internal use.
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include <openssl/cast.h>
|
||||
#include "cast_local.h"
|
||||
#include <openssl/opensslv.h>
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* CAST low level APIs are deprecated for public use, but still ok for
|
||||
* internal use.
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include <openssl/cast.h>
|
||||
#include "cast_local.h"
|
||||
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* CAST low level APIs are deprecated for public use, but still ok for
|
||||
* internal use.
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include <openssl/cast.h>
|
||||
#include "cast_local.h"
|
||||
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* CAST low level APIs are deprecated for public use, but still ok for
|
||||
* internal use.
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include <openssl/cast.h>
|
||||
#include "cast_local.h"
|
||||
#include "cast_s.h"
|
||||
|
||||
@@ -1232,8 +1232,7 @@ $code.=<<___;
|
||||
adds $len,$len,#512
|
||||
ushr $ONE,$ONE,#1 // 4 -> 2
|
||||
|
||||
ldp d8,d9,[sp,#128+0] // meet ABI requirements
|
||||
ldp d10,d11,[sp,#128+16]
|
||||
ldp d10,d11,[sp,#128+16] // meet ABI requirements
|
||||
ldp d12,d13,[sp,#128+32]
|
||||
ldp d14,d15,[sp,#128+48]
|
||||
|
||||
@@ -1250,6 +1249,7 @@ $code.=<<___;
|
||||
ld1 {$CTR,$ROT24},[$key]
|
||||
b.hs .Loop_outer_neon
|
||||
|
||||
ldp d8,d9,[sp,#0] // meet ABI requirements
|
||||
eor @K[1],@K[1],@K[1]
|
||||
eor @K[2],@K[2],@K[2]
|
||||
eor @K[3],@K[3],@K[3]
|
||||
@@ -1259,6 +1259,7 @@ $code.=<<___;
|
||||
b .Loop_outer
|
||||
|
||||
.Ldone_512_neon:
|
||||
ldp d8,d9,[sp,#128+0] // meet ABI requirements
|
||||
ldp x19,x20,[x29,#16]
|
||||
add sp,sp,#128+64
|
||||
ldp x21,x22,[x29,#32]
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
use strict;
|
||||
use FindBin qw($Bin);
|
||||
use lib "$Bin/../..";
|
||||
use perlasm::s390x qw(:DEFAULT :VX :LD AUTOLOAD LABEL INCLUDE);
|
||||
use perlasm::s390x qw(:DEFAULT :VX :EI AUTOLOAD LABEL INCLUDE);
|
||||
|
||||
# $output is the last argument if it looks like a file (it has an extension)
|
||||
# $flavour is the first argument if it doesn't look like a file
|
||||
|
||||
@@ -61,7 +61,7 @@ $ymm=1 if ($xmm && !$ymm && $ARGV[0] eq "win32" &&
|
||||
$1>=10); # first version supporting AVX
|
||||
|
||||
$ymm=1 if ($xmm && !$ymm &&
|
||||
`$ENV{CC} -v 2>&1` =~ /((?:^clang|LLVM) version|based on LLVM) ([3-9]\.[0-9]+)/ &&
|
||||
`$ENV{CC} -v 2>&1` =~ /((?:^clang|LLVM) version|based on LLVM) ([0-9]+\.[0-9]+)/ &&
|
||||
$2>=3.0); # first version supporting AVX
|
||||
|
||||
$a="eax";
|
||||
|
||||
@@ -86,7 +86,7 @@ if (!$avx && $win64 && ($flavour =~ /masm/ || $ENV{ASM} =~ /ml64/) &&
|
||||
$avx = ($1>=10) + ($1>=11);
|
||||
}
|
||||
|
||||
if (!$avx && `$ENV{CC} -v 2>&1` =~ /((?:^clang|LLVM) version|.*based on LLVM) ([3-9]\.[0-9]+)/) {
|
||||
if (!$avx && `$ENV{CC} -v 2>&1` =~ /((?:^clang|LLVM) version|.*based on LLVM) ([0-9]+\.[0-9]+)/) {
|
||||
$avx = ($2>=3.0) + ($2>3.0);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "crypto/chacha.h"
|
||||
#include "crypto/ctype.h"
|
||||
|
||||
typedef unsigned int u32;
|
||||
typedef unsigned char u8;
|
||||
@@ -78,10 +79,18 @@ void ChaCha20_ctr32(unsigned char *out, const unsigned char *inp,
|
||||
size_t todo, i;
|
||||
|
||||
/* sigma constant "expand 32-byte k" in little-endian encoding */
|
||||
input[0] = ((u32)'e') | ((u32)'x'<<8) | ((u32)'p'<<16) | ((u32)'a'<<24);
|
||||
input[1] = ((u32)'n') | ((u32)'d'<<8) | ((u32)' '<<16) | ((u32)'3'<<24);
|
||||
input[2] = ((u32)'2') | ((u32)'-'<<8) | ((u32)'b'<<16) | ((u32)'y'<<24);
|
||||
input[3] = ((u32)'t') | ((u32)'e'<<8) | ((u32)' '<<16) | ((u32)'k'<<24);
|
||||
input[0] = ((u32)ossl_toascii('e')) | ((u32)ossl_toascii('x') << 8)
|
||||
| ((u32)ossl_toascii('p') << 16)
|
||||
| ((u32)ossl_toascii('a') << 24);
|
||||
input[1] = ((u32)ossl_toascii('n')) | ((u32)ossl_toascii('d') << 8)
|
||||
| ((u32)ossl_toascii(' ') << 16)
|
||||
| ((u32)ossl_toascii('3') << 24);
|
||||
input[2] = ((u32)ossl_toascii('2')) | ((u32)ossl_toascii('-') << 8)
|
||||
| ((u32)ossl_toascii('b') << 16)
|
||||
| ((u32)ossl_toascii('y') << 24);
|
||||
input[3] = ((u32)ossl_toascii('t')) | ((u32)ossl_toascii('e') << 8)
|
||||
| ((u32)ossl_toascii(' ') << 16)
|
||||
| ((u32)ossl_toascii('k') << 24);
|
||||
|
||||
input[4] = key[0];
|
||||
input[5] = key[1];
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
LIBS=../../libcrypto
|
||||
SOURCE[../../libcrypto]= cmp_asn.c cmp_ctx.c cmp_err.c cmp_util.c
|
||||
SOURCE[../../libcrypto]= cmp_asn.c cmp_ctx.c cmp_err.c cmp_util.c \
|
||||
cmp_status.c cmp_hdr.c cmp_protect.c cmp_msg.c
|
||||
@@ -164,7 +164,7 @@ int OSSL_CMP_ITAV_push0_stack_item(STACK_OF(OSSL_CMP_ITAV) **itav_sk_p,
|
||||
{
|
||||
int created = 0;
|
||||
|
||||
if (itav_sk_p == NULL) {
|
||||
if (itav_sk_p == NULL || itav == NULL) {
|
||||
CMPerr(0, CMP_R_NULL_ARGUMENT);
|
||||
goto err;
|
||||
}
|
||||
@@ -174,11 +174,10 @@ int OSSL_CMP_ITAV_push0_stack_item(STACK_OF(OSSL_CMP_ITAV) **itav_sk_p,
|
||||
goto err;
|
||||
created = 1;
|
||||
}
|
||||
if (itav != NULL) {
|
||||
if (!sk_OSSL_CMP_ITAV_push(*itav_sk_p, itav))
|
||||
goto err;
|
||||
}
|
||||
if (!sk_OSSL_CMP_ITAV_push(*itav_sk_p, itav))
|
||||
goto err;
|
||||
return 1;
|
||||
|
||||
err:
|
||||
if (created != 0) {
|
||||
sk_OSSL_CMP_ITAV_free(*itav_sk_p);
|
||||
|
||||
+23
-8
@@ -68,14 +68,21 @@ STACK_OF(X509) *OSSL_CMP_CTX_get0_untrusted_certs(const OSSL_CMP_CTX *ctx)
|
||||
*/
|
||||
int OSSL_CMP_CTX_set1_untrusted_certs(OSSL_CMP_CTX *ctx, STACK_OF(X509) *certs)
|
||||
{
|
||||
STACK_OF(X509) *untrusted_certs;
|
||||
if (ctx == NULL) {
|
||||
CMPerr(0, CMP_R_NULL_ARGUMENT);
|
||||
return 0;
|
||||
}
|
||||
sk_X509_pop_free(ctx->untrusted_certs, X509_free);
|
||||
if ((ctx->untrusted_certs = sk_X509_new_null()) == NULL)
|
||||
if ((untrusted_certs = sk_X509_new_null()) == NULL)
|
||||
return 0;
|
||||
return ossl_cmp_sk_X509_add1_certs(ctx->untrusted_certs, certs, 0, 1, 0);
|
||||
if (ossl_cmp_sk_X509_add1_certs(untrusted_certs, certs, 0, 1, 0) != 1)
|
||||
goto err;
|
||||
sk_X509_pop_free(ctx->untrusted_certs, X509_free);
|
||||
ctx->untrusted_certs = untrusted_certs;
|
||||
return 1;
|
||||
err:
|
||||
sk_X509_pop_free(untrusted_certs, X509_free);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -195,7 +202,7 @@ void OSSL_CMP_CTX_free(OSSL_CMP_CTX *ctx)
|
||||
int ossl_cmp_ctx_set_status(OSSL_CMP_CTX *ctx, int status)
|
||||
{
|
||||
if (!ossl_assert(ctx != NULL))
|
||||
return 0;
|
||||
return 0;
|
||||
ctx->status = status;
|
||||
return 1;
|
||||
}
|
||||
@@ -373,13 +380,19 @@ int OSSL_CMP_CTX_set1_referenceValue(OSSL_CMP_CTX *ctx,
|
||||
int OSSL_CMP_CTX_set1_secretValue(OSSL_CMP_CTX *ctx, const unsigned char *sec,
|
||||
const int len)
|
||||
{
|
||||
ASN1_OCTET_STRING *secretValue = NULL;
|
||||
if (ctx == NULL) {
|
||||
CMPerr(0, CMP_R_NULL_ARGUMENT);
|
||||
return 0;
|
||||
}
|
||||
if (ctx->secretValue != NULL)
|
||||
if (ossl_cmp_asn1_octet_string_set1_bytes(&secretValue, sec, len) != 1)
|
||||
return 0;
|
||||
if (ctx->secretValue != NULL) {
|
||||
OPENSSL_cleanse(ctx->secretValue->data, ctx->secretValue->length);
|
||||
return ossl_cmp_asn1_octet_string_set1_bytes(&ctx->secretValue, sec, len);
|
||||
ASN1_OCTET_STRING_free(ctx->secretValue);
|
||||
}
|
||||
ctx->secretValue = secretValue;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -933,7 +946,8 @@ int OSSL_CMP_CTX_get_failInfoCode(const OSSL_CMP_CTX *ctx)
|
||||
* Sets a Boolean or integer option of the context to the "val" arg.
|
||||
* Returns 1 on success, 0 on error
|
||||
*/
|
||||
int OSSL_CMP_CTX_set_option(OSSL_CMP_CTX *ctx, int opt, int val) {
|
||||
int OSSL_CMP_CTX_set_option(OSSL_CMP_CTX *ctx, int opt, int val)
|
||||
{
|
||||
int min_val;
|
||||
|
||||
if (ctx == NULL) {
|
||||
@@ -1036,7 +1050,8 @@ int OSSL_CMP_CTX_set_option(OSSL_CMP_CTX *ctx, int opt, int val) {
|
||||
* Reads a Boolean or integer option value from the context.
|
||||
* Returns -1 on error (which is the default OSSL_CMP_OPT_REVOCATION_REASON)
|
||||
*/
|
||||
int OSSL_CMP_CTX_get_option(const OSSL_CMP_CTX *ctx, int opt) {
|
||||
int OSSL_CMP_CTX_get_option(const OSSL_CMP_CTX *ctx, int opt)
|
||||
{
|
||||
if (ctx == NULL) {
|
||||
CMPerr(0, CMP_R_NULL_ARGUMENT);
|
||||
return -1;
|
||||
|
||||
+60
-3
@@ -1,7 +1,6 @@
|
||||
/*
|
||||
* Copyright 2007-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright Nokia 2007-2019
|
||||
* Copyright Siemens AG 2015-2019
|
||||
* Generated by util/mkerr.pl DO NOT EDIT
|
||||
* Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -15,11 +14,69 @@
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
|
||||
static const ERR_STRING_DATA CMP_str_reasons[] = {
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, CMP_R_BAD_REQUEST_ID), "bad request id"},
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, CMP_R_CERTID_NOT_FOUND), "certid not found"},
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, CMP_R_CERTIFICATE_NOT_FOUND),
|
||||
"certificate not found"},
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, CMP_R_CERTRESPONSE_NOT_FOUND),
|
||||
"certresponse not found"},
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, CMP_R_CERT_AND_KEY_DO_NOT_MATCH),
|
||||
"cert and key do not match"},
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, CMP_R_ERROR_CALCULATING_PROTECTION),
|
||||
"error calculating protection"},
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, CMP_R_ERROR_CREATING_CERTCONF),
|
||||
"error creating certconf"},
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, CMP_R_ERROR_CREATING_CERTREP),
|
||||
"error creating certrep"},
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, CMP_R_ERROR_CREATING_ERROR),
|
||||
"error creating error"},
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, CMP_R_ERROR_CREATING_GENM),
|
||||
"error creating genm"},
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, CMP_R_ERROR_CREATING_GENP),
|
||||
"error creating genp"},
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, CMP_R_ERROR_CREATING_P10CR),
|
||||
"error creating p10cr"},
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, CMP_R_ERROR_CREATING_PKICONF),
|
||||
"error creating pkiconf"},
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, CMP_R_ERROR_CREATING_POLLREP),
|
||||
"error creating pollrep"},
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, CMP_R_ERROR_CREATING_POLLREQ),
|
||||
"error creating pollreq"},
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, CMP_R_ERROR_CREATING_RP), "error creating rp"},
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, CMP_R_ERROR_CREATING_RR), "error creating rr"},
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, CMP_R_ERROR_PARSING_PKISTATUS),
|
||||
"error parsing pkistatus"},
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, CMP_R_ERROR_PROTECTING_MESSAGE),
|
||||
"error protecting message"},
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, CMP_R_ERROR_SETTING_CERTHASH),
|
||||
"error setting certhash"},
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, CMP_R_FAILURE_OBTAINING_RANDOM),
|
||||
"failure obtaining random"},
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, CMP_R_FAIL_INFO_OUT_OF_RANGE),
|
||||
"fail info out of range"},
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, CMP_R_INVALID_ARGS), "invalid args"},
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, CMP_R_MISSING_KEY_INPUT_FOR_CREATING_PROTECTION),
|
||||
"missing key input for creating protection"},
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, CMP_R_MISSING_PRIVATE_KEY),
|
||||
"missing private key"},
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, CMP_R_MISSING_SENDER_IDENTIFICATION),
|
||||
"missing sender identification"},
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, CMP_R_MULTIPLE_SAN_SOURCES),
|
||||
"multiple san sources"},
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, CMP_R_NO_STDIO), "no stdio"},
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, CMP_R_NULL_ARGUMENT), "null argument"},
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, CMP_R_PKISTATUSINFO_NOT_FOUND),
|
||||
"pkistatusinfo not found"},
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, CMP_R_UNEXPECTED_PKIBODY), "unexpected pkibody"},
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, CMP_R_UNKNOWN_ALGORITHM_ID),
|
||||
"unknown algorithm id"},
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, CMP_R_UNKNOWN_CERT_TYPE), "unknown cert type"},
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, CMP_R_UNSUPPORTED_ALGORITHM),
|
||||
"unsupported algorithm"},
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, CMP_R_UNSUPPORTED_KEY_TYPE),
|
||||
"unsupported key type"},
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, CMP_R_WRONG_ALGORITHM_OID),
|
||||
"wrong algorithm oid"},
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,377 @@
|
||||
/*
|
||||
* Copyright 2007-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright Nokia 2007-2019
|
||||
* Copyright Siemens AG 2015-2019
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/* CMP functions for PKIHeader handling */
|
||||
|
||||
#include "cmp_local.h"
|
||||
|
||||
#include <openssl/rand.h>
|
||||
|
||||
/* explicit #includes not strictly needed since implied by the above: */
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/cmp.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
int ossl_cmp_hdr_set_pvno(OSSL_CMP_PKIHEADER *hdr, int pvno)
|
||||
{
|
||||
if (!ossl_assert(hdr != NULL))
|
||||
return 0;
|
||||
return ASN1_INTEGER_set(hdr->pvno, pvno);
|
||||
}
|
||||
|
||||
int ossl_cmp_hdr_get_pvno(const OSSL_CMP_PKIHEADER *hdr)
|
||||
{
|
||||
int64_t pvno;
|
||||
|
||||
if (!ossl_assert(hdr != NULL))
|
||||
return -1;
|
||||
if (!ASN1_INTEGER_get_int64(&pvno, hdr->pvno) || pvno < 0 || pvno > INT_MAX)
|
||||
return -1;
|
||||
return (int)pvno;
|
||||
}
|
||||
|
||||
ASN1_OCTET_STRING *OSSL_CMP_HDR_get0_transactionID(const OSSL_CMP_PKIHEADER *hdr)
|
||||
{
|
||||
if (hdr == NULL) {
|
||||
CMPerr(0, CMP_R_NULL_ARGUMENT);
|
||||
return NULL;
|
||||
}
|
||||
return hdr->transactionID;
|
||||
}
|
||||
|
||||
ASN1_OCTET_STRING *ossl_cmp_hdr_get0_senderNonce(const OSSL_CMP_PKIHEADER *hdr)
|
||||
{
|
||||
if (!ossl_assert(hdr != NULL))
|
||||
return NULL;
|
||||
return hdr->senderNonce;
|
||||
}
|
||||
|
||||
ASN1_OCTET_STRING *OSSL_CMP_HDR_get0_recipNonce(const OSSL_CMP_PKIHEADER *hdr)
|
||||
{
|
||||
if (hdr == NULL) {
|
||||
CMPerr(0, CMP_R_NULL_ARGUMENT);
|
||||
return NULL;
|
||||
}
|
||||
return hdr->recipNonce;
|
||||
}
|
||||
|
||||
/* assign to *tgt a copy of src (which may be NULL to indicate an empty DN) */
|
||||
static int set1_general_name(GENERAL_NAME **tgt, const X509_NAME *src)
|
||||
{
|
||||
GENERAL_NAME *gen;
|
||||
|
||||
if (!ossl_assert(tgt != NULL))
|
||||
return 0;
|
||||
if ((gen = GENERAL_NAME_new()) == NULL)
|
||||
goto err;
|
||||
gen->type = GEN_DIRNAME;
|
||||
|
||||
if (src == NULL) { /* NULL-DN */
|
||||
if ((gen->d.directoryName = X509_NAME_new()) == NULL)
|
||||
goto err;
|
||||
} else if (!X509_NAME_set(&gen->d.directoryName, src)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
GENERAL_NAME_free(*tgt);
|
||||
*tgt = gen;
|
||||
|
||||
return 1;
|
||||
|
||||
err:
|
||||
GENERAL_NAME_free(gen);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the sender name in PKIHeader.
|
||||
* when nm is NULL, sender is set to an empty string
|
||||
* returns 1 on success, 0 on error
|
||||
*/
|
||||
int ossl_cmp_hdr_set1_sender(OSSL_CMP_PKIHEADER *hdr, const X509_NAME *nm)
|
||||
{
|
||||
if (!ossl_assert(hdr != NULL))
|
||||
return 0;
|
||||
return set1_general_name(&hdr->sender, nm);
|
||||
}
|
||||
|
||||
int ossl_cmp_hdr_set1_recipient(OSSL_CMP_PKIHEADER *hdr, const X509_NAME *nm)
|
||||
{
|
||||
if (!ossl_assert(hdr != NULL))
|
||||
return 0;
|
||||
return set1_general_name(&hdr->recipient, nm);
|
||||
}
|
||||
|
||||
int ossl_cmp_hdr_update_messageTime(OSSL_CMP_PKIHEADER *hdr)
|
||||
{
|
||||
if (!ossl_assert(hdr != NULL))
|
||||
return 0;
|
||||
if (hdr->messageTime == NULL
|
||||
&& (hdr->messageTime = ASN1_GENERALIZEDTIME_new()) == NULL)
|
||||
return 0;
|
||||
return ASN1_GENERALIZEDTIME_set(hdr->messageTime, time(NULL)) != NULL;
|
||||
}
|
||||
|
||||
/* assign to *tgt a copy of src (or if NULL a random byte array of given len) */
|
||||
static int set1_aostr_else_random(ASN1_OCTET_STRING **tgt,
|
||||
const ASN1_OCTET_STRING *src, size_t len)
|
||||
{
|
||||
unsigned char *bytes = NULL;
|
||||
int res = 0;
|
||||
|
||||
if (src == NULL) { /* generate a random value if src == NULL */
|
||||
if ((bytes = OPENSSL_malloc(len)) == NULL)
|
||||
goto err;
|
||||
if (RAND_bytes(bytes, len) <= 0) {
|
||||
CMPerr(0, CMP_R_FAILURE_OBTAINING_RANDOM);
|
||||
goto err;
|
||||
}
|
||||
res = ossl_cmp_asn1_octet_string_set1_bytes(tgt, bytes, len);
|
||||
} else {
|
||||
res = ossl_cmp_asn1_octet_string_set1(tgt, src);
|
||||
}
|
||||
|
||||
err:
|
||||
OPENSSL_free(bytes);
|
||||
return res;
|
||||
}
|
||||
|
||||
int ossl_cmp_hdr_set1_senderKID(OSSL_CMP_PKIHEADER *hdr,
|
||||
const ASN1_OCTET_STRING *senderKID)
|
||||
{
|
||||
if (!ossl_assert(hdr != NULL))
|
||||
return 0;
|
||||
return ossl_cmp_asn1_octet_string_set1(&hdr->senderKID, senderKID);
|
||||
}
|
||||
|
||||
/* push the given text string to the given PKIFREETEXT ft */
|
||||
int ossl_cmp_pkifreetext_push_str(OSSL_CMP_PKIFREETEXT *ft, const char *text)
|
||||
{
|
||||
ASN1_UTF8STRING *utf8string;
|
||||
|
||||
if (!ossl_assert(ft != NULL && text != NULL))
|
||||
return 0;
|
||||
if ((utf8string = ASN1_UTF8STRING_new()) == NULL)
|
||||
return 0;
|
||||
if (!ASN1_STRING_set(utf8string, text, -1))
|
||||
goto err;
|
||||
if (!sk_ASN1_UTF8STRING_push(ft, utf8string))
|
||||
goto err;
|
||||
return 1;
|
||||
|
||||
err:
|
||||
ASN1_UTF8STRING_free(utf8string);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ossl_cmp_hdr_push0_freeText(OSSL_CMP_PKIHEADER *hdr, ASN1_UTF8STRING *text)
|
||||
{
|
||||
if (!ossl_assert(hdr != NULL && text != NULL))
|
||||
return 0;
|
||||
|
||||
if (hdr->freeText == NULL
|
||||
&& (hdr->freeText = sk_ASN1_UTF8STRING_new_null()) == NULL)
|
||||
return 0;
|
||||
|
||||
return sk_ASN1_UTF8STRING_push(hdr->freeText, text);
|
||||
}
|
||||
|
||||
int ossl_cmp_hdr_push1_freeText(OSSL_CMP_PKIHEADER *hdr, ASN1_UTF8STRING *text)
|
||||
{
|
||||
if (!ossl_assert(hdr != NULL && text != NULL))
|
||||
return 0;
|
||||
|
||||
if (hdr->freeText == NULL
|
||||
&& (hdr->freeText = sk_ASN1_UTF8STRING_new_null()) == NULL)
|
||||
return 0;
|
||||
|
||||
return ossl_cmp_pkifreetext_push_str(hdr->freeText, (char *)text->data);
|
||||
}
|
||||
|
||||
int ossl_cmp_hdr_generalInfo_push0_item(OSSL_CMP_PKIHEADER *hdr,
|
||||
OSSL_CMP_ITAV *itav)
|
||||
{
|
||||
if (!ossl_assert(hdr != NULL && itav != NULL))
|
||||
return 0;
|
||||
return OSSL_CMP_ITAV_push0_stack_item(&hdr->generalInfo, itav);
|
||||
}
|
||||
|
||||
int ossl_cmp_hdr_generalInfo_push1_items(OSSL_CMP_PKIHEADER *hdr,
|
||||
STACK_OF(OSSL_CMP_ITAV) *itavs)
|
||||
{
|
||||
int i;
|
||||
OSSL_CMP_ITAV *itav;
|
||||
|
||||
if (!ossl_assert(hdr != NULL))
|
||||
return 0;
|
||||
|
||||
for (i = 0; i < sk_OSSL_CMP_ITAV_num(itavs); i++) {
|
||||
itav = OSSL_CMP_ITAV_dup(sk_OSSL_CMP_ITAV_value(itavs, i));
|
||||
if (itav == NULL)
|
||||
return 0;
|
||||
|
||||
if (!ossl_cmp_hdr_generalInfo_push0_item(hdr, itav)) {
|
||||
OSSL_CMP_ITAV_free(itav);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ossl_cmp_hdr_set_implicitConfirm(OSSL_CMP_PKIHEADER *hdr)
|
||||
{
|
||||
OSSL_CMP_ITAV *itav;
|
||||
ASN1_TYPE *asn1null;
|
||||
|
||||
if (!ossl_assert(hdr != NULL))
|
||||
return 0;
|
||||
asn1null = (ASN1_TYPE *)ASN1_NULL_new();
|
||||
if (asn1null == NULL)
|
||||
return 0;
|
||||
if ((itav = OSSL_CMP_ITAV_create(OBJ_nid2obj(NID_id_it_implicitConfirm),
|
||||
asn1null)) == NULL)
|
||||
goto err;
|
||||
if (!ossl_cmp_hdr_generalInfo_push0_item(hdr, itav))
|
||||
goto err;
|
||||
return 1;
|
||||
|
||||
err:
|
||||
ASN1_TYPE_free(asn1null);
|
||||
OSSL_CMP_ITAV_free(itav);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* return 1 if implicitConfirm in the generalInfo field of the header is set */
|
||||
int ossl_cmp_hdr_check_implicitConfirm(const OSSL_CMP_PKIHEADER *hdr)
|
||||
{
|
||||
int itavCount;
|
||||
int i;
|
||||
OSSL_CMP_ITAV *itav;
|
||||
|
||||
if (!ossl_assert(hdr != NULL))
|
||||
return 0;
|
||||
|
||||
itavCount = sk_OSSL_CMP_ITAV_num(hdr->generalInfo);
|
||||
for (i = 0; i < itavCount; i++) {
|
||||
itav = sk_OSSL_CMP_ITAV_value(hdr->generalInfo, i);
|
||||
if (itav != NULL
|
||||
&& OBJ_obj2nid(itav->infoType) == NID_id_it_implicitConfirm)
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* fill in all fields of the hdr according to the info given in ctx */
|
||||
int ossl_cmp_hdr_init(OSSL_CMP_CTX *ctx, OSSL_CMP_PKIHEADER *hdr)
|
||||
{
|
||||
X509_NAME *sender;
|
||||
X509_NAME *rcp = NULL;
|
||||
|
||||
if (!ossl_assert(ctx != NULL && hdr != NULL))
|
||||
return 0;
|
||||
|
||||
/* set the CMP version */
|
||||
if (!ossl_cmp_hdr_set_pvno(hdr, OSSL_CMP_PVNO))
|
||||
return 0;
|
||||
|
||||
sender = ctx->clCert != NULL ?
|
||||
X509_get_subject_name(ctx->clCert) : ctx->subjectName;
|
||||
/*
|
||||
* The sender name is copied from the subject of the client cert, if any,
|
||||
* or else from the the subject name provided for certification requests.
|
||||
* As required by RFC 4210 section 5.1.1., if the sender name is not known
|
||||
* to the client it set to NULL-DN. In this case for identification at least
|
||||
* the senderKID must be set, which we take from any referenceValue given.
|
||||
*/
|
||||
if (sender == NULL && ctx->referenceValue == NULL) {
|
||||
CMPerr(0, CMP_R_MISSING_SENDER_IDENTIFICATION);
|
||||
return 0;
|
||||
}
|
||||
if (!ossl_cmp_hdr_set1_sender(hdr, sender))
|
||||
return 0;
|
||||
|
||||
/* determine recipient entry in PKIHeader */
|
||||
if (ctx->srvCert != NULL) {
|
||||
rcp = X509_get_subject_name(ctx->srvCert);
|
||||
/* set also as expected_sender of responses unless set explicitly */
|
||||
if (ctx->expected_sender == NULL && rcp != NULL
|
||||
&& !OSSL_CMP_CTX_set1_expected_sender(ctx, rcp))
|
||||
return 0;
|
||||
} else if (ctx->recipient != NULL) {
|
||||
rcp = ctx->recipient;
|
||||
} else if (ctx->issuer != NULL) {
|
||||
rcp = ctx->issuer;
|
||||
} else if (ctx->oldCert != NULL) {
|
||||
rcp = X509_get_issuer_name(ctx->oldCert);
|
||||
} else if (ctx->clCert != NULL) {
|
||||
rcp = X509_get_issuer_name(ctx->clCert);
|
||||
}
|
||||
if (!ossl_cmp_hdr_set1_recipient(hdr, rcp))
|
||||
return 0;
|
||||
|
||||
/* set current time as message time */
|
||||
if (!ossl_cmp_hdr_update_messageTime(hdr))
|
||||
return 0;
|
||||
|
||||
if (ctx->recipNonce != NULL
|
||||
&& !ossl_cmp_asn1_octet_string_set1(&hdr->recipNonce,
|
||||
ctx->recipNonce))
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* set ctx->transactionID in CMP header
|
||||
* if ctx->transactionID is NULL, a random one is created with 128 bit
|
||||
* according to section 5.1.1:
|
||||
*
|
||||
* It is RECOMMENDED that the clients fill the transactionID field with
|
||||
* 128 bits of (pseudo-) random data for the start of a transaction to
|
||||
* reduce the probability of having the transactionID in use at the server.
|
||||
*/
|
||||
if (ctx->transactionID == NULL
|
||||
&& !set1_aostr_else_random(&ctx->transactionID, NULL,
|
||||
OSSL_CMP_TRANSACTIONID_LENGTH))
|
||||
return 0;
|
||||
if (!ossl_cmp_asn1_octet_string_set1(&hdr->transactionID,
|
||||
ctx->transactionID))
|
||||
return 0;
|
||||
|
||||
/*-
|
||||
* set random senderNonce
|
||||
* according to section 5.1.1:
|
||||
*
|
||||
* senderNonce present
|
||||
* -- 128 (pseudo-)random bits
|
||||
* The senderNonce and recipNonce fields protect the PKIMessage against
|
||||
* replay attacks. The senderNonce will typically be 128 bits of
|
||||
* (pseudo-) random data generated by the sender, whereas the recipNonce
|
||||
* is copied from the senderNonce of the previous message in the
|
||||
* transaction.
|
||||
*/
|
||||
if (!set1_aostr_else_random(&hdr->senderNonce, NULL,
|
||||
OSSL_CMP_SENDERNONCE_LENGTH))
|
||||
return 0;
|
||||
|
||||
/* store senderNonce - for cmp with recipNonce in next outgoing msg */
|
||||
if (!OSSL_CMP_CTX_set1_senderNonce(ctx, hdr->senderNonce))
|
||||
return 0;
|
||||
|
||||
/*-
|
||||
* freeText [7] PKIFreeText OPTIONAL,
|
||||
* -- this may be used to indicate context-specific instructions
|
||||
* -- (this field is intended for human consumption)
|
||||
*/
|
||||
if (ctx->freeText != NULL
|
||||
&& !ossl_cmp_hdr_push1_freeText(hdr, ctx->freeText))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
+128
-2
@@ -42,7 +42,7 @@ struct ossl_cmp_ctx_st {
|
||||
int proxyPort;
|
||||
int msgtimeout; /* max seconds to wait for each CMP message round trip */
|
||||
int totaltimeout; /* maximum number seconds an enrollment may take, incl. */
|
||||
/* attempts polling for a response if a 'waiting' PKIStatus is received */
|
||||
/* attempts polling for a response if a 'waiting' PKIStatus is received */
|
||||
time_t end_time; /* session start time + totaltimeout */
|
||||
OSSL_cmp_http_cb_t http_cb;
|
||||
void *http_cb_arg; /* allows to store optional argument to cb */
|
||||
@@ -77,6 +77,7 @@ struct ossl_cmp_ctx_st {
|
||||
ASN1_OCTET_STRING *transactionID; /* the current transaction ID */
|
||||
ASN1_OCTET_STRING *senderNonce; /* last nonce sent */
|
||||
ASN1_OCTET_STRING *recipNonce; /* last nonce received */
|
||||
ASN1_UTF8STRING *freeText; /* optional string to include each msg */
|
||||
STACK_OF(OSSL_CMP_ITAV) *geninfo_ITAVs;
|
||||
int implicitConfirm; /* set implicitConfirm in IR/KUR/CR messages */
|
||||
int disableConfirm; /* disable certConf in IR/KUR/CR for broken servers */
|
||||
@@ -278,6 +279,7 @@ struct ossl_cmp_pkisi_st {
|
||||
} /* OSSL_CMP_PKISI */;
|
||||
DECLARE_ASN1_FUNCTIONS(OSSL_CMP_PKISI)
|
||||
DECLARE_ASN1_DUP_FUNCTION(OSSL_CMP_PKISI)
|
||||
DECLARE_ASN1_DUP_FUNCTION(OSSL_CRMF_CERTID)
|
||||
|
||||
/*-
|
||||
* RevReqContent ::= SEQUENCE OF RevDetails
|
||||
@@ -525,6 +527,7 @@ DECLARE_ASN1_FUNCTIONS(OSSL_CMP_GENREPCONTENT)
|
||||
* certConf [24] CertConfirmContent, --Certificate confirm
|
||||
* pollReq [25] PollReqContent, --Polling request
|
||||
* pollRep [26] PollRepContent --Polling response
|
||||
* }
|
||||
*/
|
||||
typedef struct ossl_cmp_pkibody_st {
|
||||
int type;
|
||||
@@ -678,6 +681,13 @@ DECLARE_ASN1_FUNCTIONS(CMP_PROTECTEDPART)
|
||||
* }
|
||||
*/
|
||||
|
||||
/*
|
||||
* constants
|
||||
*/
|
||||
/* certReqId for the first - and so far only - certificate request */
|
||||
# define OSSL_CMP_CERTREQID 0
|
||||
/* sequence id for the first - and so far only - revocation request */
|
||||
# define OSSL_CMP_REVREQSID 0
|
||||
/*
|
||||
* functions
|
||||
*/
|
||||
@@ -720,6 +730,122 @@ int ossl_cmp_ctx_set1_extraCertsIn(OSSL_CMP_CTX *ctx,
|
||||
int ossl_cmp_ctx_set1_recipNonce(OSSL_CMP_CTX *ctx,
|
||||
const ASN1_OCTET_STRING *nonce);
|
||||
|
||||
# define OSSL_CMP_TRANSACTIONID_LENGTH 16
|
||||
/* from cmp_status.c */
|
||||
OSSL_CMP_PKISI *
|
||||
ossl_cmp_statusinfo_new(int status, int fail_info, const char *text);
|
||||
int ossl_cmp_pkisi_get_pkistatus(const OSSL_CMP_PKISI *statusInfo);
|
||||
const char *ossl_cmp_PKIStatus_to_string(int status);
|
||||
OSSL_CMP_PKIFREETEXT *ossl_cmp_pkisi_get0_statusstring(const OSSL_CMP_PKISI *si);
|
||||
int ossl_cmp_pkisi_get_pkifailureinfo(const OSSL_CMP_PKISI *si);
|
||||
int ossl_cmp_pkisi_pkifailureinfo_check(const OSSL_CMP_PKISI *si, int bit_index);
|
||||
|
||||
/* from cmp_hdr.c */
|
||||
int ossl_cmp_hdr_set_pvno(OSSL_CMP_PKIHEADER *hdr, int pvno);
|
||||
int ossl_cmp_hdr_get_pvno(const OSSL_CMP_PKIHEADER *hdr);
|
||||
ASN1_OCTET_STRING *ossl_cmp_hdr_get0_senderNonce(const OSSL_CMP_PKIHEADER *hdr);
|
||||
int ossl_cmp_hdr_set1_sender(OSSL_CMP_PKIHEADER *hdr, const X509_NAME *nm);
|
||||
int ossl_cmp_hdr_set1_recipient(OSSL_CMP_PKIHEADER *hdr, const X509_NAME *nm);
|
||||
int ossl_cmp_hdr_update_messageTime(OSSL_CMP_PKIHEADER *hdr);
|
||||
int ossl_cmp_hdr_set1_senderKID(OSSL_CMP_PKIHEADER *hdr,
|
||||
const ASN1_OCTET_STRING *senderKID);
|
||||
int ossl_cmp_pkifreetext_push_str(OSSL_CMP_PKIFREETEXT *ft, const char *text);
|
||||
int ossl_cmp_hdr_push0_freeText(OSSL_CMP_PKIHEADER *hdr, ASN1_UTF8STRING *text);
|
||||
int ossl_cmp_hdr_push1_freeText(OSSL_CMP_PKIHEADER *hdr, ASN1_UTF8STRING *text);
|
||||
int ossl_cmp_hdr_generalInfo_push0_item(OSSL_CMP_PKIHEADER *hdr,
|
||||
OSSL_CMP_ITAV *itav);
|
||||
int ossl_cmp_hdr_generalInfo_push1_items(OSSL_CMP_PKIHEADER *hdr,
|
||||
STACK_OF(OSSL_CMP_ITAV) *itavs);
|
||||
int ossl_cmp_hdr_set_implicitConfirm(OSSL_CMP_PKIHEADER *hdr);
|
||||
int ossl_cmp_hdr_check_implicitConfirm(const OSSL_CMP_PKIHEADER *hdr);
|
||||
# define OSSL_CMP_TRANSACTIONID_LENGTH 16
|
||||
# define OSSL_CMP_SENDERNONCE_LENGTH 16
|
||||
int ossl_cmp_hdr_init(OSSL_CMP_CTX *ctx, OSSL_CMP_PKIHEADER *hdr);
|
||||
|
||||
/* from cmp_msg.c */
|
||||
/* OSSL_CMP_MSG bodytype ASN.1 choice IDs */
|
||||
# define OSSL_CMP_PKIBODY_IR 0
|
||||
# define OSSL_CMP_PKIBODY_IP 1
|
||||
# define OSSL_CMP_PKIBODY_CR 2
|
||||
# define OSSL_CMP_PKIBODY_CP 3
|
||||
# define OSSL_CMP_PKIBODY_P10CR 4
|
||||
# define OSSL_CMP_PKIBODY_POPDECC 5
|
||||
# define OSSL_CMP_PKIBODY_POPDECR 6
|
||||
# define OSSL_CMP_PKIBODY_KUR 7
|
||||
# define OSSL_CMP_PKIBODY_KUP 8
|
||||
# define OSSL_CMP_PKIBODY_KRR 9
|
||||
# define OSSL_CMP_PKIBODY_KRP 10
|
||||
# define OSSL_CMP_PKIBODY_RR 11
|
||||
# define OSSL_CMP_PKIBODY_RP 12
|
||||
# define OSSL_CMP_PKIBODY_CCR 13
|
||||
# define OSSL_CMP_PKIBODY_CCP 14
|
||||
# define OSSL_CMP_PKIBODY_CKUANN 15
|
||||
# define OSSL_CMP_PKIBODY_CANN 16
|
||||
# define OSSL_CMP_PKIBODY_RANN 17
|
||||
# define OSSL_CMP_PKIBODY_CRLANN 18
|
||||
# define OSSL_CMP_PKIBODY_PKICONF 19
|
||||
# define OSSL_CMP_PKIBODY_NESTED 20
|
||||
# define OSSL_CMP_PKIBODY_GENM 21
|
||||
# define OSSL_CMP_PKIBODY_GENP 22
|
||||
# define OSSL_CMP_PKIBODY_ERROR 23
|
||||
# define OSSL_CMP_PKIBODY_CERTCONF 24
|
||||
# define OSSL_CMP_PKIBODY_POLLREQ 25
|
||||
# define OSSL_CMP_PKIBODY_POLLREP 26
|
||||
# define OSSL_CMP_PKIBODY_TYPE_MAX OSSL_CMP_PKIBODY_POLLREP
|
||||
const char *ossl_cmp_bodytype_to_string(int type);
|
||||
int ossl_cmp_msg_set_bodytype(OSSL_CMP_MSG *msg, int type);
|
||||
int ossl_cmp_msg_get_bodytype(const OSSL_CMP_MSG *msg);
|
||||
OSSL_CMP_MSG *ossl_cmp_msg_create(OSSL_CMP_CTX *ctx, int bodytype);
|
||||
OSSL_CMP_MSG *ossl_cmp_certReq_new(OSSL_CMP_CTX *ctx, int bodytype,
|
||||
int err_code);
|
||||
OSSL_CMP_MSG *ossl_cmp_certRep_new(OSSL_CMP_CTX *ctx, int bodytype,
|
||||
int certReqId, OSSL_CMP_PKISI *si,
|
||||
X509 *cert, STACK_OF(X509) *chain,
|
||||
STACK_OF(X509) *caPubs, int encrypted,
|
||||
int unprotectedErrors);
|
||||
OSSL_CMP_MSG *ossl_cmp_rr_new(OSSL_CMP_CTX *ctx);
|
||||
OSSL_CMP_MSG *ossl_cmp_rp_new(OSSL_CMP_CTX *ctx, OSSL_CMP_PKISI *si,
|
||||
OSSL_CRMF_CERTID *certId, int unprot_err);
|
||||
OSSL_CMP_MSG *ossl_cmp_pkiconf_new(OSSL_CMP_CTX *ctx);
|
||||
int ossl_cmp_msg_gen_push0_ITAV(OSSL_CMP_MSG *msg, OSSL_CMP_ITAV *itav);
|
||||
int ossl_cmp_msg_gen_push1_ITAVs(OSSL_CMP_MSG *msg,
|
||||
STACK_OF(OSSL_CMP_ITAV) *itavs);
|
||||
OSSL_CMP_MSG *ossl_cmp_genm_new(OSSL_CMP_CTX *ctx);
|
||||
OSSL_CMP_MSG *ossl_cmp_genp_new(OSSL_CMP_CTX *ctx);
|
||||
OSSL_CMP_MSG *ossl_cmp_error_new(OSSL_CMP_CTX *ctx, OSSL_CMP_PKISI *si,
|
||||
int errorCode,
|
||||
OSSL_CMP_PKIFREETEXT *errorDetails,
|
||||
int unprotected);
|
||||
int ossl_cmp_certstatus_set_certHash(OSSL_CMP_CERTSTATUS *certStatus,
|
||||
const X509 *cert);
|
||||
OSSL_CMP_MSG *ossl_cmp_certConf_new(OSSL_CMP_CTX *ctx, int fail_info,
|
||||
const char *text);
|
||||
OSSL_CMP_MSG *ossl_cmp_pollReq_new(OSSL_CMP_CTX *ctx, int crid);
|
||||
OSSL_CMP_MSG *ossl_cmp_pollRep_new(OSSL_CMP_CTX *ctx, int crid,
|
||||
int64_t poll_after);
|
||||
OSSL_CMP_PKISI *
|
||||
ossl_cmp_revrepcontent_get_pkistatusinfo(OSSL_CMP_REVREPCONTENT *rrep, int rsid);
|
||||
OSSL_CRMF_CERTID *ossl_cmp_revrepcontent_get_CertId(OSSL_CMP_REVREPCONTENT *rrep,
|
||||
int rsid);
|
||||
OSSL_CMP_POLLREP *
|
||||
ossl_cmp_pollrepcontent_get0_pollrep(const OSSL_CMP_POLLREPCONTENT *prc,
|
||||
int rid);
|
||||
OSSL_CMP_CERTRESPONSE *
|
||||
ossl_cmp_certrepmessage_get0_certresponse(const OSSL_CMP_CERTREPMESSAGE *crepmsg,
|
||||
int rid);
|
||||
X509 *ossl_cmp_certresponse_get1_certificate(EVP_PKEY *privkey,
|
||||
const OSSL_CMP_CERTRESPONSE *crep);
|
||||
OSSL_CMP_MSG *ossl_cmp_msg_load(const char *file);
|
||||
/* BIO definitions */
|
||||
# define OSSL_d2i_CMP_MSG_bio(bp, p) \
|
||||
ASN1_d2i_bio_of(OSSL_CMP_MSG, OSSL_CMP_MSG_new, d2i_OSSL_CMP_MSG, bp, p)
|
||||
# define OSSL_i2d_CMP_MSG_bio(bp, o) \
|
||||
ASN1_i2d_bio_of(OSSL_CMP_MSG, i2d_OSSL_CMP_MSG, bp, o)
|
||||
|
||||
/* from cmp_protect.c */
|
||||
ASN1_BIT_STRING *ossl_cmp_calc_protection(const OSSL_CMP_MSG *msg,
|
||||
const ASN1_OCTET_STRING *secret,
|
||||
EVP_PKEY *pkey);
|
||||
int ossl_cmp_msg_add_extraCerts(OSSL_CMP_CTX *ctx, OSSL_CMP_MSG *msg);
|
||||
int ossl_cmp_msg_protect(OSSL_CMP_CTX *ctx, OSSL_CMP_MSG *msg);
|
||||
|
||||
#endif /* !defined OSSL_CRYPTO_CMP_LOCAL_H */
|
||||
@@ -0,0 +1,996 @@
|
||||
/*
|
||||
* Copyright 2007-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright Nokia 2007-2019
|
||||
* Copyright Siemens AG 2015-2019
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/* CMP functions for PKIMessage construction */
|
||||
|
||||
#include "cmp_local.h"
|
||||
|
||||
/* explicit #includes not strictly needed since implied by the above: */
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/cmp.h>
|
||||
#include <openssl/crmf.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/x509.h>
|
||||
|
||||
OSSL_CMP_PKIHEADER *OSSL_CMP_MSG_get0_header(const OSSL_CMP_MSG *msg)
|
||||
{
|
||||
if (msg == NULL) {
|
||||
CMPerr(0, CMP_R_NULL_ARGUMENT);
|
||||
return NULL;
|
||||
}
|
||||
return msg->header;
|
||||
}
|
||||
|
||||
const char *ossl_cmp_bodytype_to_string(int type)
|
||||
{
|
||||
static const char *type_names[] = {
|
||||
"IR", "IP", "CR", "CP", "P10CR",
|
||||
"POPDECC", "POPDECR", "KUR", "KUP",
|
||||
"KRR", "KRP", "RR", "RP", "CCR", "CCP",
|
||||
"CKUANN", "CANN", "RANN", "CRLANN", "PKICONF", "NESTED",
|
||||
"GENM", "GENP", "ERROR", "CERTCONF", "POLLREQ", "POLLREP",
|
||||
};
|
||||
|
||||
if (type < 0 || type > OSSL_CMP_PKIBODY_TYPE_MAX)
|
||||
return "illegal body type";
|
||||
return type_names[type];
|
||||
}
|
||||
|
||||
int ossl_cmp_msg_set_bodytype(OSSL_CMP_MSG *msg, int type)
|
||||
{
|
||||
if (!ossl_assert(msg != NULL && msg->body != NULL))
|
||||
return 0;
|
||||
|
||||
msg->body->type = type;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ossl_cmp_msg_get_bodytype(const OSSL_CMP_MSG *msg)
|
||||
{
|
||||
if (!ossl_assert(msg != NULL && msg->body != NULL))
|
||||
return -1;
|
||||
|
||||
return msg->body->type;
|
||||
}
|
||||
|
||||
/* Add an extension to the referenced extension stack, which may be NULL */
|
||||
static int add1_extension(X509_EXTENSIONS **pexts, int nid, int crit, void *ex)
|
||||
{
|
||||
X509_EXTENSION *ext;
|
||||
int res;
|
||||
|
||||
if (!ossl_assert(pexts != NULL)) /* pointer to var must not be NULL */
|
||||
return 0;
|
||||
|
||||
if ((ext = X509V3_EXT_i2d(nid, crit, ex)) == NULL)
|
||||
return 0;
|
||||
|
||||
res = X509v3_add_ext(pexts, ext, 0) != NULL;
|
||||
X509_EXTENSION_free(ext);
|
||||
return res;
|
||||
}
|
||||
|
||||
/* Add a CRL revocation reason code to extension stack, which may be NULL */
|
||||
static int add_crl_reason_extension(X509_EXTENSIONS **pexts, int reason_code)
|
||||
{
|
||||
ASN1_ENUMERATED *val = ASN1_ENUMERATED_new();
|
||||
int res = 0;
|
||||
|
||||
if (val != NULL && ASN1_ENUMERATED_set(val, reason_code))
|
||||
res = add1_extension(pexts, NID_crl_reason, 0 /* non-critical */, val);
|
||||
ASN1_ENUMERATED_free(val);
|
||||
return res;
|
||||
}
|
||||
|
||||
OSSL_CMP_MSG *ossl_cmp_msg_create(OSSL_CMP_CTX *ctx, int bodytype)
|
||||
{
|
||||
OSSL_CMP_MSG *msg = NULL;
|
||||
|
||||
if (!ossl_assert(ctx != NULL))
|
||||
return NULL;
|
||||
|
||||
if ((msg = OSSL_CMP_MSG_new()) == NULL)
|
||||
return NULL;
|
||||
if (!ossl_cmp_hdr_init(ctx, msg->header)
|
||||
|| !ossl_cmp_msg_set_bodytype(msg, bodytype))
|
||||
goto err;
|
||||
if (ctx->geninfo_ITAVs != NULL
|
||||
&& !ossl_cmp_hdr_generalInfo_push1_items(msg->header,
|
||||
ctx->geninfo_ITAVs))
|
||||
goto err;
|
||||
|
||||
switch (bodytype) {
|
||||
case OSSL_CMP_PKIBODY_IR:
|
||||
case OSSL_CMP_PKIBODY_CR:
|
||||
case OSSL_CMP_PKIBODY_KUR:
|
||||
if ((msg->body->value.ir = OSSL_CRMF_MSGS_new()) == NULL)
|
||||
goto err;
|
||||
return msg;
|
||||
|
||||
case OSSL_CMP_PKIBODY_P10CR:
|
||||
if (ctx->p10CSR == NULL) {
|
||||
CMPerr(0, CMP_R_ERROR_CREATING_P10CR);
|
||||
goto err;
|
||||
}
|
||||
if ((msg->body->value.p10cr = X509_REQ_dup(ctx->p10CSR)) == NULL)
|
||||
goto err;
|
||||
return msg;
|
||||
|
||||
case OSSL_CMP_PKIBODY_IP:
|
||||
case OSSL_CMP_PKIBODY_CP:
|
||||
case OSSL_CMP_PKIBODY_KUP:
|
||||
if ((msg->body->value.ip = OSSL_CMP_CERTREPMESSAGE_new()) == NULL)
|
||||
goto err;
|
||||
return msg;
|
||||
|
||||
case OSSL_CMP_PKIBODY_RR:
|
||||
if ((msg->body->value.rr = sk_OSSL_CMP_REVDETAILS_new_null()) == NULL)
|
||||
goto err;
|
||||
return msg;
|
||||
case OSSL_CMP_PKIBODY_RP:
|
||||
if ((msg->body->value.rp = OSSL_CMP_REVREPCONTENT_new()) == NULL)
|
||||
goto err;
|
||||
return msg;
|
||||
|
||||
case OSSL_CMP_PKIBODY_CERTCONF:
|
||||
if ((msg->body->value.certConf =
|
||||
sk_OSSL_CMP_CERTSTATUS_new_null()) == NULL)
|
||||
goto err;
|
||||
return msg;
|
||||
case OSSL_CMP_PKIBODY_PKICONF:
|
||||
if ((msg->body->value.pkiconf = ASN1_TYPE_new()) == NULL)
|
||||
goto err;
|
||||
ASN1_TYPE_set(msg->body->value.pkiconf, V_ASN1_NULL, NULL);
|
||||
return msg;
|
||||
|
||||
case OSSL_CMP_PKIBODY_POLLREQ:
|
||||
if ((msg->body->value.pollReq = sk_OSSL_CMP_POLLREQ_new_null()) == NULL)
|
||||
goto err;
|
||||
return msg;
|
||||
case OSSL_CMP_PKIBODY_POLLREP:
|
||||
if ((msg->body->value.pollRep = sk_OSSL_CMP_POLLREP_new_null()) == NULL)
|
||||
goto err;
|
||||
return msg;
|
||||
|
||||
case OSSL_CMP_PKIBODY_GENM:
|
||||
case OSSL_CMP_PKIBODY_GENP:
|
||||
if ((msg->body->value.genm = sk_OSSL_CMP_ITAV_new_null()) == NULL)
|
||||
goto err;
|
||||
return msg;
|
||||
|
||||
case OSSL_CMP_PKIBODY_ERROR:
|
||||
if ((msg->body->value.error = OSSL_CMP_ERRORMSGCONTENT_new()) == NULL)
|
||||
goto err;
|
||||
return msg;
|
||||
|
||||
default:
|
||||
CMPerr(0, CMP_R_UNEXPECTED_PKIBODY);
|
||||
goto err;
|
||||
}
|
||||
|
||||
err:
|
||||
OSSL_CMP_MSG_free(msg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#define HAS_SAN(ctx) \
|
||||
(sk_GENERAL_NAME_num((ctx)->subjectAltNames) > 0 \
|
||||
|| OSSL_CMP_CTX_reqExtensions_have_SAN(ctx) == 1)
|
||||
|
||||
static X509_NAME *determine_subj(OSSL_CMP_CTX *ctx, X509 *refcert,
|
||||
int bodytype)
|
||||
{
|
||||
if (ctx->subjectName != NULL)
|
||||
return ctx->subjectName;
|
||||
|
||||
if (refcert != NULL
|
||||
&& (bodytype == OSSL_CMP_PKIBODY_KUR || !HAS_SAN(ctx)))
|
||||
/*
|
||||
* For KUR, copy subjectName from reference certificate.
|
||||
* For IR or CR, do the same only if there is no subjectAltName.
|
||||
*/
|
||||
return X509_get_subject_name(refcert);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Create CRMF certificate request message for IR/CR/KUR
|
||||
* returns a pointer to the OSSL_CRMF_MSG on success, NULL on error
|
||||
*/
|
||||
static OSSL_CRMF_MSG *crm_new(OSSL_CMP_CTX *ctx, int bodytype,
|
||||
int rid, EVP_PKEY *rkey)
|
||||
{
|
||||
OSSL_CRMF_MSG *crm = NULL;
|
||||
X509 *refcert = ctx->oldCert != NULL ? ctx->oldCert : ctx->clCert;
|
||||
/* refcert defaults to current client cert */
|
||||
STACK_OF(GENERAL_NAME) *default_sans = NULL;
|
||||
X509_NAME *subject = determine_subj(ctx, refcert, bodytype);
|
||||
int crit = ctx->setSubjectAltNameCritical || subject == NULL;
|
||||
/* RFC5280: subjectAltName MUST be critical if subject is null */
|
||||
X509_EXTENSIONS *exts = NULL;
|
||||
|
||||
if (rkey == NULL
|
||||
|| (bodytype == OSSL_CMP_PKIBODY_KUR && refcert == NULL)) {
|
||||
CMPerr(0, CMP_R_INVALID_ARGS);
|
||||
return NULL;
|
||||
}
|
||||
if ((crm = OSSL_CRMF_MSG_new()) == NULL)
|
||||
return NULL;
|
||||
if (!OSSL_CRMF_MSG_set_certReqId(crm, rid)
|
||||
/*
|
||||
* fill certTemplate, corresponding to CertificationRequestInfo
|
||||
* of PKCS#10. The rkey param cannot be NULL so far -
|
||||
* it could be NULL if centralized key creation was supported
|
||||
*/
|
||||
|| !OSSL_CRMF_CERTTEMPLATE_fill(OSSL_CRMF_MSG_get0_tmpl(crm), rkey,
|
||||
subject, ctx->issuer,
|
||||
NULL/* serial */))
|
||||
goto err;
|
||||
if (ctx->days != 0) {
|
||||
time_t notBefore, notAfter;
|
||||
|
||||
notBefore = time(NULL);
|
||||
notAfter = notBefore + 60 * 60 * 24 * ctx->days;
|
||||
if (!OSSL_CRMF_MSG_set_validity(crm, notBefore, notAfter))
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* extensions */
|
||||
if (refcert != NULL && !ctx->SubjectAltName_nodefault)
|
||||
default_sans = X509V3_get_d2i(X509_get0_extensions(refcert),
|
||||
NID_subject_alt_name, NULL, NULL);
|
||||
/* exts are copied from ctx to allow reuse */
|
||||
if (ctx->reqExtensions != NULL) {
|
||||
exts = sk_X509_EXTENSION_deep_copy(ctx->reqExtensions,
|
||||
X509_EXTENSION_dup,
|
||||
X509_EXTENSION_free);
|
||||
if (exts == NULL)
|
||||
goto err;
|
||||
}
|
||||
if (sk_GENERAL_NAME_num(ctx->subjectAltNames) > 0
|
||||
&& !add1_extension(&exts, NID_subject_alt_name,
|
||||
crit, ctx->subjectAltNames))
|
||||
goto err;
|
||||
if (!HAS_SAN(ctx) && default_sans != NULL
|
||||
&& !add1_extension(&exts, NID_subject_alt_name, crit, default_sans))
|
||||
goto err;
|
||||
if (ctx->policies != NULL
|
||||
&& !add1_extension(&exts, NID_certificate_policies,
|
||||
ctx->setPoliciesCritical, ctx->policies))
|
||||
goto err;
|
||||
if (!OSSL_CRMF_MSG_set0_extensions(crm, exts))
|
||||
goto err;
|
||||
exts = NULL;
|
||||
/* end fill certTemplate, now set any controls */
|
||||
|
||||
/* for KUR, set OldCertId according to D.6 */
|
||||
if (bodytype == OSSL_CMP_PKIBODY_KUR) {
|
||||
OSSL_CRMF_CERTID *cid =
|
||||
OSSL_CRMF_CERTID_gen(X509_get_issuer_name(refcert),
|
||||
X509_get_serialNumber(refcert));
|
||||
int ret;
|
||||
|
||||
if (cid == NULL)
|
||||
goto err;
|
||||
ret = OSSL_CRMF_MSG_set1_regCtrl_oldCertID(crm, cid);
|
||||
OSSL_CRMF_CERTID_free(cid);
|
||||
if (ret == 0)
|
||||
goto err;
|
||||
}
|
||||
|
||||
goto end;
|
||||
|
||||
err:
|
||||
OSSL_CRMF_MSG_free(crm);
|
||||
crm = NULL;
|
||||
|
||||
end:
|
||||
sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
|
||||
sk_GENERAL_NAME_pop_free(default_sans, GENERAL_NAME_free);
|
||||
return crm;
|
||||
}
|
||||
|
||||
OSSL_CMP_MSG *ossl_cmp_certReq_new(OSSL_CMP_CTX *ctx, int type, int err_code)
|
||||
{
|
||||
EVP_PKEY *rkey;
|
||||
EVP_PKEY *privkey;
|
||||
OSSL_CMP_MSG *msg;
|
||||
OSSL_CRMF_MSG *crm = NULL;
|
||||
|
||||
if (!ossl_assert(ctx != NULL))
|
||||
return NULL;
|
||||
|
||||
rkey = OSSL_CMP_CTX_get0_newPkey(ctx, 0);
|
||||
if (rkey == NULL)
|
||||
return NULL;
|
||||
privkey = OSSL_CMP_CTX_get0_newPkey(ctx, 1);
|
||||
|
||||
if (type != OSSL_CMP_PKIBODY_IR && type != OSSL_CMP_PKIBODY_CR
|
||||
&& type != OSSL_CMP_PKIBODY_KUR && type != OSSL_CMP_PKIBODY_P10CR) {
|
||||
CMPerr(0, CMP_R_INVALID_ARGS);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((msg = ossl_cmp_msg_create(ctx, type)) == NULL)
|
||||
goto err;
|
||||
|
||||
/* header */
|
||||
if (ctx->implicitConfirm && !ossl_cmp_hdr_set_implicitConfirm(msg->header))
|
||||
goto err;
|
||||
|
||||
/* body */
|
||||
/* For P10CR the content has already been set in OSSL_CMP_MSG_create */
|
||||
if (type != OSSL_CMP_PKIBODY_P10CR) {
|
||||
if (ctx->popoMethod == OSSL_CRMF_POPO_SIGNATURE && privkey == NULL) {
|
||||
CMPerr(0, CMP_R_MISSING_PRIVATE_KEY);
|
||||
goto err;
|
||||
}
|
||||
if ((crm = crm_new(ctx, type, OSSL_CMP_CERTREQID, rkey)) == NULL
|
||||
|| !OSSL_CRMF_MSG_create_popo(crm, privkey, ctx->digest,
|
||||
ctx->popoMethod)
|
||||
/* value.ir is same for cr and kur */
|
||||
|| !sk_OSSL_CRMF_MSG_push(msg->body->value.ir, crm))
|
||||
goto err;
|
||||
crm = NULL;
|
||||
/* TODO: here optional 2nd certreqmsg could be pushed to the stack */
|
||||
}
|
||||
|
||||
if (!ossl_cmp_msg_protect(ctx, msg))
|
||||
goto err;
|
||||
|
||||
return msg;
|
||||
|
||||
err:
|
||||
CMPerr(0, err_code);
|
||||
OSSL_CRMF_MSG_free(crm);
|
||||
OSSL_CMP_MSG_free(msg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
OSSL_CMP_MSG *ossl_cmp_certRep_new(OSSL_CMP_CTX *ctx, int bodytype,
|
||||
int certReqId, OSSL_CMP_PKISI *si,
|
||||
X509 *cert, STACK_OF(X509) *chain,
|
||||
STACK_OF(X509) *caPubs, int encrypted,
|
||||
int unprotectedErrors)
|
||||
{
|
||||
OSSL_CMP_MSG *msg = NULL;
|
||||
OSSL_CMP_CERTREPMESSAGE *repMsg = NULL;
|
||||
OSSL_CMP_CERTRESPONSE *resp = NULL;
|
||||
int status = -1;
|
||||
|
||||
if (!ossl_assert(ctx != NULL && si != NULL))
|
||||
return NULL;
|
||||
|
||||
if ((msg = ossl_cmp_msg_create(ctx, bodytype)) == NULL)
|
||||
goto err;
|
||||
repMsg = msg->body->value.ip; /* value.ip is same for cp and kup */
|
||||
|
||||
/* header */
|
||||
if (ctx->implicitConfirm && !ossl_cmp_hdr_set_implicitConfirm(msg->header))
|
||||
goto err;
|
||||
|
||||
/* body */
|
||||
if ((resp = OSSL_CMP_CERTRESPONSE_new()) == NULL)
|
||||
goto err;
|
||||
OSSL_CMP_PKISI_free(resp->status);
|
||||
if ((resp->status = OSSL_CMP_PKISI_dup(si)) == NULL
|
||||
|| !ASN1_INTEGER_set(resp->certReqId, certReqId))
|
||||
goto err;
|
||||
|
||||
status = ossl_cmp_pkisi_get_pkistatus(resp->status);
|
||||
if (status != OSSL_CMP_PKISTATUS_rejection
|
||||
&& status != OSSL_CMP_PKISTATUS_waiting && cert != NULL) {
|
||||
if (encrypted) {
|
||||
CMPerr(0, CMP_R_INVALID_ARGS);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if ((resp->certifiedKeyPair = OSSL_CMP_CERTIFIEDKEYPAIR_new())
|
||||
== NULL)
|
||||
goto err;
|
||||
resp->certifiedKeyPair->certOrEncCert->type =
|
||||
OSSL_CMP_CERTORENCCERT_CERTIFICATE;
|
||||
if (!X509_up_ref(cert))
|
||||
goto err;
|
||||
resp->certifiedKeyPair->certOrEncCert->value.certificate = cert;
|
||||
}
|
||||
|
||||
if (!sk_OSSL_CMP_CERTRESPONSE_push(repMsg->response, resp))
|
||||
goto err;
|
||||
resp = NULL;
|
||||
/* TODO: here optional 2nd certrep could be pushed to the stack */
|
||||
|
||||
if (bodytype == OSSL_CMP_PKIBODY_IP && caPubs != NULL
|
||||
&& (repMsg->caPubs = X509_chain_up_ref(caPubs)) == NULL)
|
||||
goto err;
|
||||
if (chain != NULL
|
||||
&& !ossl_cmp_sk_X509_add1_certs(msg->extraCerts, chain, 0, 1, 0))
|
||||
goto err;
|
||||
|
||||
if (!unprotectedErrors
|
||||
|| ossl_cmp_pkisi_get_pkistatus(si) != OSSL_CMP_PKISTATUS_rejection)
|
||||
if (!ossl_cmp_msg_protect(ctx, msg))
|
||||
goto err;
|
||||
|
||||
return msg;
|
||||
|
||||
err:
|
||||
CMPerr(0, CMP_R_ERROR_CREATING_CERTREP);
|
||||
OSSL_CMP_CERTRESPONSE_free(resp);
|
||||
OSSL_CMP_MSG_free(msg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
OSSL_CMP_MSG *ossl_cmp_rr_new(OSSL_CMP_CTX *ctx)
|
||||
{
|
||||
OSSL_CMP_MSG *msg = NULL;
|
||||
OSSL_CMP_REVDETAILS *rd;
|
||||
|
||||
if (!ossl_assert(ctx != NULL && ctx->oldCert != NULL))
|
||||
return NULL;
|
||||
|
||||
if ((rd = OSSL_CMP_REVDETAILS_new()) == NULL)
|
||||
goto err;
|
||||
|
||||
/* Fill the template from the contents of the certificate to be revoked */
|
||||
if (!OSSL_CRMF_CERTTEMPLATE_fill(rd->certDetails,
|
||||
NULL/* pubkey would be redundant */,
|
||||
NULL/* subject would be redundant */,
|
||||
X509_get_issuer_name(ctx->oldCert),
|
||||
X509_get_serialNumber(ctx->oldCert)))
|
||||
goto err;
|
||||
|
||||
/* revocation reason code is optional */
|
||||
if (ctx->revocationReason != CRL_REASON_NONE
|
||||
&& !add_crl_reason_extension(&rd->crlEntryDetails,
|
||||
ctx->revocationReason))
|
||||
goto err;
|
||||
|
||||
if ((msg = ossl_cmp_msg_create(ctx, OSSL_CMP_PKIBODY_RR)) == NULL)
|
||||
goto err;
|
||||
|
||||
if (!sk_OSSL_CMP_REVDETAILS_push(msg->body->value.rr, rd))
|
||||
goto err;
|
||||
rd = NULL;
|
||||
|
||||
/*
|
||||
* TODO: the Revocation Passphrase according to section 5.3.19.9 could be
|
||||
* set here if set in ctx
|
||||
*/
|
||||
|
||||
if (!ossl_cmp_msg_protect(ctx, msg))
|
||||
goto err;
|
||||
|
||||
return msg;
|
||||
|
||||
err:
|
||||
CMPerr(0, CMP_R_ERROR_CREATING_RR);
|
||||
OSSL_CMP_MSG_free(msg);
|
||||
OSSL_CMP_REVDETAILS_free(rd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
OSSL_CMP_MSG *ossl_cmp_rp_new(OSSL_CMP_CTX *ctx, OSSL_CMP_PKISI *si,
|
||||
OSSL_CRMF_CERTID *cid, int unprot_err)
|
||||
{
|
||||
OSSL_CMP_REVREPCONTENT *rep = NULL;
|
||||
OSSL_CMP_PKISI *si1 = NULL;
|
||||
OSSL_CRMF_CERTID *cid_copy = NULL;
|
||||
OSSL_CMP_MSG *msg = NULL;
|
||||
|
||||
if (!ossl_assert(ctx != NULL && si != NULL && cid != NULL))
|
||||
return NULL;
|
||||
|
||||
if ((msg = ossl_cmp_msg_create(ctx, OSSL_CMP_PKIBODY_RP)) == NULL)
|
||||
goto err;
|
||||
rep = msg->body->value.rp;
|
||||
|
||||
if ((si1 = OSSL_CMP_PKISI_dup(si)) == NULL)
|
||||
goto err;
|
||||
|
||||
if (!sk_OSSL_CMP_PKISI_push(rep->status, si1)) {
|
||||
OSSL_CMP_PKISI_free(si1);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if ((rep->revCerts = sk_OSSL_CRMF_CERTID_new_null()) == NULL)
|
||||
goto err;
|
||||
if ((cid_copy = OSSL_CRMF_CERTID_dup(cid)) == NULL)
|
||||
goto err;
|
||||
if (!sk_OSSL_CRMF_CERTID_push(rep->revCerts, cid_copy)) {
|
||||
OSSL_CRMF_CERTID_free(cid_copy);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!unprot_err
|
||||
|| ossl_cmp_pkisi_get_pkistatus(si) != OSSL_CMP_PKISTATUS_rejection)
|
||||
if (!ossl_cmp_msg_protect(ctx, msg))
|
||||
goto err;
|
||||
|
||||
return msg;
|
||||
|
||||
err:
|
||||
CMPerr(0, CMP_R_ERROR_CREATING_RP);
|
||||
OSSL_CMP_MSG_free(msg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
OSSL_CMP_MSG *ossl_cmp_pkiconf_new(OSSL_CMP_CTX *ctx)
|
||||
{
|
||||
OSSL_CMP_MSG *msg;
|
||||
|
||||
if (!ossl_assert(ctx != NULL))
|
||||
return NULL;
|
||||
|
||||
if ((msg = ossl_cmp_msg_create(ctx, OSSL_CMP_PKIBODY_PKICONF)) == NULL)
|
||||
goto err;
|
||||
if (ossl_cmp_msg_protect(ctx, msg))
|
||||
return msg;
|
||||
|
||||
err:
|
||||
CMPerr(0, CMP_R_ERROR_CREATING_PKICONF);
|
||||
OSSL_CMP_MSG_free(msg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int ossl_cmp_msg_gen_push0_ITAV(OSSL_CMP_MSG *msg, OSSL_CMP_ITAV *itav)
|
||||
{
|
||||
int bodytype;
|
||||
|
||||
if (!ossl_assert(msg != NULL && itav != NULL))
|
||||
return 0;
|
||||
|
||||
bodytype = ossl_cmp_msg_get_bodytype(msg);
|
||||
if (bodytype != OSSL_CMP_PKIBODY_GENM
|
||||
&& bodytype != OSSL_CMP_PKIBODY_GENP) {
|
||||
CMPerr(0, CMP_R_INVALID_ARGS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* value.genp has the same structure, so this works for genp as well */
|
||||
return OSSL_CMP_ITAV_push0_stack_item(&msg->body->value.genm, itav);
|
||||
}
|
||||
|
||||
int ossl_cmp_msg_gen_push1_ITAVs(OSSL_CMP_MSG *msg,
|
||||
STACK_OF(OSSL_CMP_ITAV) *itavs)
|
||||
{
|
||||
int i;
|
||||
OSSL_CMP_ITAV *itav = NULL;
|
||||
|
||||
if (!ossl_assert(msg != NULL))
|
||||
return 0;
|
||||
|
||||
for (i = 0; i < sk_OSSL_CMP_ITAV_num(itavs); i++) {
|
||||
if ((itav = OSSL_CMP_ITAV_dup(sk_OSSL_CMP_ITAV_value(itavs,i))) == NULL)
|
||||
return 0;
|
||||
if (!ossl_cmp_msg_gen_push0_ITAV(msg, itav)) {
|
||||
OSSL_CMP_ITAV_free(itav);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Creates a new General Message/Response with an empty itav stack
|
||||
* returns a pointer to the PKIMessage on success, NULL on error
|
||||
*/
|
||||
static OSSL_CMP_MSG *gen_new(OSSL_CMP_CTX *ctx, int body_type, int err_code)
|
||||
{
|
||||
OSSL_CMP_MSG *msg = NULL;
|
||||
|
||||
if (!ossl_assert(ctx != NULL))
|
||||
return NULL;
|
||||
|
||||
if ((msg = ossl_cmp_msg_create(ctx, body_type)) == NULL)
|
||||
return NULL;
|
||||
|
||||
if (ctx->genm_ITAVs != NULL
|
||||
&& !ossl_cmp_msg_gen_push1_ITAVs(msg, ctx->genm_ITAVs))
|
||||
goto err;
|
||||
|
||||
if (!ossl_cmp_msg_protect(ctx, msg))
|
||||
goto err;
|
||||
|
||||
return msg;
|
||||
|
||||
err:
|
||||
CMPerr(0, err_code);
|
||||
OSSL_CMP_MSG_free(msg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
OSSL_CMP_MSG *ossl_cmp_genm_new(OSSL_CMP_CTX *ctx)
|
||||
{
|
||||
return gen_new(ctx, OSSL_CMP_PKIBODY_GENM, CMP_R_ERROR_CREATING_GENM);
|
||||
}
|
||||
|
||||
OSSL_CMP_MSG *ossl_cmp_genp_new(OSSL_CMP_CTX *ctx)
|
||||
{
|
||||
return gen_new(ctx, OSSL_CMP_PKIBODY_GENP, CMP_R_ERROR_CREATING_GENP);
|
||||
}
|
||||
|
||||
OSSL_CMP_MSG *ossl_cmp_error_new(OSSL_CMP_CTX *ctx, OSSL_CMP_PKISI *si,
|
||||
int errorCode,
|
||||
OSSL_CMP_PKIFREETEXT *errorDetails,
|
||||
int unprotected)
|
||||
{
|
||||
OSSL_CMP_MSG *msg = NULL;
|
||||
|
||||
if (!ossl_assert(ctx != NULL && si != NULL))
|
||||
return NULL;
|
||||
|
||||
if ((msg = ossl_cmp_msg_create(ctx, OSSL_CMP_PKIBODY_ERROR)) == NULL)
|
||||
goto err;
|
||||
|
||||
OSSL_CMP_PKISI_free(msg->body->value.error->pKIStatusInfo);
|
||||
if ((msg->body->value.error->pKIStatusInfo = OSSL_CMP_PKISI_dup(si))
|
||||
== NULL)
|
||||
goto err;
|
||||
if (errorCode >= 0) {
|
||||
if ((msg->body->value.error->errorCode = ASN1_INTEGER_new()) == NULL)
|
||||
goto err;
|
||||
if (!ASN1_INTEGER_set(msg->body->value.error->errorCode, errorCode))
|
||||
goto err;
|
||||
}
|
||||
if (errorDetails != NULL)
|
||||
if ((msg->body->value.error->errorDetails =
|
||||
sk_ASN1_UTF8STRING_deep_copy(errorDetails, ASN1_STRING_dup,
|
||||
ASN1_STRING_free)) == NULL)
|
||||
goto err;
|
||||
|
||||
if (!unprotected && !ossl_cmp_msg_protect(ctx, msg))
|
||||
goto err;
|
||||
return msg;
|
||||
|
||||
err:
|
||||
CMPerr(0, CMP_R_ERROR_CREATING_ERROR);
|
||||
OSSL_CMP_MSG_free(msg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* OSSL_CMP_CERTSTATUS_set_certHash() calculates a hash of the certificate,
|
||||
* using the same hash algorithm as is used to create and verify the
|
||||
* certificate signature, and places the hash into the certHash field of a
|
||||
* OSSL_CMP_CERTSTATUS structure. This is used in the certConf message,
|
||||
* for example, to confirm that the certificate was received successfully.
|
||||
*/
|
||||
int ossl_cmp_certstatus_set_certHash(OSSL_CMP_CERTSTATUS *certStatus,
|
||||
const X509 *cert)
|
||||
{
|
||||
unsigned int len;
|
||||
unsigned char hash[EVP_MAX_MD_SIZE];
|
||||
int md_NID;
|
||||
const EVP_MD *md = NULL;
|
||||
|
||||
if (!ossl_assert(certStatus != NULL && cert != NULL))
|
||||
return 0;
|
||||
|
||||
/*-
|
||||
* select hash algorithm, as stated in Appendix F. Compilable ASN.1 defs:
|
||||
* the hash of the certificate, using the same hash algorithm
|
||||
* as is used to create and verify the certificate signature
|
||||
*/
|
||||
if (OBJ_find_sigid_algs(X509_get_signature_nid(cert), &md_NID, NULL)
|
||||
&& (md = EVP_get_digestbynid(md_NID)) != NULL) {
|
||||
if (!X509_digest(cert, md, hash, &len))
|
||||
goto err;
|
||||
if (!ossl_cmp_asn1_octet_string_set1_bytes(&certStatus->certHash, hash,
|
||||
len))
|
||||
goto err;
|
||||
} else {
|
||||
CMPerr(0, CMP_R_UNSUPPORTED_ALGORITHM);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
err:
|
||||
CMPerr(0, CMP_R_ERROR_SETTING_CERTHASH);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO: handle potential 2nd certificate when signing and encrypting
|
||||
* certificates have been requested/received
|
||||
*/
|
||||
OSSL_CMP_MSG *ossl_cmp_certConf_new(OSSL_CMP_CTX *ctx, int fail_info,
|
||||
const char *text)
|
||||
{
|
||||
OSSL_CMP_MSG *msg = NULL;
|
||||
OSSL_CMP_CERTSTATUS *certStatus = NULL;
|
||||
OSSL_CMP_PKISI *sinfo;
|
||||
|
||||
if (!ossl_assert(ctx != NULL && ctx->newCert != NULL))
|
||||
return NULL;
|
||||
|
||||
if ((unsigned)fail_info > OSSL_CMP_PKIFAILUREINFO_MAX_BIT_PATTERN) {
|
||||
CMPerr(0, CMP_R_FAIL_INFO_OUT_OF_RANGE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((msg = ossl_cmp_msg_create(ctx, OSSL_CMP_PKIBODY_CERTCONF)) == NULL)
|
||||
goto err;
|
||||
|
||||
if ((certStatus = OSSL_CMP_CERTSTATUS_new()) == NULL)
|
||||
goto err;
|
||||
/* consume certStatus into msg right away so it gets deallocated with msg */
|
||||
if (!sk_OSSL_CMP_CERTSTATUS_push(msg->body->value.certConf, certStatus))
|
||||
goto err;
|
||||
/* set the ID of the certReq */
|
||||
if (!ASN1_INTEGER_set(certStatus->certReqId, OSSL_CMP_CERTREQID))
|
||||
goto err;
|
||||
/*
|
||||
* the hash of the certificate, using the same hash algorithm
|
||||
* as is used to create and verify the certificate signature
|
||||
*/
|
||||
if (!ossl_cmp_certstatus_set_certHash(certStatus, ctx->newCert))
|
||||
goto err;
|
||||
/*
|
||||
* For any particular CertStatus, omission of the statusInfo field
|
||||
* indicates ACCEPTANCE of the specified certificate. Alternatively,
|
||||
* explicit status details (with respect to acceptance or rejection) MAY
|
||||
* be provided in the statusInfo field, perhaps for auditing purposes at
|
||||
* the CA/RA.
|
||||
*/
|
||||
sinfo = fail_info != 0 ?
|
||||
ossl_cmp_statusinfo_new(OSSL_CMP_PKISTATUS_rejection, fail_info, text) :
|
||||
ossl_cmp_statusinfo_new(OSSL_CMP_PKISTATUS_accepted, 0, text);
|
||||
if (sinfo == NULL)
|
||||
goto err;
|
||||
certStatus->statusInfo = sinfo;
|
||||
|
||||
if (!ossl_cmp_msg_protect(ctx, msg))
|
||||
goto err;
|
||||
|
||||
return msg;
|
||||
|
||||
err:
|
||||
CMPerr(0, CMP_R_ERROR_CREATING_CERTCONF);
|
||||
OSSL_CMP_MSG_free(msg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
OSSL_CMP_MSG *ossl_cmp_pollReq_new(OSSL_CMP_CTX *ctx, int crid)
|
||||
{
|
||||
OSSL_CMP_MSG *msg = NULL;
|
||||
OSSL_CMP_POLLREQ *preq = NULL;
|
||||
|
||||
if (!ossl_assert(ctx != NULL))
|
||||
return NULL;
|
||||
|
||||
if ((msg = ossl_cmp_msg_create(ctx, OSSL_CMP_PKIBODY_POLLREQ)) == NULL)
|
||||
goto err;
|
||||
|
||||
/* TODO: support multiple cert request IDs to poll */
|
||||
if ((preq = OSSL_CMP_POLLREQ_new()) == NULL
|
||||
|| !ASN1_INTEGER_set(preq->certReqId, crid)
|
||||
|| !sk_OSSL_CMP_POLLREQ_push(msg->body->value.pollReq, preq))
|
||||
goto err;
|
||||
|
||||
preq = NULL;
|
||||
if (!ossl_cmp_msg_protect(ctx, msg))
|
||||
goto err;
|
||||
|
||||
return msg;
|
||||
|
||||
err:
|
||||
CMPerr(0, CMP_R_ERROR_CREATING_POLLREQ);
|
||||
OSSL_CMP_POLLREQ_free(preq);
|
||||
OSSL_CMP_MSG_free(msg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
OSSL_CMP_MSG *ossl_cmp_pollRep_new(OSSL_CMP_CTX *ctx, int crid,
|
||||
int64_t poll_after)
|
||||
{
|
||||
OSSL_CMP_MSG *msg;
|
||||
OSSL_CMP_POLLREP *prep;
|
||||
|
||||
if (!ossl_assert(ctx != NULL))
|
||||
return NULL;
|
||||
|
||||
if ((msg = ossl_cmp_msg_create(ctx, OSSL_CMP_PKIBODY_POLLREP)) == NULL)
|
||||
goto err;
|
||||
if ((prep = OSSL_CMP_POLLREP_new()) == NULL)
|
||||
goto err;
|
||||
if (!sk_OSSL_CMP_POLLREP_push(msg->body->value.pollRep, prep))
|
||||
goto err;
|
||||
if (!ASN1_INTEGER_set(prep->certReqId, crid))
|
||||
goto err;
|
||||
if (!ASN1_INTEGER_set_int64(prep->checkAfter, poll_after))
|
||||
goto err;
|
||||
|
||||
if (!ossl_cmp_msg_protect(ctx, msg))
|
||||
goto err;
|
||||
return msg;
|
||||
|
||||
err:
|
||||
CMPerr(0, CMP_R_ERROR_CREATING_POLLREP);
|
||||
OSSL_CMP_MSG_free(msg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*-
|
||||
* returns the status field of the RevRepContent with the given
|
||||
* request/sequence id inside a revocation response.
|
||||
* RevRepContent has the revocation statuses in same order as they were sent in
|
||||
* RevReqContent.
|
||||
* returns NULL on error
|
||||
*/
|
||||
OSSL_CMP_PKISI *
|
||||
ossl_cmp_revrepcontent_get_pkistatusinfo(OSSL_CMP_REVREPCONTENT *rrep, int rsid)
|
||||
{
|
||||
OSSL_CMP_PKISI *status;
|
||||
|
||||
if (!ossl_assert(rrep != NULL))
|
||||
return NULL;
|
||||
|
||||
if ((status = sk_OSSL_CMP_PKISI_value(rrep->status, rsid)) != NULL)
|
||||
return status;
|
||||
|
||||
CMPerr(0, CMP_R_PKISTATUSINFO_NOT_FOUND);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* returns the CertId field in the revCerts part of the RevRepContent
|
||||
* with the given request/sequence id inside a revocation response.
|
||||
* RevRepContent has the CertIds in same order as they were sent in
|
||||
* RevReqContent.
|
||||
* returns NULL on error
|
||||
*/
|
||||
OSSL_CRMF_CERTID *
|
||||
ossl_cmp_revrepcontent_get_CertId(OSSL_CMP_REVREPCONTENT *rrep, int rsid)
|
||||
{
|
||||
OSSL_CRMF_CERTID *cid = NULL;
|
||||
|
||||
if (!ossl_assert(rrep != NULL))
|
||||
return NULL;
|
||||
|
||||
if ((cid = sk_OSSL_CRMF_CERTID_value(rrep->revCerts, rsid)) != NULL)
|
||||
return cid;
|
||||
|
||||
CMPerr(0, CMP_R_CERTID_NOT_FOUND);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int suitable_rid(const ASN1_INTEGER *certReqId, int rid)
|
||||
{
|
||||
int trid;
|
||||
|
||||
if (rid == -1)
|
||||
return 1;
|
||||
|
||||
trid = ossl_cmp_asn1_get_int(certReqId);
|
||||
|
||||
if (trid == -1) {
|
||||
CMPerr(0, CMP_R_BAD_REQUEST_ID);
|
||||
return 0;
|
||||
}
|
||||
return rid == trid;
|
||||
}
|
||||
|
||||
static void add_expected_rid(int rid)
|
||||
{
|
||||
char str[DECIMAL_SIZE(rid) + 1];
|
||||
|
||||
BIO_snprintf(str, sizeof(str), "%d", rid);
|
||||
ERR_add_error_data(2, "expected certReqId = ", str);
|
||||
}
|
||||
|
||||
/*
|
||||
* returns a pointer to the PollResponse with the given CertReqId
|
||||
* (or the first one in case -1) inside a PollRepContent
|
||||
* returns NULL on error or if no suitable PollResponse available
|
||||
*/
|
||||
OSSL_CMP_POLLREP *
|
||||
ossl_cmp_pollrepcontent_get0_pollrep(const OSSL_CMP_POLLREPCONTENT *prc,
|
||||
int rid)
|
||||
{
|
||||
OSSL_CMP_POLLREP *pollRep = NULL;
|
||||
int i;
|
||||
|
||||
if (!ossl_assert(prc != NULL))
|
||||
return NULL;
|
||||
|
||||
for (i = 0; i < sk_OSSL_CMP_POLLREP_num(prc); i++) {
|
||||
pollRep = sk_OSSL_CMP_POLLREP_value(prc, i);
|
||||
if (suitable_rid(pollRep->certReqId, rid))
|
||||
return pollRep;
|
||||
}
|
||||
|
||||
CMPerr(0, CMP_R_CERTRESPONSE_NOT_FOUND);
|
||||
add_expected_rid(rid);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* returns a pointer to the CertResponse with the given CertReqId
|
||||
* (or the first one in case -1) inside a CertRepMessage
|
||||
* returns NULL on error or if no suitable CertResponse available
|
||||
*/
|
||||
OSSL_CMP_CERTRESPONSE *
|
||||
ossl_cmp_certrepmessage_get0_certresponse(const OSSL_CMP_CERTREPMESSAGE *crm,
|
||||
int rid)
|
||||
{
|
||||
OSSL_CMP_CERTRESPONSE *crep = NULL;
|
||||
int i;
|
||||
|
||||
if (!ossl_assert(crm != NULL && crm->response != NULL))
|
||||
return NULL;
|
||||
|
||||
for (i = 0; i < sk_OSSL_CMP_CERTRESPONSE_num(crm->response); i++) {
|
||||
crep = sk_OSSL_CMP_CERTRESPONSE_value(crm->response, i);
|
||||
if (suitable_rid(crep->certReqId, rid))
|
||||
return crep;
|
||||
}
|
||||
|
||||
CMPerr(0, CMP_R_CERTRESPONSE_NOT_FOUND);
|
||||
add_expected_rid(rid);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* CMP_CERTRESPONSE_get1_certificate() attempts to retrieve the returned
|
||||
* certificate from the given certResponse B<crep>.
|
||||
* Uses the privkey in case of indirect POP from B<ctx>.
|
||||
* Returns a pointer to a copy of the found certificate, or NULL if not found.
|
||||
*/
|
||||
X509 *ossl_cmp_certresponse_get1_certificate(EVP_PKEY *privkey,
|
||||
const OSSL_CMP_CERTRESPONSE *crep)
|
||||
{
|
||||
OSSL_CMP_CERTORENCCERT *coec;
|
||||
X509 *crt = NULL;
|
||||
|
||||
if (!ossl_assert(crep != NULL))
|
||||
return NULL;
|
||||
|
||||
if (crep->certifiedKeyPair
|
||||
&& (coec = crep->certifiedKeyPair->certOrEncCert) != NULL) {
|
||||
switch (coec->type) {
|
||||
case OSSL_CMP_CERTORENCCERT_CERTIFICATE:
|
||||
crt = X509_dup(coec->value.certificate);
|
||||
break;
|
||||
case OSSL_CMP_CERTORENCCERT_ENCRYPTEDCERT:
|
||||
/* cert encrypted for indirect PoP; RFC 4210, 5.2.8.2 */
|
||||
if (privkey == NULL) {
|
||||
CMPerr(0, CMP_R_MISSING_PRIVATE_KEY);
|
||||
return NULL;
|
||||
}
|
||||
crt =
|
||||
OSSL_CRMF_ENCRYPTEDVALUE_get1_encCert(coec->value.encryptedCert,
|
||||
privkey);
|
||||
break;
|
||||
default:
|
||||
CMPerr(0, CMP_R_UNKNOWN_CERT_TYPE);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if (crt == NULL)
|
||||
CMPerr(0, CMP_R_CERTIFICATE_NOT_FOUND);
|
||||
return crt;
|
||||
}
|
||||
|
||||
OSSL_CMP_MSG *ossl_cmp_msg_load(const char *file)
|
||||
{
|
||||
OSSL_CMP_MSG *msg = NULL;
|
||||
BIO *bio = NULL;
|
||||
|
||||
if (!ossl_assert(file != NULL))
|
||||
return NULL;
|
||||
|
||||
if ((bio = BIO_new_file(file, "rb")) == NULL)
|
||||
return NULL;
|
||||
msg = OSSL_d2i_CMP_MSG_bio(bio, NULL);
|
||||
BIO_free(bio);
|
||||
return msg;
|
||||
}
|
||||
@@ -0,0 +1,313 @@
|
||||
/*
|
||||
* Copyright 2007-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright Nokia 2007-2019
|
||||
* Copyright Siemens AG 2015-2019
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include "cmp_local.h"
|
||||
|
||||
/* explicit #includes not strictly needed since implied by the above: */
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/cmp.h>
|
||||
#include <openssl/crmf.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/x509.h>
|
||||
|
||||
/*
|
||||
* This function is also used for verification from cmp_vfy.
|
||||
*
|
||||
* Calculate protection for given PKImessage utilizing the given credentials
|
||||
* and the algorithm parameters set inside the message header's protectionAlg.
|
||||
*
|
||||
* Either secret or pkey must be set, the other must be NULL. Attempts doing
|
||||
* PBMAC in case 'secret' is set and signature if 'pkey' is set - but will only
|
||||
* do the protection already marked in msg->header->protectionAlg.
|
||||
*
|
||||
* returns ptr to ASN1_BIT_STRING containing protection on success, else NULL
|
||||
*/
|
||||
ASN1_BIT_STRING *ossl_cmp_calc_protection(const OSSL_CMP_MSG *msg,
|
||||
const ASN1_OCTET_STRING *secret,
|
||||
EVP_PKEY *pkey)
|
||||
{
|
||||
ASN1_BIT_STRING *prot = NULL;
|
||||
CMP_PROTECTEDPART prot_part;
|
||||
const ASN1_OBJECT *algorOID = NULL;
|
||||
int len;
|
||||
size_t prot_part_der_len;
|
||||
unsigned char *prot_part_der = NULL;
|
||||
size_t sig_len;
|
||||
unsigned char *protection = NULL;
|
||||
const void *ppval = NULL;
|
||||
int pptype = 0;
|
||||
OSSL_CRMF_PBMPARAMETER *pbm = NULL;
|
||||
ASN1_STRING *pbm_str = NULL;
|
||||
const unsigned char *pbm_str_uc = NULL;
|
||||
EVP_MD_CTX *evp_ctx = NULL;
|
||||
int md_NID;
|
||||
const EVP_MD *md = NULL;
|
||||
|
||||
if (!ossl_assert(msg != NULL))
|
||||
return NULL;
|
||||
|
||||
/* construct data to be signed */
|
||||
prot_part.header = msg->header;
|
||||
prot_part.body = msg->body;
|
||||
|
||||
len = i2d_CMP_PROTECTEDPART(&prot_part, &prot_part_der);
|
||||
if (len < 0 || prot_part_der == NULL) {
|
||||
CMPerr(0, CMP_R_ERROR_CALCULATING_PROTECTION);
|
||||
goto end;
|
||||
}
|
||||
prot_part_der_len = (size_t) len;
|
||||
|
||||
if (msg->header->protectionAlg == NULL) {
|
||||
CMPerr(0, CMP_R_UNKNOWN_ALGORITHM_ID);
|
||||
goto end;
|
||||
}
|
||||
X509_ALGOR_get0(&algorOID, &pptype, &ppval, msg->header->protectionAlg);
|
||||
|
||||
if (secret != NULL && pkey == NULL) {
|
||||
if (ppval == NULL) {
|
||||
CMPerr(0, CMP_R_ERROR_CALCULATING_PROTECTION);
|
||||
goto end;
|
||||
}
|
||||
if (NID_id_PasswordBasedMAC != OBJ_obj2nid(algorOID)) {
|
||||
CMPerr(0, CMP_R_WRONG_ALGORITHM_OID);
|
||||
goto end;
|
||||
}
|
||||
pbm_str = (ASN1_STRING *)ppval;
|
||||
pbm_str_uc = pbm_str->data;
|
||||
pbm = d2i_OSSL_CRMF_PBMPARAMETER(NULL, &pbm_str_uc, pbm_str->length);
|
||||
if (pbm == NULL) {
|
||||
CMPerr(0, CMP_R_WRONG_ALGORITHM_OID);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!OSSL_CRMF_pbm_new(pbm, prot_part_der, prot_part_der_len,
|
||||
secret->data, secret->length,
|
||||
&protection, &sig_len))
|
||||
goto end;
|
||||
} else if (secret == NULL && pkey != NULL) {
|
||||
/* TODO combine this with large parts of CRMF_poposigningkey_init() */
|
||||
/* EVP_DigestSignInit() checks that pkey type is correct for the alg */
|
||||
|
||||
if (!OBJ_find_sigid_algs(OBJ_obj2nid(algorOID), &md_NID, NULL)
|
||||
|| (md = EVP_get_digestbynid(md_NID)) == NULL
|
||||
|| (evp_ctx = EVP_MD_CTX_new()) == NULL) {
|
||||
CMPerr(0, CMP_R_UNKNOWN_ALGORITHM_ID);
|
||||
goto end;
|
||||
}
|
||||
if (EVP_DigestSignInit(evp_ctx, NULL, md, NULL, pkey) <= 0
|
||||
|| EVP_DigestSignUpdate(evp_ctx, prot_part_der,
|
||||
prot_part_der_len) <= 0
|
||||
|| EVP_DigestSignFinal(evp_ctx, NULL, &sig_len) <= 0
|
||||
|| (protection = OPENSSL_malloc(sig_len)) == NULL
|
||||
|| EVP_DigestSignFinal(evp_ctx, protection, &sig_len) <= 0) {
|
||||
CMPerr(0, CMP_R_ERROR_CALCULATING_PROTECTION);
|
||||
goto end;
|
||||
}
|
||||
} else {
|
||||
CMPerr(0, CMP_R_INVALID_ARGS);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if ((prot = ASN1_BIT_STRING_new()) == NULL)
|
||||
goto end;
|
||||
/* OpenSSL defaults all bit strings to be encoded as ASN.1 NamedBitList */
|
||||
prot->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07);
|
||||
prot->flags |= ASN1_STRING_FLAG_BITS_LEFT;
|
||||
if (!ASN1_BIT_STRING_set(prot, protection, sig_len)) {
|
||||
ASN1_BIT_STRING_free(prot);
|
||||
prot = NULL;
|
||||
}
|
||||
|
||||
end:
|
||||
OSSL_CRMF_PBMPARAMETER_free(pbm);
|
||||
EVP_MD_CTX_free(evp_ctx);
|
||||
OPENSSL_free(protection);
|
||||
OPENSSL_free(prot_part_der);
|
||||
return prot;
|
||||
}
|
||||
|
||||
int ossl_cmp_msg_add_extraCerts(OSSL_CMP_CTX *ctx, OSSL_CMP_MSG *msg)
|
||||
{
|
||||
if (!ossl_assert(ctx != NULL && msg != NULL))
|
||||
return 0;
|
||||
|
||||
if (msg->extraCerts == NULL
|
||||
&& (msg->extraCerts = sk_X509_new_null()) == NULL)
|
||||
return 0;
|
||||
|
||||
if (ctx->clCert != NULL) {
|
||||
/* Make sure that our own cert gets sent, in the first position */
|
||||
if (!X509_up_ref(ctx->clCert))
|
||||
return 0;
|
||||
if (!sk_X509_push(msg->extraCerts, ctx->clCert)) {
|
||||
X509_free(ctx->clCert);
|
||||
return 0;
|
||||
}
|
||||
/* if we have untrusted store, try to add intermediate certs */
|
||||
if (ctx->untrusted_certs != NULL) {
|
||||
STACK_OF(X509) *chain =
|
||||
ossl_cmp_build_cert_chain(ctx->untrusted_certs, ctx->clCert);
|
||||
int res = ossl_cmp_sk_X509_add1_certs(msg->extraCerts, chain,
|
||||
1 /* no self-signed */,
|
||||
1 /* no duplicates */, 0);
|
||||
sk_X509_pop_free(chain, X509_free);
|
||||
if (res == 0)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* add any additional certificates from ctx->extraCertsOut */
|
||||
if (!ossl_cmp_sk_X509_add1_certs(msg->extraCerts, ctx->extraCertsOut, 0,
|
||||
1 /* no duplicates */, 0))
|
||||
return 0;
|
||||
|
||||
/* if none was found avoid empty ASN.1 sequence */
|
||||
if (sk_X509_num(msg->extraCerts) == 0) {
|
||||
sk_X509_free(msg->extraCerts);
|
||||
msg->extraCerts = NULL;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Create an X509_ALGOR structure for PasswordBasedMAC protection based on
|
||||
* the pbm settings in the context
|
||||
* returns pointer to X509_ALGOR on success, NULL on error
|
||||
*/
|
||||
static X509_ALGOR *create_pbmac_algor(OSSL_CMP_CTX *ctx)
|
||||
{
|
||||
X509_ALGOR *alg = NULL;
|
||||
OSSL_CRMF_PBMPARAMETER *pbm = NULL;
|
||||
unsigned char *pbm_der = NULL;
|
||||
int pbm_der_len;
|
||||
ASN1_STRING *pbm_str = NULL;
|
||||
|
||||
if (!ossl_assert(ctx != NULL))
|
||||
return NULL;
|
||||
|
||||
alg = X509_ALGOR_new();
|
||||
pbm = OSSL_CRMF_pbmp_new(ctx->pbm_slen, ctx->pbm_owf, ctx->pbm_itercnt,
|
||||
ctx->pbm_mac);
|
||||
pbm_str = ASN1_STRING_new();
|
||||
if (alg == NULL || pbm == NULL || pbm_str == NULL)
|
||||
goto err;
|
||||
|
||||
if ((pbm_der_len = i2d_OSSL_CRMF_PBMPARAMETER(pbm, &pbm_der)) < 0)
|
||||
goto err;
|
||||
|
||||
if (!ASN1_STRING_set(pbm_str, pbm_der, pbm_der_len))
|
||||
goto err;
|
||||
OPENSSL_free(pbm_der);
|
||||
|
||||
X509_ALGOR_set0(alg, OBJ_nid2obj(NID_id_PasswordBasedMAC),
|
||||
V_ASN1_SEQUENCE, pbm_str);
|
||||
OSSL_CRMF_PBMPARAMETER_free(pbm);
|
||||
return alg;
|
||||
|
||||
err:
|
||||
ASN1_STRING_free(pbm_str);
|
||||
X509_ALGOR_free(alg);
|
||||
OPENSSL_free(pbm_der);
|
||||
OSSL_CRMF_PBMPARAMETER_free(pbm);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int ossl_cmp_msg_protect(OSSL_CMP_CTX *ctx, OSSL_CMP_MSG *msg)
|
||||
{
|
||||
if (!ossl_assert(ctx != NULL && msg != NULL))
|
||||
return 0;
|
||||
|
||||
if (ctx->unprotectedSend)
|
||||
return 1;
|
||||
|
||||
/* use PasswordBasedMac according to 5.1.3.1 if secretValue is given */
|
||||
if (ctx->secretValue != NULL) {
|
||||
if ((msg->header->protectionAlg = create_pbmac_algor(ctx)) == NULL)
|
||||
goto err;
|
||||
if (ctx->referenceValue != NULL
|
||||
&& !ossl_cmp_hdr_set1_senderKID(msg->header,
|
||||
ctx->referenceValue))
|
||||
goto err;
|
||||
|
||||
/*
|
||||
* add any additional certificates from ctx->extraCertsOut
|
||||
* while not needed to validate the signing cert, the option to do
|
||||
* this might be handy for certain use cases
|
||||
*/
|
||||
if (!ossl_cmp_msg_add_extraCerts(ctx, msg))
|
||||
goto err;
|
||||
|
||||
if ((msg->protection =
|
||||
ossl_cmp_calc_protection(msg, ctx->secretValue, NULL)) == NULL)
|
||||
goto err;
|
||||
} else {
|
||||
/*
|
||||
* use MSG_SIG_ALG according to 5.1.3.3 if client Certificate and
|
||||
* private key is given
|
||||
*/
|
||||
if (ctx->clCert != NULL && ctx->pkey != NULL) {
|
||||
const ASN1_OCTET_STRING *subjKeyIDStr = NULL;
|
||||
int algNID = 0;
|
||||
ASN1_OBJECT *alg = NULL;
|
||||
|
||||
/* make sure that key and certificate match */
|
||||
if (!X509_check_private_key(ctx->clCert, ctx->pkey)) {
|
||||
CMPerr(0, CMP_R_CERT_AND_KEY_DO_NOT_MATCH);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (msg->header->protectionAlg == NULL)
|
||||
if ((msg->header->protectionAlg = X509_ALGOR_new()) == NULL)
|
||||
goto err;
|
||||
|
||||
if (!OBJ_find_sigid_by_algs(&algNID, ctx->digest,
|
||||
EVP_PKEY_id(ctx->pkey))) {
|
||||
CMPerr(0, CMP_R_UNSUPPORTED_KEY_TYPE);
|
||||
goto err;
|
||||
}
|
||||
if ((alg = OBJ_nid2obj(algNID)) == NULL)
|
||||
goto err;
|
||||
if (!X509_ALGOR_set0(msg->header->protectionAlg,
|
||||
alg, V_ASN1_UNDEF, NULL)) {
|
||||
ASN1_OBJECT_free(alg);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/*
|
||||
* set senderKID to keyIdentifier of the used certificate according
|
||||
* to section 5.1.1
|
||||
*/
|
||||
subjKeyIDStr = X509_get0_subject_key_id(ctx->clCert);
|
||||
if (subjKeyIDStr != NULL
|
||||
&& !ossl_cmp_hdr_set1_senderKID(msg->header, subjKeyIDStr))
|
||||
goto err;
|
||||
|
||||
/*
|
||||
* Add ctx->clCert followed, if possible, by its chain built
|
||||
* from ctx->untrusted_certs, and then ctx->extraCertsOut
|
||||
*/
|
||||
if (!ossl_cmp_msg_add_extraCerts(ctx, msg))
|
||||
goto err;
|
||||
|
||||
if ((msg->protection =
|
||||
ossl_cmp_calc_protection(msg, NULL, ctx->pkey)) == NULL)
|
||||
goto err;
|
||||
} else {
|
||||
CMPerr(0, CMP_R_MISSING_KEY_INPUT_FOR_CREATING_PROTECTION);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
err:
|
||||
CMPerr(0, CMP_R_ERROR_PROTECTING_MESSAGE);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,301 @@
|
||||
/*
|
||||
* Copyright 2007-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright Nokia 2007-2019
|
||||
* Copyright Siemens AG 2015-2019
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/* CMP functions for PKIStatusInfo handling and PKIMessage decomposition */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "cmp_local.h"
|
||||
|
||||
/* explicit #includes not strictly needed since implied by the above: */
|
||||
#include <time.h>
|
||||
#include <openssl/cmp.h>
|
||||
#include <openssl/crmf.h>
|
||||
#include <openssl/err.h> /* needed in case config no-deprecated */
|
||||
#include <openssl/engine.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/asn1err.h> /* for ASN1_R_TOO_SMALL and ASN1_R_TOO_LARGE */
|
||||
|
||||
/* CMP functions related to PKIStatus */
|
||||
|
||||
int ossl_cmp_pkisi_get_pkistatus(const OSSL_CMP_PKISI *si)
|
||||
{
|
||||
if (!ossl_assert(si != NULL && si->status != NULL))
|
||||
return -1;
|
||||
return ossl_cmp_asn1_get_int(si->status);
|
||||
}
|
||||
|
||||
/*
|
||||
* return the declared identifier and a short explanation for the PKIStatus
|
||||
* value as specified in RFC4210, Appendix F.
|
||||
*/
|
||||
const char *ossl_cmp_PKIStatus_to_string(int status)
|
||||
{
|
||||
switch (status) {
|
||||
case OSSL_CMP_PKISTATUS_accepted:
|
||||
return "PKIStatus: accepted";
|
||||
case OSSL_CMP_PKISTATUS_grantedWithMods:
|
||||
return "PKIStatus: granted with modifications";
|
||||
case OSSL_CMP_PKISTATUS_rejection:
|
||||
return "PKIStatus: rejection";
|
||||
case OSSL_CMP_PKISTATUS_waiting:
|
||||
return "PKIStatus: waiting";
|
||||
case OSSL_CMP_PKISTATUS_revocationWarning:
|
||||
return "PKIStatus: revocation warning - a revocation of the cert is imminent";
|
||||
case OSSL_CMP_PKISTATUS_revocationNotification:
|
||||
return "PKIStatus: revocation notification - a revocation of the cert has occurred";
|
||||
case OSSL_CMP_PKISTATUS_keyUpdateWarning:
|
||||
return "PKIStatus: key update warning - update already done for the cert";
|
||||
default:
|
||||
{
|
||||
char buf[40];
|
||||
BIO_snprintf(buf, sizeof(buf), "PKIStatus: invalid=%d", status);
|
||||
CMPerr(0, CMP_R_ERROR_PARSING_PKISTATUS);
|
||||
ossl_cmp_add_error_data(buf);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* returns a pointer to the statusString contained in a PKIStatusInfo
|
||||
* returns NULL on error
|
||||
*/
|
||||
OSSL_CMP_PKIFREETEXT *ossl_cmp_pkisi_get0_statusstring(const OSSL_CMP_PKISI *si)
|
||||
{
|
||||
if (!ossl_assert(si != NULL))
|
||||
return NULL;
|
||||
return si->statusString;
|
||||
}
|
||||
|
||||
/*
|
||||
* returns the FailureInfo bits of the given PKIStatusInfo
|
||||
* returns -1 on error
|
||||
*/
|
||||
int ossl_cmp_pkisi_get_pkifailureinfo(const OSSL_CMP_PKISI *si)
|
||||
{
|
||||
int i;
|
||||
int res = 0;
|
||||
|
||||
if (!ossl_assert(si != NULL && si->failInfo != NULL))
|
||||
return -1;
|
||||
for (i = 0; i <= OSSL_CMP_PKIFAILUREINFO_MAX; i++)
|
||||
if (ASN1_BIT_STRING_get_bit(si->failInfo, i))
|
||||
res |= 1 << i;
|
||||
return res;
|
||||
}
|
||||
|
||||
/*
|
||||
* internal function
|
||||
* convert PKIFailureInfo number to human-readable string
|
||||
*
|
||||
* returns pointer to static string
|
||||
* returns NULL on error
|
||||
*/
|
||||
static const char *CMP_PKIFAILUREINFO_to_string(int number)
|
||||
{
|
||||
switch (number) {
|
||||
case OSSL_CMP_PKIFAILUREINFO_badAlg:
|
||||
return "badAlg";
|
||||
case OSSL_CMP_PKIFAILUREINFO_badMessageCheck:
|
||||
return "badMessageCheck";
|
||||
case OSSL_CMP_PKIFAILUREINFO_badRequest:
|
||||
return "badRequest";
|
||||
case OSSL_CMP_PKIFAILUREINFO_badTime:
|
||||
return "badTime";
|
||||
case OSSL_CMP_PKIFAILUREINFO_badCertId:
|
||||
return "badCertId";
|
||||
case OSSL_CMP_PKIFAILUREINFO_badDataFormat:
|
||||
return "badDataFormat";
|
||||
case OSSL_CMP_PKIFAILUREINFO_wrongAuthority:
|
||||
return "wrongAuthority";
|
||||
case OSSL_CMP_PKIFAILUREINFO_incorrectData:
|
||||
return "incorrectData";
|
||||
case OSSL_CMP_PKIFAILUREINFO_missingTimeStamp:
|
||||
return "missingTimeStamp";
|
||||
case OSSL_CMP_PKIFAILUREINFO_badPOP:
|
||||
return "badPOP";
|
||||
case OSSL_CMP_PKIFAILUREINFO_certRevoked:
|
||||
return "certRevoked";
|
||||
case OSSL_CMP_PKIFAILUREINFO_certConfirmed:
|
||||
return "certConfirmed";
|
||||
case OSSL_CMP_PKIFAILUREINFO_wrongIntegrity:
|
||||
return "wrongIntegrity";
|
||||
case OSSL_CMP_PKIFAILUREINFO_badRecipientNonce:
|
||||
return "badRecipientNonce";
|
||||
case OSSL_CMP_PKIFAILUREINFO_timeNotAvailable:
|
||||
return "timeNotAvailable";
|
||||
case OSSL_CMP_PKIFAILUREINFO_unacceptedPolicy:
|
||||
return "unacceptedPolicy";
|
||||
case OSSL_CMP_PKIFAILUREINFO_unacceptedExtension:
|
||||
return "unacceptedExtension";
|
||||
case OSSL_CMP_PKIFAILUREINFO_addInfoNotAvailable:
|
||||
return "addInfoNotAvailable";
|
||||
case OSSL_CMP_PKIFAILUREINFO_badSenderNonce:
|
||||
return "badSenderNonce";
|
||||
case OSSL_CMP_PKIFAILUREINFO_badCertTemplate:
|
||||
return "badCertTemplate";
|
||||
case OSSL_CMP_PKIFAILUREINFO_signerNotTrusted:
|
||||
return "signerNotTrusted";
|
||||
case OSSL_CMP_PKIFAILUREINFO_transactionIdInUse:
|
||||
return "transactionIdInUse";
|
||||
case OSSL_CMP_PKIFAILUREINFO_unsupportedVersion:
|
||||
return "unsupportedVersion";
|
||||
case OSSL_CMP_PKIFAILUREINFO_notAuthorized:
|
||||
return "notAuthorized";
|
||||
case OSSL_CMP_PKIFAILUREINFO_systemUnavail:
|
||||
return "systemUnavail";
|
||||
case OSSL_CMP_PKIFAILUREINFO_systemFailure:
|
||||
return "systemFailure";
|
||||
case OSSL_CMP_PKIFAILUREINFO_duplicateCertReq:
|
||||
return "duplicateCertReq";
|
||||
default:
|
||||
return NULL; /* illegal failure number */
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* checks PKIFailureInfo bits in a given PKIStatusInfo
|
||||
* returns 1 if a given bit is set, 0 if not, -1 on error
|
||||
*/
|
||||
int ossl_cmp_pkisi_pkifailureinfo_check(const OSSL_CMP_PKISI *si, int bit_index)
|
||||
{
|
||||
if (!ossl_assert(si != NULL && si->failInfo != NULL))
|
||||
return -1;
|
||||
if (bit_index < 0 || bit_index > OSSL_CMP_PKIFAILUREINFO_MAX) {
|
||||
CMPerr(0, CMP_R_INVALID_ARGS);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ASN1_BIT_STRING_get_bit(si->failInfo, bit_index);
|
||||
}
|
||||
|
||||
/*
|
||||
* place human-readable error string created from PKIStatusInfo in given buffer
|
||||
* returns pointer to the same buffer containing the string, or NULL on error
|
||||
*/
|
||||
char *OSSL_CMP_CTX_snprint_PKIStatus(OSSL_CMP_CTX *ctx, char *buf,
|
||||
size_t bufsize)
|
||||
{
|
||||
int status, failure, fail_info;
|
||||
const char *status_string, *failure_string;
|
||||
OSSL_CMP_PKIFREETEXT *status_strings;
|
||||
ASN1_UTF8STRING *text;
|
||||
int i;
|
||||
int printed_chars;
|
||||
int failinfo_found = 0;
|
||||
int n_status_strings;
|
||||
char* write_ptr = buf;
|
||||
|
||||
#define ADVANCE_BUFFER \
|
||||
if (printed_chars < 0 || (size_t)printed_chars >= bufsize) \
|
||||
return NULL; \
|
||||
write_ptr += printed_chars; \
|
||||
bufsize -= printed_chars;
|
||||
|
||||
if (ctx == NULL
|
||||
|| buf == NULL
|
||||
|| (status = OSSL_CMP_CTX_get_status(ctx)) < 0
|
||||
|| (status_string = ossl_cmp_PKIStatus_to_string(status)) == NULL)
|
||||
return NULL;
|
||||
printed_chars = BIO_snprintf(write_ptr, bufsize, "%s", status_string);
|
||||
ADVANCE_BUFFER;
|
||||
|
||||
/* failInfo is optional and may be empty */
|
||||
if ((fail_info = OSSL_CMP_CTX_get_failInfoCode(ctx)) > 0) {
|
||||
printed_chars = BIO_snprintf(write_ptr, bufsize, "; PKIFailureInfo: ");
|
||||
ADVANCE_BUFFER;
|
||||
for (failure = 0; failure <= OSSL_CMP_PKIFAILUREINFO_MAX; failure++) {
|
||||
if ((fail_info & (1 << failure)) != 0) {
|
||||
failure_string = CMP_PKIFAILUREINFO_to_string(failure);
|
||||
if (failure_string != NULL) {
|
||||
printed_chars = BIO_snprintf(write_ptr, bufsize, "%s%s",
|
||||
failure > 0 ? ", " : "",
|
||||
failure_string);
|
||||
ADVANCE_BUFFER;
|
||||
failinfo_found = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!failinfo_found && status != OSSL_CMP_PKISTATUS_accepted
|
||||
&& status != OSSL_CMP_PKISTATUS_grantedWithMods) {
|
||||
printed_chars = BIO_snprintf(write_ptr, bufsize, "; <no failure info>");
|
||||
ADVANCE_BUFFER;
|
||||
}
|
||||
|
||||
/* statusString sequence is optional and may be empty */
|
||||
status_strings = OSSL_CMP_CTX_get0_statusString(ctx);
|
||||
n_status_strings = sk_ASN1_UTF8STRING_num(status_strings);
|
||||
if (n_status_strings > 0) {
|
||||
printed_chars = BIO_snprintf(write_ptr, bufsize, "; StatusString%s: ",
|
||||
n_status_strings > 1 ? "s" : "");
|
||||
ADVANCE_BUFFER;
|
||||
for (i = 0; i < n_status_strings; i++) {
|
||||
text = sk_ASN1_UTF8STRING_value(status_strings, i);
|
||||
printed_chars = BIO_snprintf(write_ptr, bufsize, "\"%s\"%s",
|
||||
ASN1_STRING_get0_data(text),
|
||||
i < n_status_strings - 1 ? ", " : "");
|
||||
ADVANCE_BUFFER;
|
||||
}
|
||||
}
|
||||
#undef ADVANCE_BUFFER
|
||||
return buf;
|
||||
}
|
||||
|
||||
/*
|
||||
* Creates a new PKIStatusInfo structure and fills it in
|
||||
* returns a pointer to the structure on success, NULL on error
|
||||
* note: strongly overlaps with TS_RESP_CTX_set_status_info()
|
||||
* and TS_RESP_CTX_add_failure_info() in ../ts/ts_rsp_sign.c
|
||||
*/
|
||||
OSSL_CMP_PKISI *ossl_cmp_statusinfo_new(int status, int fail_info,
|
||||
const char *text)
|
||||
{
|
||||
OSSL_CMP_PKISI *si = OSSL_CMP_PKISI_new();
|
||||
ASN1_UTF8STRING *utf8_text = NULL;
|
||||
int failure;
|
||||
|
||||
if (si == NULL)
|
||||
goto err;
|
||||
if (!ASN1_INTEGER_set(si->status, status))
|
||||
goto err;
|
||||
|
||||
if (text != NULL) {
|
||||
if ((utf8_text = ASN1_UTF8STRING_new()) == NULL
|
||||
|| !ASN1_STRING_set(utf8_text, text, -1))
|
||||
goto err;
|
||||
if ((si->statusString = sk_ASN1_UTF8STRING_new_null()) == NULL)
|
||||
goto err;
|
||||
if (!sk_ASN1_UTF8STRING_push(si->statusString, utf8_text))
|
||||
goto err;
|
||||
/* Ownership is lost. */
|
||||
utf8_text = NULL;
|
||||
}
|
||||
|
||||
for (failure = 0; failure <= OSSL_CMP_PKIFAILUREINFO_MAX; failure++) {
|
||||
if ((fail_info & (1 << failure)) != 0) {
|
||||
if (si->failInfo == NULL
|
||||
&& (si->failInfo = ASN1_BIT_STRING_new()) == NULL)
|
||||
goto err;
|
||||
if (!ASN1_BIT_STRING_set_bit(si->failInfo, failure, 1))
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
return si;
|
||||
|
||||
err:
|
||||
OSSL_CMP_PKISI_free(si);
|
||||
ASN1_UTF8STRING_free(utf8_text);
|
||||
return NULL;
|
||||
}
|
||||
@@ -408,21 +408,23 @@ STACK_OF(X509) *ossl_cmp_build_cert_chain(STACK_OF(X509) *certs, X509 *cert)
|
||||
int ossl_cmp_asn1_octet_string_set1(ASN1_OCTET_STRING **tgt,
|
||||
const ASN1_OCTET_STRING *src)
|
||||
{
|
||||
ASN1_OCTET_STRING *new;
|
||||
if (tgt == NULL) {
|
||||
CMPerr(0, CMP_R_NULL_ARGUMENT);
|
||||
return 0;
|
||||
}
|
||||
if (*tgt == src) /* self-assignment */
|
||||
return 1;
|
||||
ASN1_OCTET_STRING_free(*tgt);
|
||||
|
||||
if (src != NULL) {
|
||||
if ((*tgt = ASN1_OCTET_STRING_dup(src)) == NULL)
|
||||
if ((new = ASN1_OCTET_STRING_dup(src)) == NULL)
|
||||
return 0;
|
||||
} else {
|
||||
*tgt = NULL;
|
||||
new = NULL;
|
||||
}
|
||||
|
||||
ASN1_OCTET_STRING_free(*tgt);
|
||||
*tgt = new;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
+59
-22
@@ -13,7 +13,7 @@
|
||||
#include <openssl/x509v3.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/cms.h>
|
||||
#include <openssl/aes.h>
|
||||
#include <openssl/evp.h>
|
||||
#include "cms_local.h"
|
||||
#include "crypto/asn1.h"
|
||||
#include "crypto/evp.h"
|
||||
@@ -625,6 +625,23 @@ int CMS_RecipientInfo_set0_key(CMS_RecipientInfo *ri,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const EVP_CIPHER *cms_get_key_wrap_cipher(size_t keylen)
|
||||
{
|
||||
switch(keylen) {
|
||||
case 16:
|
||||
return EVP_aes_128_wrap();
|
||||
|
||||
case 24:
|
||||
return EVP_aes_192_wrap();
|
||||
|
||||
case 32:
|
||||
return EVP_aes_256_wrap();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* Encrypt content key in KEK recipient info */
|
||||
|
||||
static int cms_RecipientInfo_kekri_encrypt(const CMS_ContentInfo *cms,
|
||||
@@ -632,36 +649,50 @@ static int cms_RecipientInfo_kekri_encrypt(const CMS_ContentInfo *cms,
|
||||
{
|
||||
CMS_EncryptedContentInfo *ec;
|
||||
CMS_KEKRecipientInfo *kekri;
|
||||
AES_KEY actx;
|
||||
unsigned char *wkey = NULL;
|
||||
int wkeylen;
|
||||
int r = 0;
|
||||
const EVP_CIPHER *cipher = NULL;
|
||||
int outlen = 0;
|
||||
EVP_CIPHER_CTX *ctx = NULL;
|
||||
|
||||
ec = cms->d.envelopedData->encryptedContentInfo;
|
||||
|
||||
kekri = ri->d.kekri;
|
||||
|
||||
if (!kekri->key) {
|
||||
if (kekri->key == NULL) {
|
||||
CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_ENCRYPT, CMS_R_NO_KEY);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (AES_set_encrypt_key(kekri->key, kekri->keylen << 3, &actx)) {
|
||||
CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_ENCRYPT,
|
||||
CMS_R_ERROR_SETTING_KEY);
|
||||
cipher = cms_get_key_wrap_cipher(kekri->keylen);
|
||||
if (cipher == NULL) {
|
||||
CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_ENCRYPT, CMS_R_INVALID_KEY_LENGTH);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* 8 byte prefix for AES wrap ciphers */
|
||||
wkey = OPENSSL_malloc(ec->keylen + 8);
|
||||
|
||||
if (wkey == NULL) {
|
||||
CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_ENCRYPT, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
wkeylen = AES_wrap_key(&actx, NULL, wkey, ec->key, ec->keylen);
|
||||
ctx = EVP_CIPHER_CTX_new();
|
||||
if (ctx == NULL) {
|
||||
CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_ENCRYPT, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (wkeylen <= 0) {
|
||||
EVP_CIPHER_CTX_set_flags(ctx, EVP_CIPHER_CTX_FLAG_WRAP_ALLOW);
|
||||
if (!EVP_EncryptInit_ex(ctx, cipher, NULL, kekri->key, NULL)
|
||||
|| !EVP_EncryptUpdate(ctx, wkey, &wkeylen, ec->key, ec->keylen)
|
||||
|| !EVP_EncryptFinal_ex(ctx, wkey + wkeylen, &outlen)) {
|
||||
CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_ENCRYPT, CMS_R_WRAP_ERROR);
|
||||
goto err;
|
||||
}
|
||||
wkeylen += outlen;
|
||||
if (!ossl_assert((size_t)wkeylen == ec->keylen + 8)) {
|
||||
CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_ENCRYPT, CMS_R_WRAP_ERROR);
|
||||
goto err;
|
||||
}
|
||||
@@ -671,10 +702,9 @@ static int cms_RecipientInfo_kekri_encrypt(const CMS_ContentInfo *cms,
|
||||
r = 1;
|
||||
|
||||
err:
|
||||
|
||||
if (!r)
|
||||
OPENSSL_free(wkey);
|
||||
OPENSSL_cleanse(&actx, sizeof(actx));
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
|
||||
return r;
|
||||
|
||||
@@ -687,10 +717,12 @@ static int cms_RecipientInfo_kekri_decrypt(CMS_ContentInfo *cms,
|
||||
{
|
||||
CMS_EncryptedContentInfo *ec;
|
||||
CMS_KEKRecipientInfo *kekri;
|
||||
AES_KEY actx;
|
||||
unsigned char *ukey = NULL;
|
||||
int ukeylen;
|
||||
int r = 0, wrap_nid;
|
||||
const EVP_CIPHER *cipher = NULL;
|
||||
int outlen = 0;
|
||||
EVP_CIPHER_CTX *ctx = NULL;
|
||||
|
||||
ec = cms->d.envelopedData->encryptedContentInfo;
|
||||
|
||||
@@ -716,27 +748,33 @@ static int cms_RecipientInfo_kekri_decrypt(CMS_ContentInfo *cms,
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (AES_set_decrypt_key(kekri->key, kekri->keylen << 3, &actx)) {
|
||||
CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_DECRYPT,
|
||||
CMS_R_ERROR_SETTING_KEY);
|
||||
cipher = cms_get_key_wrap_cipher(kekri->keylen);
|
||||
if (cipher == NULL) {
|
||||
CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_DECRYPT, CMS_R_INVALID_KEY_LENGTH);
|
||||
goto err;
|
||||
}
|
||||
|
||||
ukey = OPENSSL_malloc(kekri->encryptedKey->length - 8);
|
||||
|
||||
if (ukey == NULL) {
|
||||
CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_DECRYPT, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
ukeylen = AES_unwrap_key(&actx, NULL, ukey,
|
||||
kekri->encryptedKey->data,
|
||||
kekri->encryptedKey->length);
|
||||
ctx = EVP_CIPHER_CTX_new();
|
||||
if (ctx == NULL) {
|
||||
CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_DECRYPT, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (ukeylen <= 0) {
|
||||
if (!EVP_DecryptInit_ex(ctx, cipher, NULL, kekri->key, NULL)
|
||||
|| !EVP_DecryptUpdate(ctx, ukey, &ukeylen,
|
||||
kekri->encryptedKey->data,
|
||||
kekri->encryptedKey->length)
|
||||
|| !EVP_DecryptFinal_ex(ctx, ukey + ukeylen, &outlen)) {
|
||||
CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_DECRYPT, CMS_R_UNWRAP_ERROR);
|
||||
goto err;
|
||||
}
|
||||
ukeylen += outlen;
|
||||
|
||||
ec->key = ukey;
|
||||
ec->keylen = ukeylen;
|
||||
@@ -744,10 +782,9 @@ static int cms_RecipientInfo_kekri_decrypt(CMS_ContentInfo *cms,
|
||||
r = 1;
|
||||
|
||||
err:
|
||||
|
||||
if (!r)
|
||||
OPENSSL_free(ukey);
|
||||
OPENSSL_cleanse(&actx, sizeof(actx));
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
|
||||
return r;
|
||||
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ int i2d_CMS_bio(BIO *bp, CMS_ContentInfo *cms)
|
||||
return ASN1_item_i2d_bio(ASN1_ITEM_rptr(CMS_ContentInfo), bp, cms);
|
||||
}
|
||||
|
||||
IMPLEMENT_PEM_rw_const(CMS, CMS_ContentInfo, PEM_STRING_CMS, CMS_ContentInfo)
|
||||
IMPLEMENT_PEM_rw(CMS, CMS_ContentInfo, PEM_STRING_CMS, CMS_ContentInfo)
|
||||
|
||||
BIO *BIO_new_CMS(BIO *out, CMS_ContentInfo *cms)
|
||||
{
|
||||
|
||||
+67
-19
@@ -54,7 +54,7 @@ static BIO *get_next_file(const char *path, OPENSSL_DIR_CTX **dirctx);
|
||||
|
||||
static CONF *def_create(CONF_METHOD *meth);
|
||||
static int def_init_default(CONF *conf);
|
||||
#if !OPENSSL_API_3
|
||||
#ifndef OPENSSL_NO_DEPRECATED_3_0
|
||||
static int def_init_WIN32(CONF *conf);
|
||||
#endif
|
||||
static int def_destroy(CONF *conf);
|
||||
@@ -83,7 +83,7 @@ CONF_METHOD *NCONF_default(void)
|
||||
return &default_method;
|
||||
}
|
||||
|
||||
#if ! OPENSSL_API_3
|
||||
#ifndef OPENSSL_NO_DEPRECATED_3_0
|
||||
static CONF_METHOD WIN32_method = {
|
||||
"WIN32",
|
||||
def_create,
|
||||
@@ -121,22 +121,22 @@ static int def_init_default(CONF *conf)
|
||||
if (conf == NULL)
|
||||
return 0;
|
||||
|
||||
memset(conf, 0, sizeof(*conf));
|
||||
conf->meth = &default_method;
|
||||
conf->meth_data = (void *)CONF_type_default;
|
||||
conf->data = NULL;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
#if ! OPENSSL_API_3
|
||||
#ifndef OPENSSL_NO_DEPRECATED_3_0
|
||||
static int def_init_WIN32(CONF *conf)
|
||||
{
|
||||
if (conf == NULL)
|
||||
return 0;
|
||||
|
||||
memset(conf, 0, sizeof(*conf));
|
||||
conf->meth = &WIN32_method;
|
||||
conf->meth_data = (void *)CONF_type_win32;
|
||||
conf->data = NULL;
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -354,7 +354,49 @@ static int def_load_bio(CONF *conf, BIO *in, long *line)
|
||||
psection = section;
|
||||
}
|
||||
p = eat_ws(conf, end);
|
||||
if (strncmp(pname, ".include", 8) == 0
|
||||
if (strncmp(pname, ".pragma", 7) == 0
|
||||
&& (p != pname + 7 || *p == '=')) {
|
||||
char *pval;
|
||||
|
||||
if (*p == '=') {
|
||||
p++;
|
||||
p = eat_ws(conf, p);
|
||||
}
|
||||
trim_ws(conf, p);
|
||||
|
||||
/* Pragma values take the form keyword:value */
|
||||
pval = strchr(p, ':');
|
||||
if (pval == NULL || pval == p || pval[1] == '\0') {
|
||||
CONFerr(CONF_F_DEF_LOAD_BIO, CONF_R_INVALID_PRAGMA);
|
||||
goto err;
|
||||
}
|
||||
|
||||
*pval++ = '\0';
|
||||
trim_ws(conf, p);
|
||||
pval = eat_ws(conf, pval);
|
||||
|
||||
/*
|
||||
* Known pragmas:
|
||||
*
|
||||
* dollarid takes "on", "true or "off", "false"
|
||||
*/
|
||||
if (strcmp(p, "dollarid") == 0) {
|
||||
if (strcmp(pval, "on") == 0
|
||||
|| strcmp(pval, "true") == 0) {
|
||||
conf->flag_dollarid = 1;
|
||||
} else if (strcmp(pval, "off") == 0
|
||||
|| strcmp(pval, "false") == 0) {
|
||||
conf->flag_dollarid = 0;
|
||||
} else {
|
||||
CONFerr(CONF_F_DEF_LOAD_BIO, CONF_R_INVALID_PRAGMA);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* We *ignore* any unknown pragma.
|
||||
*/
|
||||
continue;
|
||||
} else if (strncmp(pname, ".include", 8) == 0
|
||||
&& (p != pname + 8 || *p == '=')) {
|
||||
char *include = NULL;
|
||||
BIO *next;
|
||||
@@ -414,6 +456,7 @@ static int def_load_bio(CONF *conf, BIO *in, long *line)
|
||||
continue;
|
||||
} else if (*p != '=') {
|
||||
CONFerr(CONF_F_DEF_LOAD_BIO, CONF_R_MISSING_EQUAL_SIGN);
|
||||
ERR_add_error_data(2, "HERE-->", p);
|
||||
goto err;
|
||||
}
|
||||
*end = '\0';
|
||||
@@ -590,7 +633,10 @@ static int str_copy(CONF *conf, char *section, char **pto, char *from)
|
||||
buf->data[to++] = v;
|
||||
} else if (IS_EOF(conf, *from))
|
||||
break;
|
||||
else if (*from == '$') {
|
||||
else if (*from == '$'
|
||||
&& (!conf->flag_dollarid
|
||||
|| from[1] == '{'
|
||||
|| from[1] == '(')) {
|
||||
size_t newsize;
|
||||
|
||||
/* try to expand it */
|
||||
@@ -607,7 +653,8 @@ static int str_copy(CONF *conf, char *section, char **pto, char *from)
|
||||
s++;
|
||||
cp = section;
|
||||
e = np = s;
|
||||
while (IS_ALNUM(conf, *e))
|
||||
while (IS_ALNUM(conf, *e)
|
||||
|| (conf->flag_dollarid && IS_DOLLAR(conf, *e)))
|
||||
e++;
|
||||
if ((e[0] == ':') && (e[1] == ':')) {
|
||||
cp = np;
|
||||
@@ -616,7 +663,8 @@ static int str_copy(CONF *conf, char *section, char **pto, char *from)
|
||||
*rrp = '\0';
|
||||
e += 2;
|
||||
np = e;
|
||||
while (IS_ALNUM(conf, *e))
|
||||
while (IS_ALNUM(conf, *e)
|
||||
|| (conf->flag_dollarid && IS_DOLLAR(conf, *e)))
|
||||
e++;
|
||||
}
|
||||
r = *e;
|
||||
@@ -729,7 +777,9 @@ static BIO *process_include(char *include, OPENSSL_DIR_CTX **dirctx,
|
||||
static BIO *get_next_file(const char *path, OPENSSL_DIR_CTX **dirctx)
|
||||
{
|
||||
const char *filename;
|
||||
size_t pathlen;
|
||||
|
||||
pathlen = strlen(path);
|
||||
while ((filename = OPENSSL_DIR_read(dirctx, path)) != NULL) {
|
||||
size_t namelen;
|
||||
|
||||
@@ -742,7 +792,7 @@ static BIO *get_next_file(const char *path, OPENSSL_DIR_CTX **dirctx)
|
||||
char *newpath;
|
||||
BIO *bio;
|
||||
|
||||
newlen = strlen(path) + namelen + 2;
|
||||
newlen = pathlen + namelen + 2;
|
||||
newpath = OPENSSL_zalloc(newlen);
|
||||
if (newpath == NULL) {
|
||||
CONFerr(CONF_F_GET_NEXT_FILE, ERR_R_MALLOC_FAILURE);
|
||||
@@ -753,14 +803,11 @@ static BIO *get_next_file(const char *path, OPENSSL_DIR_CTX **dirctx)
|
||||
* If the given path isn't clear VMS syntax,
|
||||
* we treat it as on Unix.
|
||||
*/
|
||||
{
|
||||
size_t pathlen = strlen(path);
|
||||
|
||||
if (path[pathlen - 1] == ']' || path[pathlen - 1] == '>'
|
||||
|| path[pathlen - 1] == ':') {
|
||||
/* Clear VMS directory syntax, just copy as is */
|
||||
OPENSSL_strlcpy(newpath, path, newlen);
|
||||
}
|
||||
if (path[pathlen - 1] == ']'
|
||||
|| path[pathlen - 1] == '>'
|
||||
|| path[pathlen - 1] == ':') {
|
||||
/* Clear VMS directory syntax, just copy as is */
|
||||
OPENSSL_strlcpy(newpath, path, newlen);
|
||||
}
|
||||
#endif
|
||||
if (newpath[0] == '\0') {
|
||||
@@ -833,7 +880,8 @@ static char *eat_alpha_numeric(CONF *conf, char *p)
|
||||
p = scan_esc(conf, p);
|
||||
continue;
|
||||
}
|
||||
if (!IS_ALNUM_PUNCT(conf, *p))
|
||||
if (!(IS_ALNUM_PUNCT(conf, *p)
|
||||
|| (conf->flag_dollarid && IS_DOLLAR(conf, *p))))
|
||||
return p;
|
||||
p++;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* WARNING: do not edit!
|
||||
* Generated by crypto/conf/keysets.pl
|
||||
*
|
||||
* Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
@@ -20,6 +20,7 @@
|
||||
#define CONF_DQUOTE 1024
|
||||
#define CONF_COMMENT 128
|
||||
#define CONF_FCOMMENT 2048
|
||||
#define CONF_DOLLAR 4096
|
||||
#define CONF_EOF 8
|
||||
#define CONF_ALPHA (CONF_UPPER|CONF_LOWER)
|
||||
#define CONF_ALNUM (CONF_ALPHA|CONF_NUMBER|CONF_UNDER)
|
||||
@@ -36,13 +37,14 @@
|
||||
#define IS_ALNUM_PUNCT(conf,c) is_keytype(conf, c, CONF_ALNUM_PUNCT)
|
||||
#define IS_QUOTE(conf,c) is_keytype(conf, c, CONF_QUOTE)
|
||||
#define IS_DQUOTE(conf,c) is_keytype(conf, c, CONF_DQUOTE)
|
||||
#define IS_DOLLAR(conf,c) is_keytype(conf, c, CONF_DOLLAR)
|
||||
|
||||
static const unsigned short CONF_type_default[128] = {
|
||||
0x0008, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
0x0000, 0x0010, 0x0010, 0x0000, 0x0000, 0x0010, 0x0000, 0x0000,
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
0x0010, 0x0200, 0x0040, 0x0080, 0x0000, 0x0200, 0x0200, 0x0040,
|
||||
0x0010, 0x0200, 0x0040, 0x0080, 0x1000, 0x0200, 0x0200, 0x0040,
|
||||
0x0000, 0x0000, 0x0200, 0x0200, 0x0200, 0x0200, 0x0200, 0x0200,
|
||||
0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001,
|
||||
0x0001, 0x0001, 0x0000, 0x0200, 0x0000, 0x0000, 0x0000, 0x0200,
|
||||
@@ -56,13 +58,13 @@ static const unsigned short CONF_type_default[128] = {
|
||||
0x0004, 0x0004, 0x0004, 0x0000, 0x0200, 0x0000, 0x0200, 0x0000,
|
||||
};
|
||||
|
||||
#if ! OPENSSL_API_3
|
||||
#ifndef OPENSSL_NO_DEPRECATED_3_0
|
||||
static const unsigned short CONF_type_win32[128] = {
|
||||
0x0008, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
0x0000, 0x0010, 0x0010, 0x0000, 0x0000, 0x0010, 0x0000, 0x0000,
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
0x0010, 0x0200, 0x0400, 0x0000, 0x0000, 0x0200, 0x0200, 0x0000,
|
||||
0x0010, 0x0200, 0x0400, 0x0000, 0x1000, 0x0200, 0x0200, 0x0000,
|
||||
0x0000, 0x0000, 0x0200, 0x0200, 0x0200, 0x0200, 0x0200, 0x0200,
|
||||
0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001,
|
||||
0x0001, 0x0001, 0x0000, 0x0A00, 0x0000, 0x0000, 0x0000, 0x0200,
|
||||
|
||||
@@ -15,8 +15,11 @@
|
||||
|
||||
static const ERR_STRING_DATA CONF_str_reasons[] = {
|
||||
{ERR_PACK(ERR_LIB_CONF, 0, CONF_R_ERROR_LOADING_DSO), "error loading dso"},
|
||||
{ERR_PACK(ERR_LIB_CONF, 0, CONF_R_INVALID_PRAGMA), "invalid pragma"},
|
||||
{ERR_PACK(ERR_LIB_CONF, 0, CONF_R_LIST_CANNOT_BE_NULL),
|
||||
"list cannot be null"},
|
||||
{ERR_PACK(ERR_LIB_CONF, 0, CONF_R_MANDATORY_BRACES_IN_VARIABLE_EXPANSION),
|
||||
"mandatory braces in variable expansion"},
|
||||
{ERR_PACK(ERR_LIB_CONF, 0, CONF_R_MISSING_CLOSE_SQUARE_BRACKET),
|
||||
"missing close square bracket"},
|
||||
{ERR_PACK(ERR_LIB_CONF, 0, CONF_R_MISSING_EQUAL_SIGN),
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
static int openssl_configured = 0;
|
||||
|
||||
#if !OPENSSL_API_1_1_0
|
||||
#ifndef OPENSSL_NO_DEPRECATED_1_1_0
|
||||
void OPENSSL_config(const char *appname)
|
||||
{
|
||||
OPENSSL_INIT_SETTINGS settings;
|
||||
|
||||
@@ -20,6 +20,7 @@ my $QUOTE = 0x0040;
|
||||
my $DQUOTE = 0x0400;
|
||||
my $COMMENT = 0x0080;
|
||||
my $FCOMMENT = 0x0800;
|
||||
my $DOLLAR = 0x1000;
|
||||
my $EOF = 0x0008;
|
||||
my @V_def;
|
||||
my @V_w32;
|
||||
@@ -38,6 +39,7 @@ foreach (0 .. 127) {
|
||||
$v |= $ESC if $c =~ /\\/;
|
||||
$v |= $QUOTE if $c =~ /['`"]/; # for emacs: "`'
|
||||
$v |= $COMMENT if $c =~ /\#/;
|
||||
$v |= $DOLLAR if $c eq '$';
|
||||
$v |= $EOF if $c =~ /\0/;
|
||||
push(@V_def, $v);
|
||||
|
||||
@@ -50,13 +52,13 @@ foreach (0 .. 127) {
|
||||
$v |= $WS if $c =~ /[ \t\r\n]/;
|
||||
$v |= $DQUOTE if $c =~ /["]/; # for emacs: "
|
||||
$v |= $FCOMMENT if $c =~ /;/;
|
||||
$v |= $DOLLAR if $c eq '$';
|
||||
$v |= $EOF if $c =~ /\0/;
|
||||
push(@V_w32, $v);
|
||||
}
|
||||
|
||||
# Output year depends on the year of the script.
|
||||
my $YEAR = [localtime([stat($0)]->[9])]->[5] + 1900;
|
||||
|
||||
# The year the output file is generated.
|
||||
my $YEAR = [localtime()]->[5] + 1900;
|
||||
print <<"EOF";
|
||||
/*
|
||||
* WARNING: do not edit!
|
||||
@@ -80,6 +82,7 @@ print <<"EOF";
|
||||
#define CONF_DQUOTE $DQUOTE
|
||||
#define CONF_COMMENT $COMMENT
|
||||
#define CONF_FCOMMENT $FCOMMENT
|
||||
#define CONF_DOLLAR $DOLLAR
|
||||
#define CONF_EOF $EOF
|
||||
#define CONF_ALPHA (CONF_UPPER|CONF_LOWER)
|
||||
#define CONF_ALNUM (CONF_ALPHA|CONF_NUMBER|CONF_UNDER)
|
||||
@@ -96,6 +99,7 @@ print <<"EOF";
|
||||
#define IS_ALNUM_PUNCT(conf,c) is_keytype(conf, c, CONF_ALNUM_PUNCT)
|
||||
#define IS_QUOTE(conf,c) is_keytype(conf, c, CONF_QUOTE)
|
||||
#define IS_DQUOTE(conf,c) is_keytype(conf, c, CONF_DQUOTE)
|
||||
#define IS_DOLLAR(conf,c) is_keytype(conf, c, CONF_DOLLAR)
|
||||
|
||||
EOF
|
||||
|
||||
@@ -108,7 +112,7 @@ for ($i = 0; $i < 128; $i++) {
|
||||
}
|
||||
print "\n};\n\n";
|
||||
|
||||
print "#if ! OPENSSL_API_3\n";
|
||||
print "#ifndef OPENSSL_NO_DEPRECATED_3_0\n";
|
||||
print "static const unsigned short CONF_type_win32[128] = {";
|
||||
for ($i = 0; $i < 128; $i++) {
|
||||
print "\n " if ($i % 8) == 0;
|
||||
|
||||
+2
-3
@@ -31,9 +31,8 @@ static void ossl_method_construct_this(OSSL_PROVIDER *provider,
|
||||
struct construct_data_st *data = cbdata;
|
||||
void *method = NULL;
|
||||
|
||||
if ((method = data->mcm->construct(algo->algorithm_names,
|
||||
algo->implementation, provider,
|
||||
data->mcm_data)) == NULL)
|
||||
if ((method = data->mcm->construct(algo, provider, data->mcm_data))
|
||||
== NULL)
|
||||
return;
|
||||
|
||||
/*
|
||||
|
||||
+183
-34
@@ -72,9 +72,11 @@ static void stored_namemap_free(void *vnamemap)
|
||||
{
|
||||
OSSL_NAMEMAP *namemap = vnamemap;
|
||||
|
||||
/* Pretend it isn't stored, or ossl_namemap_free() will do nothing */
|
||||
namemap->stored = 0;
|
||||
ossl_namemap_free(namemap);
|
||||
if (namemap != NULL) {
|
||||
/* Pretend it isn't stored, or ossl_namemap_free() will do nothing */
|
||||
namemap->stored = 0;
|
||||
ossl_namemap_free(namemap);
|
||||
}
|
||||
}
|
||||
|
||||
static const OPENSSL_CTX_METHOD stored_namemap_method = {
|
||||
@@ -87,36 +89,16 @@ static const OPENSSL_CTX_METHOD stored_namemap_method = {
|
||||
* =============
|
||||
*/
|
||||
|
||||
OSSL_NAMEMAP *ossl_namemap_stored(OPENSSL_CTX *libctx)
|
||||
int ossl_namemap_empty(OSSL_NAMEMAP *namemap)
|
||||
{
|
||||
return openssl_ctx_get_data(libctx, OPENSSL_CTX_NAMEMAP_INDEX,
|
||||
&stored_namemap_method);
|
||||
}
|
||||
int rv = 0;
|
||||
|
||||
OSSL_NAMEMAP *ossl_namemap_new(void)
|
||||
{
|
||||
OSSL_NAMEMAP *namemap;
|
||||
CRYPTO_THREAD_read_lock(namemap->lock);
|
||||
if (namemap->max_number == 0)
|
||||
rv = 1;
|
||||
CRYPTO_THREAD_unlock(namemap->lock);
|
||||
|
||||
if ((namemap = OPENSSL_zalloc(sizeof(*namemap))) != NULL
|
||||
&& (namemap->lock = CRYPTO_THREAD_lock_new()) != NULL
|
||||
&& (namemap->namenum =
|
||||
lh_NAMENUM_ENTRY_new(namenum_hash, namenum_cmp)) != NULL)
|
||||
return namemap;
|
||||
|
||||
ossl_namemap_free(namemap);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ossl_namemap_free(OSSL_NAMEMAP *namemap)
|
||||
{
|
||||
if (namemap == NULL || namemap->stored)
|
||||
return;
|
||||
|
||||
lh_NAMENUM_ENTRY_doall(namemap->namenum, namenum_free);
|
||||
lh_NAMENUM_ENTRY_free(namemap->namenum);
|
||||
|
||||
CRYPTO_THREAD_lock_free(namemap->lock);
|
||||
OPENSSL_free(namemap);
|
||||
return rv;
|
||||
}
|
||||
|
||||
typedef struct doall_names_data_st {
|
||||
@@ -210,8 +192,8 @@ const char *ossl_namemap_num2name(const OSSL_NAMEMAP *namemap, int number,
|
||||
return data.name;
|
||||
}
|
||||
|
||||
int ossl_namemap_add_n(OSSL_NAMEMAP *namemap, int number,
|
||||
const char *name, size_t name_len)
|
||||
int ossl_namemap_add_name_n(OSSL_NAMEMAP *namemap, int number,
|
||||
const char *name, size_t name_len)
|
||||
{
|
||||
NAMENUM_ENTRY *namenum = NULL;
|
||||
int tmp_number;
|
||||
@@ -251,10 +233,177 @@ int ossl_namemap_add_n(OSSL_NAMEMAP *namemap, int number,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ossl_namemap_add(OSSL_NAMEMAP *namemap, int number, const char *name)
|
||||
int ossl_namemap_add_name(OSSL_NAMEMAP *namemap, int number, const char *name)
|
||||
{
|
||||
if (name == NULL)
|
||||
return 0;
|
||||
|
||||
return ossl_namemap_add_n(namemap, number, name, strlen(name));
|
||||
return ossl_namemap_add_name_n(namemap, number, name, strlen(name));
|
||||
}
|
||||
|
||||
int ossl_namemap_add_names(OSSL_NAMEMAP *namemap, int number,
|
||||
const char *names, const char separator)
|
||||
{
|
||||
const char *p, *q;
|
||||
size_t l;
|
||||
|
||||
/* Check that we have a namemap */
|
||||
if (!ossl_assert(namemap != NULL)) {
|
||||
ERR_raise(ERR_LIB_CRYPTO, ERR_R_PASSED_NULL_PARAMETER);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check that no name is an empty string, and that all names have at
|
||||
* most one numeric identity together.
|
||||
*/
|
||||
for (p = names; *p != '\0'; p = (q == NULL ? p + l : q + 1)) {
|
||||
int this_number;
|
||||
|
||||
if ((q = strchr(p, separator)) == NULL)
|
||||
l = strlen(p); /* offset to \0 */
|
||||
else
|
||||
l = q - p; /* offset to the next separator */
|
||||
|
||||
this_number = ossl_namemap_name2num_n(namemap, p, l);
|
||||
|
||||
if (*p == '\0' || *p == separator) {
|
||||
ERR_raise(ERR_LIB_CRYPTO, CRYPTO_R_BAD_ALGORITHM_NAME);
|
||||
return 0;
|
||||
}
|
||||
if (number == 0) {
|
||||
number = this_number;
|
||||
} else if (this_number != 0 && this_number != number) {
|
||||
ERR_raise_data(ERR_LIB_CRYPTO, CRYPTO_R_CONFLICTING_NAMES,
|
||||
"\"%.*s\" has an existing different identity %d (from \"%s\")",
|
||||
l, p, this_number, names);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Now that we have checked, register all names */
|
||||
for (p = names; *p != '\0'; p = (q == NULL ? p + l : q + 1)) {
|
||||
int this_number;
|
||||
|
||||
if ((q = strchr(p, separator)) == NULL)
|
||||
l = strlen(p); /* offset to \0 */
|
||||
else
|
||||
l = q - p; /* offset to the next separator */
|
||||
|
||||
this_number = ossl_namemap_add_name_n(namemap, number, p, l);
|
||||
if (number == 0) {
|
||||
number = this_number;
|
||||
} else if (this_number != number) {
|
||||
ERR_raise_data(ERR_LIB_CRYPTO, ERR_R_INTERNAL_ERROR,
|
||||
"Got number %d when expecting %d",
|
||||
this_number, number);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return number;
|
||||
}
|
||||
|
||||
/*-
|
||||
* Pre-population
|
||||
* ==============
|
||||
*/
|
||||
|
||||
#ifndef FIPS_MODE
|
||||
#include <openssl/evp.h>
|
||||
|
||||
/* Creates an initial namemap with names found in the legacy method db */
|
||||
static void get_legacy_evp_names(const char *main_name, const char *alias,
|
||||
void *arg)
|
||||
{
|
||||
int main_id = ossl_namemap_add_name(arg, 0, main_name);
|
||||
|
||||
/*
|
||||
* We could check that the returned value is the same as main_id,
|
||||
* but since this is a void function, there's no sane way to report
|
||||
* the error. The best we can do is trust ourselve to keep the legacy
|
||||
* method database conflict free.
|
||||
*
|
||||
* This registers any alias with the same number as the main name.
|
||||
* Should it be that the current |on| *has* the main name, this is
|
||||
* simply a no-op.
|
||||
*/
|
||||
if (alias != NULL) {
|
||||
(void)ossl_namemap_add_name(arg, main_id, alias);
|
||||
}
|
||||
}
|
||||
|
||||
static void get_legacy_cipher_names(const OBJ_NAME *on, void *arg)
|
||||
{
|
||||
const EVP_CIPHER *cipher = (void *)OBJ_NAME_get(on->name, on->type);
|
||||
|
||||
get_legacy_evp_names(EVP_CIPHER_name(cipher), on->name, arg);
|
||||
}
|
||||
|
||||
static void get_legacy_md_names(const OBJ_NAME *on, void *arg)
|
||||
{
|
||||
const EVP_MD *md = (void *)OBJ_NAME_get(on->name, on->type);
|
||||
/* We don't want the pkey_type names, so we need some extra care */
|
||||
int snid, lnid;
|
||||
|
||||
snid = OBJ_sn2nid(on->name);
|
||||
lnid = OBJ_ln2nid(on->name);
|
||||
if (snid != EVP_MD_pkey_type(md) && lnid != EVP_MD_pkey_type(md))
|
||||
get_legacy_evp_names(EVP_MD_name(md), on->name, arg);
|
||||
else
|
||||
get_legacy_evp_names(EVP_MD_name(md), NULL, arg);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*-
|
||||
* Constructors / destructors
|
||||
* ==========================
|
||||
*/
|
||||
|
||||
OSSL_NAMEMAP *ossl_namemap_stored(OPENSSL_CTX *libctx)
|
||||
{
|
||||
OSSL_NAMEMAP *namemap =
|
||||
openssl_ctx_get_data(libctx, OPENSSL_CTX_NAMEMAP_INDEX,
|
||||
&stored_namemap_method);
|
||||
|
||||
#ifndef FIPS_MODE
|
||||
if (namemap != NULL && ossl_namemap_empty(namemap)) {
|
||||
/* Before pilfering, we make sure the legacy database is populated */
|
||||
OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS
|
||||
| OPENSSL_INIT_ADD_ALL_DIGESTS, NULL);
|
||||
|
||||
OBJ_NAME_do_all(OBJ_NAME_TYPE_CIPHER_METH,
|
||||
get_legacy_cipher_names, namemap);
|
||||
OBJ_NAME_do_all(OBJ_NAME_TYPE_MD_METH,
|
||||
get_legacy_md_names, namemap);
|
||||
}
|
||||
#endif
|
||||
|
||||
return namemap;
|
||||
}
|
||||
|
||||
OSSL_NAMEMAP *ossl_namemap_new(void)
|
||||
{
|
||||
OSSL_NAMEMAP *namemap;
|
||||
|
||||
if ((namemap = OPENSSL_zalloc(sizeof(*namemap))) != NULL
|
||||
&& (namemap->lock = CRYPTO_THREAD_lock_new()) != NULL
|
||||
&& (namemap->namenum =
|
||||
lh_NAMENUM_ENTRY_new(namenum_hash, namenum_cmp)) != NULL)
|
||||
return namemap;
|
||||
|
||||
ossl_namemap_free(namemap);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ossl_namemap_free(OSSL_NAMEMAP *namemap)
|
||||
{
|
||||
if (namemap == NULL || namemap->stored)
|
||||
return;
|
||||
|
||||
lh_NAMENUM_ENTRY_doall(namemap->namenum, namenum_free);
|
||||
lh_NAMENUM_ENTRY_free(namemap->namenum);
|
||||
|
||||
CRYPTO_THREAD_lock_free(namemap->lock);
|
||||
OPENSSL_free(namemap);
|
||||
}
|
||||
@@ -14,6 +14,10 @@
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
|
||||
static const ERR_STRING_DATA CRYPTO_str_reasons[] = {
|
||||
{ERR_PACK(ERR_LIB_CRYPTO, 0, CRYPTO_R_BAD_ALGORITHM_NAME),
|
||||
"bad algorithm name"},
|
||||
{ERR_PACK(ERR_LIB_CRYPTO, 0, CRYPTO_R_CONFLICTING_NAMES),
|
||||
"conflicting names"},
|
||||
{ERR_PACK(ERR_LIB_CRYPTO, 0, CRYPTO_R_FIPS_MODE_NOT_SUPPORTED),
|
||||
"fips mode not supported"},
|
||||
{ERR_PACK(ERR_LIB_CRYPTO, 0, CRYPTO_R_ILLEGAL_HEX_DIGIT),
|
||||
|
||||
@@ -235,6 +235,5 @@ IMPLEMENT_ASN1_FUNCTIONS(OSSL_CRMF_MSG)
|
||||
ASN1_ITEM_TEMPLATE(OSSL_CRMF_MSGS) =
|
||||
ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0,
|
||||
OSSL_CRMF_MSGS, OSSL_CRMF_MSG)
|
||||
ASN1_ITEM_TEMPLATE_END(OSSL_CRMF_MSGS)
|
||||
ASN1_ITEM_TEMPLATE_END(OSSL_CRMF_MSGS)
|
||||
IMPLEMENT_ASN1_FUNCTIONS(OSSL_CRMF_MSGS)
|
||||
|
||||
+9
-10
@@ -97,10 +97,10 @@ static int OSSL_CRMF_MSG_push0_regCtrl(OSSL_CRMF_MSG *crm,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* id-regCtrl-regToken Control (section 6.1) */
|
||||
/* id-regCtrl-regToken Control (section 6.1) */
|
||||
IMPLEMENT_CRMF_CTRL_FUNC(regToken, ASN1_STRING, regCtrl)
|
||||
|
||||
/* id-regCtrl-authenticator Control (section 6.2) */
|
||||
/* id-regCtrl-authenticator Control (section 6.2) */
|
||||
#define ASN1_UTF8STRING_dup ASN1_STRING_dup
|
||||
IMPLEMENT_CRMF_CTRL_FUNC(authenticator, ASN1_UTF8STRING, regCtrl)
|
||||
|
||||
@@ -153,11 +153,11 @@ int OSSL_CRMF_MSG_set_PKIPublicationInfo_action(
|
||||
return ASN1_INTEGER_set(pi->action, action);
|
||||
}
|
||||
|
||||
/* id-regCtrl-pkiPublicationInfo Control (section 6.3) */
|
||||
/* id-regCtrl-pkiPublicationInfo Control (section 6.3) */
|
||||
IMPLEMENT_CRMF_CTRL_FUNC(pkiPublicationInfo, OSSL_CRMF_PKIPUBLICATIONINFO,
|
||||
regCtrl)
|
||||
|
||||
/* id-regCtrl-oldCertID Control (section 6.5) from the given */
|
||||
/* id-regCtrl-oldCertID Control (section 6.5) from the given */
|
||||
IMPLEMENT_CRMF_CTRL_FUNC(oldCertID, OSSL_CRMF_CERTID, regCtrl)
|
||||
|
||||
OSSL_CRMF_CERTID *OSSL_CRMF_CERTID_gen(const X509_NAME *issuer,
|
||||
@@ -188,10 +188,9 @@ OSSL_CRMF_CERTID *OSSL_CRMF_CERTID_gen(const X509_NAME *issuer,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* id-regCtrl-protocolEncrKey Control (section 6.6)
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* id-regCtrl-protocolEncrKey Control (section 6.6)
|
||||
*/
|
||||
IMPLEMENT_CRMF_CTRL_FUNC(protocolEncrKey, X509_PUBKEY, regCtrl)
|
||||
|
||||
/*-
|
||||
@@ -567,7 +566,7 @@ int OSSL_CRMF_MSGS_verify_popo(const OSSL_CRMF_MSGS *reqs,
|
||||
* return 1 if the type of req->popo->value.keyEncipherment
|
||||
* is OSSL_CRMF_POPOPRIVKEY_SUBSEQUENTMESSAGE and
|
||||
* its value.subsequentMessage == OSSL_CRMF_SUBSEQUENTMESSAGE_ENCRCERT
|
||||
*/
|
||||
*/
|
||||
case OSSL_CRMF_POPO_KEYAGREE:
|
||||
default:
|
||||
CRMFerr(CRMF_F_OSSL_CRMF_MSGS_VERIFY_POPO,
|
||||
@@ -702,7 +701,7 @@ X509 *OSSL_CRMF_ENCRYPTEDVALUE_get1_encCert(OSSL_CRMF_ENCRYPTEDVALUE *ecert,
|
||||
if ((iv = OPENSSL_malloc(EVP_CIPHER_iv_length(cipher))) == NULL)
|
||||
goto end;
|
||||
if (ASN1_TYPE_get_octetstring(ecert->symmAlg->parameter, iv,
|
||||
EVP_CIPHER_iv_length(cipher))
|
||||
EVP_CIPHER_iv_length(cipher))
|
||||
!= EVP_CIPHER_iv_length(cipher)) {
|
||||
CRMFerr(CRMF_F_OSSL_CRMF_ENCRYPTEDVALUE_GET1_ENCCERT,
|
||||
CRMF_R_MALFORMED_IV);
|
||||
|
||||
@@ -217,7 +217,7 @@ struct ossl_crmf_pbmparameter_st {
|
||||
ASN1_INTEGER *iterationCount;
|
||||
X509_ALGOR *mac;
|
||||
} /* OSSL_CRMF_PBMPARAMETER */;
|
||||
#define OSSL_CRMF_PBM_MAX_ITERATION_COUNT 100000 /* if too large allows DoS */
|
||||
# define OSSL_CRMF_PBM_MAX_ITERATION_COUNT 100000 /* if too large allows DoS */
|
||||
|
||||
/*-
|
||||
* POPOSigningKeyInput ::= SEQUENCE {
|
||||
@@ -232,7 +232,7 @@ struct ossl_crmf_pbmparameter_st {
|
||||
* -- on the DER-encoded value of publicKey
|
||||
* publicKey SubjectPublicKeyInfo -- from CertTemplate
|
||||
* }
|
||||
*/
|
||||
*/
|
||||
typedef struct ossl_crmf_poposigningkeyinput_authinfo_st {
|
||||
int type;
|
||||
union {
|
||||
|
||||
@@ -133,8 +133,7 @@ int OSSL_CRMF_pbm_new(const OSSL_CRMF_PBMPARAMETER *pbmp,
|
||||
int ok = 0;
|
||||
EVP_MAC *mac = NULL;
|
||||
EVP_MAC_CTX *mctx = NULL;
|
||||
OSSL_PARAM macparams[3] =
|
||||
{ OSSL_PARAM_END, OSSL_PARAM_END, OSSL_PARAM_END };
|
||||
OSSL_PARAM macparams[3] = {OSSL_PARAM_END, OSSL_PARAM_END, OSSL_PARAM_END};
|
||||
|
||||
if (out == NULL || pbmp == NULL || pbmp->mac == NULL
|
||||
|| pbmp->mac->algorithm == NULL || msg == NULL || sec == NULL) {
|
||||
@@ -193,16 +192,15 @@ int OSSL_CRMF_pbm_new(const OSSL_CRMF_PBMPARAMETER *pbmp,
|
||||
mac_nid = OBJ_obj2nid(pbmp->mac->algorithm);
|
||||
|
||||
if (!EVP_PBE_find(EVP_PBE_TYPE_PRF, mac_nid, NULL, &hmac_md_nid, NULL)
|
||||
|| ((mdname = OBJ_nid2sn(hmac_md_nid)) == NULL)) {
|
||||
|| (mdname = OBJ_nid2sn(hmac_md_nid)) == NULL) {
|
||||
CRMFerr(CRMF_F_OSSL_CRMF_PBM_NEW, CRMF_R_UNSUPPORTED_ALGORITHM);
|
||||
goto err;
|
||||
}
|
||||
|
||||
macparams[0] =
|
||||
OSSL_PARAM_construct_utf8_string(OSSL_MAC_PARAM_DIGEST,
|
||||
(char *)mdname, 0);
|
||||
macparams[1] =
|
||||
OSSL_PARAM_construct_octet_string(OSSL_MAC_PARAM_KEY, basekey, bklen);
|
||||
macparams[0] = OSSL_PARAM_construct_utf8_string(OSSL_MAC_PARAM_DIGEST,
|
||||
(char *)mdname, 0);
|
||||
macparams[1] = OSSL_PARAM_construct_octet_string(OSSL_MAC_PARAM_KEY,
|
||||
basekey, bklen);
|
||||
if ((mac = EVP_MAC_fetch(NULL, "HMAC", NULL)) == NULL
|
||||
|| (mctx = EVP_MAC_CTX_new(mac)) == NULL
|
||||
|| !EVP_MAC_CTX_set_params(mctx, macparams)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user