Compare commits
1
Commits
e3a2ed3d39
...
f03e5e0d15
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f03e5e0d15 |
@@ -2,7 +2,7 @@
|
||||
--------------------
|
||||
|
||||
This document describes installation on all supported operating
|
||||
systems (the Linux/Unix family, OpenVMS and Windows)
|
||||
systems (the Linux/Unix family including Mac OS/X, OpenVMS and Windows)
|
||||
|
||||
To install OpenSSL, you will need:
|
||||
|
||||
@@ -76,7 +76,7 @@
|
||||
|
||||
If you want to just get on with it, do:
|
||||
|
||||
on Unix:
|
||||
on Unix (again, this includes Mac OS/X):
|
||||
|
||||
$ ./config
|
||||
$ make
|
||||
|
||||
@@ -40,7 +40,8 @@
|
||||
# CBC en-/decrypt CTR XTS
|
||||
# POWER8[le] 3.96/0.72 0.74 1.1
|
||||
# POWER8[be] 3.75/0.65 0.66 1.0
|
||||
# POWER9[le] 3.05/0.65 0.65 0.80
|
||||
# POWER9[le] 4.02/0.86 0.84 1.05
|
||||
# POWER9[be] 3.99/0.78 0.79 0.97
|
||||
|
||||
$flavour = shift;
|
||||
|
||||
|
||||
@@ -115,6 +115,19 @@ OPENSSL_cleanse:
|
||||
CRYPTO_memcmp:
|
||||
eor w3,w3,w3
|
||||
cbz x2,.Lno_data // len==0?
|
||||
cmp x2,#16
|
||||
b.ne .Loop_cmp
|
||||
ldp x8,x9,[x0]
|
||||
ldp x10,x11,[x1]
|
||||
eor x8,x8,x10
|
||||
eor x9,x9,x11
|
||||
orr x8,x8,x9
|
||||
mov x0,#1
|
||||
cmp x8,#0
|
||||
csel x0,xzr,x0,eq
|
||||
ret
|
||||
|
||||
.align 4
|
||||
.Loop_cmp:
|
||||
ldrb w4,[x0],#1
|
||||
ldrb w5,[x1],#1
|
||||
|
||||
@@ -23,11 +23,11 @@
|
||||
# IALU/gcc-4.x 3xAltiVec+1xIALU
|
||||
#
|
||||
# Freescale e300 13.6/+115% -
|
||||
# PPC74x0/G4e 6.81/+310% 3.72
|
||||
# PPC74x0/G4e 6.81/+310% 3.81
|
||||
# PPC970/G5 9.29/+160% ?
|
||||
# POWER7 8.62/+61% 3.38
|
||||
# POWER8 8.70/+51% 3.36
|
||||
# POWER9 6.61/+29% 3.30(*)
|
||||
# POWER7 8.62/+61% 3.35
|
||||
# POWER8 8.70/+51% 2.91
|
||||
# POWER9 8.80/+29% 4.44(*)
|
||||
#
|
||||
# (*) this is trade-off result, it's possible to improve it, but
|
||||
# then it would negatively affect all others;
|
||||
@@ -398,12 +398,12 @@ ___
|
||||
my ($A0,$B0,$C0,$D0,$A1,$B1,$C1,$D1,$A2,$B2,$C2,$D2)
|
||||
= map("v$_",(0..11));
|
||||
my @K = map("v$_",(12..17));
|
||||
my ($FOUR,$sixteen,$twenty4) = map("v$_",(18..20));
|
||||
my ($inpperm,$outperm,$outmask) = map("v$_",(21..23));
|
||||
my @D = map("v$_",(24..28));
|
||||
my ($FOUR,$sixteen,$twenty4) = map("v$_",(18..19,23));
|
||||
my ($inpperm,$outperm,$outmask) = map("v$_",(24..26));
|
||||
my @D = map("v$_",(27..31));
|
||||
my ($twelve,$seven,$T0,$T1) = @D;
|
||||
|
||||
my $FRAME=$LOCALS+64+10*16+18*$SIZE_T; # 10*16 is for v20-v28 offload
|
||||
my $FRAME=$LOCALS+64+10*16+18*$SIZE_T; # 10*16 is for v23-v31 offload
|
||||
|
||||
sub VMXROUND {
|
||||
my $odd = pop;
|
||||
@@ -445,22 +445,22 @@ $code.=<<___;
|
||||
li r10,`15+$LOCALS+64`
|
||||
li r11,`31+$LOCALS+64`
|
||||
mfspr r12,256
|
||||
stvx v20,r10,$sp
|
||||
stvx v23,r10,$sp
|
||||
addi r10,r10,32
|
||||
stvx v21,r11,$sp
|
||||
stvx v24,r11,$sp
|
||||
addi r11,r11,32
|
||||
stvx v22,r10,$sp
|
||||
stvx v25,r10,$sp
|
||||
addi r10,r10,32
|
||||
stvx v23,r11,$sp
|
||||
stvx v26,r11,$sp
|
||||
addi r11,r11,32
|
||||
stvx v24,r10,$sp
|
||||
stvx v27,r10,$sp
|
||||
addi r10,r10,32
|
||||
stvx v25,r11,$sp
|
||||
stvx v28,r11,$sp
|
||||
addi r11,r11,32
|
||||
stvx v26,r10,$sp
|
||||
stvx v29,r10,$sp
|
||||
addi r10,r10,32
|
||||
stvx v27,r11,$sp
|
||||
stvx v28,r10,$sp
|
||||
stvx v30,r11,$sp
|
||||
stvx v31,r10,$sp
|
||||
stw r12,`$FRAME-$SIZE_T*18-4`($sp) # save vrsave
|
||||
$PUSH r14,`$FRAME-$SIZE_T*18`($sp)
|
||||
$PUSH r15,`$FRAME-$SIZE_T*17`($sp)
|
||||
@@ -480,7 +480,7 @@ $code.=<<___;
|
||||
$PUSH r29,`$FRAME-$SIZE_T*3`($sp)
|
||||
$PUSH r30,`$FRAME-$SIZE_T*2`($sp)
|
||||
$PUSH r31,`$FRAME-$SIZE_T*1`($sp)
|
||||
li r12,-8
|
||||
li r12,-4096+511
|
||||
$PUSH r0, `$FRAME+$LRSAVE`($sp)
|
||||
mtspr 256,r12 # preserve 29 AltiVec registers
|
||||
|
||||
@@ -588,9 +588,13 @@ ___
|
||||
my @thread3=&ROUND(0,4,8,12);
|
||||
|
||||
foreach (@thread0) {
|
||||
eval; eval(shift(@thread3));
|
||||
eval(shift(@thread1)); eval(shift(@thread3));
|
||||
eval(shift(@thread2)); eval(shift(@thread3));
|
||||
eval;
|
||||
eval(shift(@thread1));
|
||||
eval(shift(@thread2));
|
||||
|
||||
eval(shift(@thread3));
|
||||
eval(shift(@thread3));
|
||||
eval(shift(@thread3));
|
||||
}
|
||||
foreach (@thread3) { eval; }
|
||||
|
||||
@@ -600,9 +604,13 @@ ___
|
||||
@thread3=&ROUND(0,5,10,15);
|
||||
|
||||
foreach (@thread0) {
|
||||
eval; eval(shift(@thread3));
|
||||
eval(shift(@thread1)); eval(shift(@thread3));
|
||||
eval(shift(@thread2)); eval(shift(@thread3));
|
||||
eval;
|
||||
eval(shift(@thread1));
|
||||
eval(shift(@thread2));
|
||||
|
||||
eval(shift(@thread3));
|
||||
eval(shift(@thread3));
|
||||
eval(shift(@thread3));
|
||||
}
|
||||
foreach (@thread3) { eval; }
|
||||
$code.=<<___;
|
||||
@@ -843,22 +851,22 @@ Ldone_vmx:
|
||||
li r10,`15+$LOCALS+64`
|
||||
li r11,`31+$LOCALS+64`
|
||||
mtspr 256,r12 # restore vrsave
|
||||
lvx v20,r10,$sp
|
||||
lvx v23,r10,$sp
|
||||
addi r10,r10,32
|
||||
lvx v21,r11,$sp
|
||||
lvx v24,r11,$sp
|
||||
addi r11,r11,32
|
||||
lvx v22,r10,$sp
|
||||
lvx v25,r10,$sp
|
||||
addi r10,r10,32
|
||||
lvx v23,r11,$sp
|
||||
lvx v26,r11,$sp
|
||||
addi r11,r11,32
|
||||
lvx v24,r10,$sp
|
||||
lvx v27,r10,$sp
|
||||
addi r10,r10,32
|
||||
lvx v25,r11,$sp
|
||||
lvx v28,r11,$sp
|
||||
addi r11,r11,32
|
||||
lvx v26,r10,$sp
|
||||
lvx v29,r10,$sp
|
||||
addi r10,r10,32
|
||||
lvx v27,r11,$sp
|
||||
lvx v28,r10,$sp
|
||||
lvx v30,r11,$sp
|
||||
lvx v31,r10,$sp
|
||||
$POP r0, `$FRAME+$LRSAVE`($sp)
|
||||
$POP r14,`$FRAME-$SIZE_T*18`($sp)
|
||||
$POP r15,`$FRAME-$SIZE_T*17`($sp)
|
||||
|
||||
+30
-43
@@ -2814,8 +2814,8 @@ static int aes_gcm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
|
||||
case EVP_CTRL_INIT:
|
||||
gctx->key_set = 0;
|
||||
gctx->iv_set = 0;
|
||||
gctx->ivlen = EVP_CIPHER_CTX_iv_length(c);
|
||||
gctx->iv = EVP_CIPHER_CTX_iv_noconst(c);
|
||||
gctx->ivlen = c->cipher->iv_len;
|
||||
gctx->iv = c->iv;
|
||||
gctx->taglen = -1;
|
||||
gctx->iv_gen = 0;
|
||||
gctx->tls_aad_len = -1;
|
||||
@@ -2826,7 +2826,7 @@ static int aes_gcm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
|
||||
return 0;
|
||||
/* Allocate memory for IV if needed */
|
||||
if ((arg > EVP_MAX_IV_LENGTH) && (arg > gctx->ivlen)) {
|
||||
if (gctx->iv != EVP_CIPHER_CTX_iv_noconst(c))
|
||||
if (gctx->iv != c->iv)
|
||||
OPENSSL_free(gctx->iv);
|
||||
if ((gctx->iv = OPENSSL_malloc(arg)) == NULL) {
|
||||
EVPerr(EVP_F_AES_GCM_CTRL, ERR_R_MALLOC_FAILURE);
|
||||
@@ -2837,17 +2837,17 @@ static int aes_gcm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
|
||||
return 1;
|
||||
|
||||
case EVP_CTRL_AEAD_SET_TAG:
|
||||
if (arg <= 0 || arg > 16 || EVP_CIPHER_CTX_encrypting(c))
|
||||
if (arg <= 0 || arg > 16 || c->encrypt)
|
||||
return 0;
|
||||
memcpy(EVP_CIPHER_CTX_buf_noconst(c), ptr, arg);
|
||||
memcpy(c->buf, ptr, arg);
|
||||
gctx->taglen = arg;
|
||||
return 1;
|
||||
|
||||
case EVP_CTRL_AEAD_GET_TAG:
|
||||
if (arg <= 0 || arg > 16 || !EVP_CIPHER_CTX_encrypting(c)
|
||||
if (arg <= 0 || arg > 16 || !c->encrypt
|
||||
|| gctx->taglen < 0)
|
||||
return 0;
|
||||
memcpy(ptr, EVP_CIPHER_CTX_buf_noconst(c), arg);
|
||||
memcpy(ptr, c->buf, arg);
|
||||
return 1;
|
||||
|
||||
case EVP_CTRL_GCM_SET_IV_FIXED:
|
||||
@@ -2865,8 +2865,7 @@ static int aes_gcm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
|
||||
return 0;
|
||||
if (arg)
|
||||
memcpy(gctx->iv, ptr, arg);
|
||||
if (EVP_CIPHER_CTX_encrypting(c)
|
||||
&& RAND_bytes(gctx->iv + arg, gctx->ivlen - arg) <= 0)
|
||||
if (c->encrypt && RAND_bytes(gctx->iv + arg, gctx->ivlen - arg) <= 0)
|
||||
return 0;
|
||||
gctx->iv_gen = 1;
|
||||
return 1;
|
||||
@@ -2887,8 +2886,7 @@ static int aes_gcm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
|
||||
return 1;
|
||||
|
||||
case EVP_CTRL_GCM_SET_IV_INV:
|
||||
if (gctx->iv_gen == 0 || gctx->key_set == 0
|
||||
|| EVP_CIPHER_CTX_encrypting(c))
|
||||
if (gctx->iv_gen == 0 || gctx->key_set == 0 || c->encrypt)
|
||||
return 0;
|
||||
memcpy(gctx->iv + gctx->ivlen - arg, ptr, arg);
|
||||
CRYPTO_gcm128_setiv(&gctx->gcm, gctx->iv, gctx->ivlen);
|
||||
@@ -2899,24 +2897,22 @@ static int aes_gcm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
|
||||
/* Save the AAD for later use */
|
||||
if (arg != EVP_AEAD_TLS1_AAD_LEN)
|
||||
return 0;
|
||||
memcpy(EVP_CIPHER_CTX_buf_noconst(c), ptr, arg);
|
||||
memcpy(c->buf, ptr, arg);
|
||||
gctx->tls_aad_len = arg;
|
||||
{
|
||||
unsigned int len =
|
||||
EVP_CIPHER_CTX_buf_noconst(c)[arg - 2] << 8
|
||||
| EVP_CIPHER_CTX_buf_noconst(c)[arg - 1];
|
||||
unsigned int len = c->buf[arg - 2] << 8 | c->buf[arg - 1];
|
||||
/* Correct length for explicit IV */
|
||||
if (len < EVP_GCM_TLS_EXPLICIT_IV_LEN)
|
||||
return 0;
|
||||
len -= EVP_GCM_TLS_EXPLICIT_IV_LEN;
|
||||
/* If decrypting correct for tag too */
|
||||
if (!EVP_CIPHER_CTX_encrypting(c)) {
|
||||
if (!c->encrypt) {
|
||||
if (len < EVP_GCM_TLS_TAG_LEN)
|
||||
return 0;
|
||||
len -= EVP_GCM_TLS_TAG_LEN;
|
||||
}
|
||||
EVP_CIPHER_CTX_buf_noconst(c)[arg - 2] = len >> 8;
|
||||
EVP_CIPHER_CTX_buf_noconst(c)[arg - 1] = len & 0xff;
|
||||
c->buf[arg - 2] = len >> 8;
|
||||
c->buf[arg - 1] = len & 0xff;
|
||||
}
|
||||
/* Extra padding: tag appended to record */
|
||||
return EVP_GCM_TLS_TAG_LEN;
|
||||
@@ -2930,8 +2926,8 @@ static int aes_gcm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
|
||||
return 0;
|
||||
gctx_out->gcm.key = &gctx_out->ks;
|
||||
}
|
||||
if (gctx->iv == EVP_CIPHER_CTX_iv_noconst(c))
|
||||
gctx_out->iv = EVP_CIPHER_CTX_iv_noconst(out);
|
||||
if (gctx->iv == c->iv)
|
||||
gctx_out->iv = out->iv;
|
||||
else {
|
||||
if ((gctx_out->iv = OPENSSL_malloc(gctx->ivlen)) == NULL) {
|
||||
EVPerr(EVP_F_AES_GCM_CTRL, ERR_R_MALLOC_FAILURE);
|
||||
@@ -2958,8 +2954,7 @@ static int aes_gcm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
||||
do {
|
||||
#ifdef HWAES_CAPABLE
|
||||
if (HWAES_CAPABLE) {
|
||||
HWAES_set_encrypt_key(key, EVP_CIPHER_CTX_key_length(ctx) * 8,
|
||||
&gctx->ks.ks);
|
||||
HWAES_set_encrypt_key(key, ctx->key_len * 8, &gctx->ks.ks);
|
||||
CRYPTO_gcm128_init(&gctx->gcm, &gctx->ks,
|
||||
(block128_f) HWAES_encrypt);
|
||||
# ifdef HWAES_ctr32_encrypt_blocks
|
||||
@@ -2972,8 +2967,7 @@ static int aes_gcm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
||||
#endif
|
||||
#ifdef BSAES_CAPABLE
|
||||
if (BSAES_CAPABLE) {
|
||||
AES_set_encrypt_key(key, EVP_CIPHER_CTX_key_length(ctx) * 8,
|
||||
&gctx->ks.ks);
|
||||
AES_set_encrypt_key(key, ctx->key_len * 8, &gctx->ks.ks);
|
||||
CRYPTO_gcm128_init(&gctx->gcm, &gctx->ks,
|
||||
(block128_f) AES_encrypt);
|
||||
gctx->ctr = (ctr128_f) bsaes_ctr32_encrypt_blocks;
|
||||
@@ -2982,8 +2976,7 @@ static int aes_gcm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
||||
#endif
|
||||
#ifdef VPAES_CAPABLE
|
||||
if (VPAES_CAPABLE) {
|
||||
vpaes_set_encrypt_key(key, EVP_CIPHER_CTX_key_length(ctx) * 8,
|
||||
&gctx->ks.ks);
|
||||
vpaes_set_encrypt_key(key, ctx->key_len * 8, &gctx->ks.ks);
|
||||
CRYPTO_gcm128_init(&gctx->gcm, &gctx->ks,
|
||||
(block128_f) vpaes_encrypt);
|
||||
gctx->ctr = NULL;
|
||||
@@ -2992,8 +2985,7 @@ static int aes_gcm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
||||
#endif
|
||||
(void)0; /* terminate potentially open 'else' */
|
||||
|
||||
AES_set_encrypt_key(key, EVP_CIPHER_CTX_key_length(ctx) * 8,
|
||||
&gctx->ks.ks);
|
||||
AES_set_encrypt_key(key, ctx->key_len * 8, &gctx->ks.ks);
|
||||
CRYPTO_gcm128_init(&gctx->gcm, &gctx->ks,
|
||||
(block128_f) AES_encrypt);
|
||||
#ifdef AES_CTR_ASM
|
||||
@@ -3045,19 +3037,18 @@ static int aes_gcm_tls_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
||||
* Set IV from start of buffer or generate IV and write to start of
|
||||
* buffer.
|
||||
*/
|
||||
if (EVP_CIPHER_CTX_ctrl(ctx, EVP_CIPHER_CTX_encrypting(ctx) ?
|
||||
EVP_CTRL_GCM_IV_GEN : EVP_CTRL_GCM_SET_IV_INV,
|
||||
if (EVP_CIPHER_CTX_ctrl(ctx, ctx->encrypt ? EVP_CTRL_GCM_IV_GEN
|
||||
: EVP_CTRL_GCM_SET_IV_INV,
|
||||
EVP_GCM_TLS_EXPLICIT_IV_LEN, out) <= 0)
|
||||
goto err;
|
||||
/* Use saved AAD */
|
||||
if (CRYPTO_gcm128_aad(&gctx->gcm, EVP_CIPHER_CTX_buf_noconst(ctx),
|
||||
gctx->tls_aad_len))
|
||||
if (CRYPTO_gcm128_aad(&gctx->gcm, ctx->buf, gctx->tls_aad_len))
|
||||
goto err;
|
||||
/* Fix buffer and length to point to payload */
|
||||
in += EVP_GCM_TLS_EXPLICIT_IV_LEN;
|
||||
out += EVP_GCM_TLS_EXPLICIT_IV_LEN;
|
||||
len -= EVP_GCM_TLS_EXPLICIT_IV_LEN + EVP_GCM_TLS_TAG_LEN;
|
||||
if (EVP_CIPHER_CTX_encrypting(ctx)) {
|
||||
if (ctx->encrypt) {
|
||||
/* Encrypt payload */
|
||||
if (gctx->ctr) {
|
||||
size_t bulk = 0;
|
||||
@@ -3136,11 +3127,9 @@ static int aes_gcm_tls_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
||||
goto err;
|
||||
}
|
||||
/* Retrieve tag */
|
||||
CRYPTO_gcm128_tag(&gctx->gcm, EVP_CIPHER_CTX_buf_noconst(ctx),
|
||||
EVP_GCM_TLS_TAG_LEN);
|
||||
CRYPTO_gcm128_tag(&gctx->gcm, ctx->buf, EVP_GCM_TLS_TAG_LEN);
|
||||
/* If tag mismatch wipe buffer */
|
||||
if (CRYPTO_memcmp(EVP_CIPHER_CTX_buf_noconst(ctx), in + len,
|
||||
EVP_GCM_TLS_TAG_LEN)) {
|
||||
if (CRYPTO_memcmp(ctx->buf, in + len, EVP_GCM_TLS_TAG_LEN)) {
|
||||
OPENSSL_cleanse(out, len);
|
||||
goto err;
|
||||
}
|
||||
@@ -3170,7 +3159,7 @@ static int aes_gcm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
||||
if (out == NULL) {
|
||||
if (CRYPTO_gcm128_aad(&gctx->gcm, in, len))
|
||||
return -1;
|
||||
} else if (EVP_CIPHER_CTX_encrypting(ctx)) {
|
||||
} else if (ctx->encrypt) {
|
||||
if (gctx->ctr) {
|
||||
size_t bulk = 0;
|
||||
#if defined(AES_GCM_ASM)
|
||||
@@ -3261,17 +3250,15 @@ static int aes_gcm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
||||
}
|
||||
return len;
|
||||
} else {
|
||||
if (!EVP_CIPHER_CTX_encrypting(ctx)) {
|
||||
if (!ctx->encrypt) {
|
||||
if (gctx->taglen < 0)
|
||||
return -1;
|
||||
if (CRYPTO_gcm128_finish(&gctx->gcm,
|
||||
EVP_CIPHER_CTX_buf_noconst(ctx),
|
||||
gctx->taglen) != 0)
|
||||
if (CRYPTO_gcm128_finish(&gctx->gcm, ctx->buf, gctx->taglen) != 0)
|
||||
return -1;
|
||||
gctx->iv_set = 0;
|
||||
return 0;
|
||||
}
|
||||
CRYPTO_gcm128_tag(&gctx->gcm, EVP_CIPHER_CTX_buf_noconst(ctx), 16);
|
||||
CRYPTO_gcm128_tag(&gctx->gcm, ctx->buf, 16);
|
||||
gctx->taglen = 16;
|
||||
/* Don't reuse the IV */
|
||||
gctx->iv_set = 0;
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
# 2x aggregated reduction improves performance by 50% (resulting
|
||||
# performance on POWER8 is 1 cycle per processed byte), and 4x
|
||||
# aggregated reduction - by 170% or 2.7x (resulting in 0.55 cpb).
|
||||
# POWER9 delivers 0.40 cpb.
|
||||
# POWER9 delivers 0.51 cpb.
|
||||
|
||||
$flavour=shift;
|
||||
$output =shift;
|
||||
|
||||
+246
-34
@@ -986,7 +986,7 @@ int CRYPTO_gcm128_encrypt(GCM128_CONTEXT *ctx,
|
||||
long one;
|
||||
char little;
|
||||
} is_endian = { 1 };
|
||||
unsigned int n, ctr;
|
||||
unsigned int n, ctr, mres;
|
||||
size_t i;
|
||||
u64 mlen = ctx->len.u[1];
|
||||
block128_f block = ctx->block;
|
||||
@@ -1004,9 +1004,23 @@ int CRYPTO_gcm128_encrypt(GCM128_CONTEXT *ctx,
|
||||
return -1;
|
||||
ctx->len.u[1] = mlen;
|
||||
|
||||
mres = ctx->mres;
|
||||
|
||||
if (ctx->ares) {
|
||||
/* First call to encrypt finalizes GHASH(AAD) */
|
||||
#if defined(GHASH) && !defined(OPENSSL_SMALL_FOOTPRINT)
|
||||
if (len == 0) {
|
||||
GCM_MUL(ctx);
|
||||
ctx->ares = 0;
|
||||
return 0;
|
||||
}
|
||||
memcpy(ctx->Xn, ctx->Xi.c, sizeof(ctx->Xi));
|
||||
ctx->Xi.u[0] = 0;
|
||||
ctx->Xi.u[1] = 0;
|
||||
mres = sizeof(ctx->Xi);
|
||||
#else
|
||||
GCM_MUL(ctx);
|
||||
#endif
|
||||
ctx->ares = 0;
|
||||
}
|
||||
|
||||
@@ -1019,28 +1033,48 @@ int CRYPTO_gcm128_encrypt(GCM128_CONTEXT *ctx,
|
||||
else
|
||||
ctr = ctx->Yi.d[3];
|
||||
|
||||
n = ctx->mres;
|
||||
n = mres % 16;
|
||||
#if !defined(OPENSSL_SMALL_FOOTPRINT)
|
||||
if (16 % sizeof(size_t) == 0) { /* always true actually */
|
||||
do {
|
||||
if (n) {
|
||||
# if defined(GHASH)
|
||||
while (n && len) {
|
||||
ctx->Xn[mres++] = *(out++) = *(in++) ^ ctx->EKi.c[n];
|
||||
--len;
|
||||
n = (n + 1) % 16;
|
||||
}
|
||||
if (n == 0) {
|
||||
GHASH(ctx, ctx->Xn, mres);
|
||||
mres = 0;
|
||||
} else {
|
||||
ctx->mres = mres;
|
||||
return 0;
|
||||
}
|
||||
# else
|
||||
while (n && len) {
|
||||
ctx->Xi.c[n] ^= *(out++) = *(in++) ^ ctx->EKi.c[n];
|
||||
--len;
|
||||
n = (n + 1) % 16;
|
||||
}
|
||||
if (n == 0)
|
||||
if (n == 0) {
|
||||
GCM_MUL(ctx);
|
||||
else {
|
||||
mres = 0;
|
||||
} else {
|
||||
ctx->mres = n;
|
||||
return 0;
|
||||
}
|
||||
# endif
|
||||
}
|
||||
# if defined(STRICT_ALIGNMENT)
|
||||
if (((size_t)in | (size_t)out) % sizeof(size_t) != 0)
|
||||
break;
|
||||
# endif
|
||||
# if defined(GHASH)
|
||||
if (len >= 16 && mres) {
|
||||
GHASH(ctx, ctx->Xn, mres);
|
||||
mres = 0;
|
||||
}
|
||||
# if defined(GHASH_CHUNK)
|
||||
while (len >= GHASH_CHUNK) {
|
||||
size_t j = GHASH_CHUNK;
|
||||
@@ -1128,13 +1162,21 @@ int CRYPTO_gcm128_encrypt(GCM128_CONTEXT *ctx,
|
||||
# endif
|
||||
else
|
||||
ctx->Yi.d[3] = ctr;
|
||||
# if defined(GHASH)
|
||||
while (len--) {
|
||||
ctx->Xn[mres++] = out[n] = in[n] ^ ctx->EKi.c[n];
|
||||
++n;
|
||||
}
|
||||
# else
|
||||
while (len--) {
|
||||
ctx->Xi.c[n] ^= out[n] = in[n] ^ ctx->EKi.c[n];
|
||||
++n;
|
||||
}
|
||||
mres = n;
|
||||
# endif
|
||||
}
|
||||
|
||||
ctx->mres = n;
|
||||
ctx->mres = mres;
|
||||
return 0;
|
||||
} while (0);
|
||||
}
|
||||
@@ -1152,13 +1194,22 @@ int CRYPTO_gcm128_encrypt(GCM128_CONTEXT *ctx,
|
||||
else
|
||||
ctx->Yi.d[3] = ctr;
|
||||
}
|
||||
ctx->Xi.c[n] ^= out[i] = in[i] ^ ctx->EKi.c[n];
|
||||
#if defined(GHASH) && !defined(OPENSSL_SMALL_FOOTPRINT)
|
||||
ctx->Xn[mres++] = out[i] = in[i] ^ ctx->EKi.c[n];
|
||||
n = (n + 1) % 16;
|
||||
if (mres == sizeof(ctx->Xn)) {
|
||||
GHASH(ctx,ctx->Xn,sizeof(ctx->Xn));
|
||||
mres = 0;
|
||||
}
|
||||
#else
|
||||
ctx->Xi.c[n] ^= out[i] = in[i] ^ ctx->EKi.c[n];
|
||||
mres = n = (n + 1) % 16;
|
||||
if (n == 0)
|
||||
GCM_MUL(ctx);
|
||||
#endif
|
||||
}
|
||||
|
||||
ctx->mres = n;
|
||||
ctx->mres = mres;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1170,7 +1221,7 @@ int CRYPTO_gcm128_decrypt(GCM128_CONTEXT *ctx,
|
||||
long one;
|
||||
char little;
|
||||
} is_endian = { 1 };
|
||||
unsigned int n, ctr;
|
||||
unsigned int n, ctr, mres;
|
||||
size_t i;
|
||||
u64 mlen = ctx->len.u[1];
|
||||
block128_f block = ctx->block;
|
||||
@@ -1188,9 +1239,23 @@ int CRYPTO_gcm128_decrypt(GCM128_CONTEXT *ctx,
|
||||
return -1;
|
||||
ctx->len.u[1] = mlen;
|
||||
|
||||
mres = ctx->mres;
|
||||
|
||||
if (ctx->ares) {
|
||||
/* First call to decrypt finalizes GHASH(AAD) */
|
||||
#if defined(GHASH) && !defined(OPENSSL_SMALL_FOOTPRINT)
|
||||
if (len == 0) {
|
||||
GCM_MUL(ctx);
|
||||
ctx->ares = 0;
|
||||
return 0;
|
||||
}
|
||||
memcpy(ctx->Xn, ctx->Xi.c, sizeof(ctx->Xi));
|
||||
ctx->Xi.u[0] = 0;
|
||||
ctx->Xi.u[1] = 0;
|
||||
mres = sizeof(ctx->Xi);
|
||||
#else
|
||||
GCM_MUL(ctx);
|
||||
#endif
|
||||
ctx->ares = 0;
|
||||
}
|
||||
|
||||
@@ -1203,11 +1268,25 @@ int CRYPTO_gcm128_decrypt(GCM128_CONTEXT *ctx,
|
||||
else
|
||||
ctr = ctx->Yi.d[3];
|
||||
|
||||
n = ctx->mres;
|
||||
n = mres % 16;
|
||||
#if !defined(OPENSSL_SMALL_FOOTPRINT)
|
||||
if (16 % sizeof(size_t) == 0) { /* always true actually */
|
||||
do {
|
||||
if (n) {
|
||||
# if defined(GHASH)
|
||||
while (n && len) {
|
||||
*(out++) = (ctx->Xn[mres++] = *(in++)) ^ ctx->EKi.c[n];
|
||||
--len;
|
||||
n = (n + 1) % 16;
|
||||
}
|
||||
if (n == 0) {
|
||||
GHASH(ctx, ctx->Xn, mres);
|
||||
mres = 0;
|
||||
} else {
|
||||
ctx->mres = mres;
|
||||
return 0;
|
||||
}
|
||||
# else
|
||||
while (n && len) {
|
||||
u8 c = *(in++);
|
||||
*(out++) = c ^ ctx->EKi.c[n];
|
||||
@@ -1215,18 +1294,24 @@ int CRYPTO_gcm128_decrypt(GCM128_CONTEXT *ctx,
|
||||
--len;
|
||||
n = (n + 1) % 16;
|
||||
}
|
||||
if (n == 0)
|
||||
if (n == 0) {
|
||||
GCM_MUL(ctx);
|
||||
else {
|
||||
mres = 0;
|
||||
} else {
|
||||
ctx->mres = n;
|
||||
return 0;
|
||||
}
|
||||
# endif
|
||||
}
|
||||
# if defined(STRICT_ALIGNMENT)
|
||||
if (((size_t)in | (size_t)out) % sizeof(size_t) != 0)
|
||||
break;
|
||||
# endif
|
||||
# if defined(GHASH)
|
||||
if (len >= 16 && mres) {
|
||||
GHASH(ctx, ctx->Xn, mres);
|
||||
mres = 0;
|
||||
}
|
||||
# if defined(GHASH_CHUNK)
|
||||
while (len >= GHASH_CHUNK) {
|
||||
size_t j = GHASH_CHUNK;
|
||||
@@ -1315,15 +1400,23 @@ int CRYPTO_gcm128_decrypt(GCM128_CONTEXT *ctx,
|
||||
# endif
|
||||
else
|
||||
ctx->Yi.d[3] = ctr;
|
||||
# if defined(GHASH)
|
||||
while (len--) {
|
||||
out[n] = (ctx->Xn[mres++] = in[n]) ^ ctx->EKi.c[n];
|
||||
++n;
|
||||
}
|
||||
# else
|
||||
while (len--) {
|
||||
u8 c = in[n];
|
||||
ctx->Xi.c[n] ^= c;
|
||||
out[n] = c ^ ctx->EKi.c[n];
|
||||
++n;
|
||||
}
|
||||
mres = n;
|
||||
# endif
|
||||
}
|
||||
|
||||
ctx->mres = n;
|
||||
ctx->mres = mres;
|
||||
return 0;
|
||||
} while (0);
|
||||
}
|
||||
@@ -1342,15 +1435,24 @@ int CRYPTO_gcm128_decrypt(GCM128_CONTEXT *ctx,
|
||||
else
|
||||
ctx->Yi.d[3] = ctr;
|
||||
}
|
||||
#if defined(GHASH) && !defined(OPENSSL_SMALL_FOOTPRINT)
|
||||
out[i] = (ctx->Xn[mres++] = c = in[i]) ^ ctx->EKi.c[n];
|
||||
n = (n + 1) % 16;
|
||||
if (mres == sizeof(ctx->Xn)) {
|
||||
GHASH(ctx,ctx->Xn,sizeof(ctx->Xn));
|
||||
mres = 0;
|
||||
}
|
||||
#else
|
||||
c = in[i];
|
||||
out[i] = c ^ ctx->EKi.c[n];
|
||||
ctx->Xi.c[n] ^= c;
|
||||
n = (n + 1) % 16;
|
||||
mres = n = (n + 1) % 16;
|
||||
if (n == 0)
|
||||
GCM_MUL(ctx);
|
||||
#endif
|
||||
}
|
||||
|
||||
ctx->mres = n;
|
||||
ctx->mres = mres;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1365,7 +1467,7 @@ int CRYPTO_gcm128_encrypt_ctr32(GCM128_CONTEXT *ctx,
|
||||
long one;
|
||||
char little;
|
||||
} is_endian = { 1 };
|
||||
unsigned int n, ctr;
|
||||
unsigned int n, ctr, mres;
|
||||
size_t i;
|
||||
u64 mlen = ctx->len.u[1];
|
||||
void *key = ctx->key;
|
||||
@@ -1382,9 +1484,23 @@ int CRYPTO_gcm128_encrypt_ctr32(GCM128_CONTEXT *ctx,
|
||||
return -1;
|
||||
ctx->len.u[1] = mlen;
|
||||
|
||||
mres = ctx->mres;
|
||||
|
||||
if (ctx->ares) {
|
||||
/* First call to encrypt finalizes GHASH(AAD) */
|
||||
#if defined(GHASH)
|
||||
if (len == 0) {
|
||||
GCM_MUL(ctx);
|
||||
ctx->ares = 0;
|
||||
return 0;
|
||||
}
|
||||
memcpy(ctx->Xn, ctx->Xi.c, sizeof(ctx->Xi));
|
||||
ctx->Xi.u[0] = 0;
|
||||
ctx->Xi.u[1] = 0;
|
||||
mres = sizeof(ctx->Xi);
|
||||
#else
|
||||
GCM_MUL(ctx);
|
||||
#endif
|
||||
ctx->ares = 0;
|
||||
}
|
||||
|
||||
@@ -1397,30 +1513,51 @@ int CRYPTO_gcm128_encrypt_ctr32(GCM128_CONTEXT *ctx,
|
||||
else
|
||||
ctr = ctx->Yi.d[3];
|
||||
|
||||
n = ctx->mres;
|
||||
n = mres % 16;
|
||||
if (n) {
|
||||
# if defined(GHASH)
|
||||
while (n && len) {
|
||||
ctx->Xn[mres++] = *(out++) = *(in++) ^ ctx->EKi.c[n];
|
||||
--len;
|
||||
n = (n + 1) % 16;
|
||||
}
|
||||
if (n == 0) {
|
||||
GHASH(ctx, ctx->Xn, mres);
|
||||
mres = 0;
|
||||
} else {
|
||||
ctx->mres = mres;
|
||||
return 0;
|
||||
}
|
||||
# else
|
||||
while (n && len) {
|
||||
ctx->Xi.c[n] ^= *(out++) = *(in++) ^ ctx->EKi.c[n];
|
||||
--len;
|
||||
n = (n + 1) % 16;
|
||||
}
|
||||
if (n == 0)
|
||||
if (n == 0) {
|
||||
GCM_MUL(ctx);
|
||||
else {
|
||||
mres = 0;
|
||||
} else {
|
||||
ctx->mres = n;
|
||||
return 0;
|
||||
}
|
||||
# endif
|
||||
}
|
||||
# if defined(GHASH) && defined(GHASH_CHUNK)
|
||||
# if defined(GHASH)
|
||||
if (len >= 16 && mres) {
|
||||
GHASH(ctx, ctx->Xn, mres);
|
||||
mres = 0;
|
||||
}
|
||||
# if defined(GHASH_CHUNK)
|
||||
while (len >= GHASH_CHUNK) {
|
||||
(*stream) (in, out, GHASH_CHUNK / 16, key, ctx->Yi.c);
|
||||
ctr += GHASH_CHUNK / 16;
|
||||
if (is_endian.little)
|
||||
# ifdef BSWAP4
|
||||
# ifdef BSWAP4
|
||||
ctx->Yi.d[3] = BSWAP4(ctr);
|
||||
# else
|
||||
# else
|
||||
PUTU32(ctx->Yi.c + 12, ctr);
|
||||
# endif
|
||||
# endif
|
||||
else
|
||||
ctx->Yi.d[3] = ctr;
|
||||
GHASH(ctx, out, GHASH_CHUNK);
|
||||
@@ -1428,6 +1565,7 @@ int CRYPTO_gcm128_encrypt_ctr32(GCM128_CONTEXT *ctx,
|
||||
in += GHASH_CHUNK;
|
||||
len -= GHASH_CHUNK;
|
||||
}
|
||||
# endif
|
||||
# endif
|
||||
if ((i = (len & (size_t)-16))) {
|
||||
size_t j = i / 16;
|
||||
@@ -1468,12 +1606,16 @@ int CRYPTO_gcm128_encrypt_ctr32(GCM128_CONTEXT *ctx,
|
||||
else
|
||||
ctx->Yi.d[3] = ctr;
|
||||
while (len--) {
|
||||
ctx->Xi.c[n] ^= out[n] = in[n] ^ ctx->EKi.c[n];
|
||||
# if defined(GHASH)
|
||||
ctx->Xn[mres++] = out[n] = in[n] ^ ctx->EKi.c[n];
|
||||
# else
|
||||
ctx->Xi.c[mres++] ^= out[n] = in[n] ^ ctx->EKi.c[n];
|
||||
# endif
|
||||
++n;
|
||||
}
|
||||
}
|
||||
|
||||
ctx->mres = n;
|
||||
ctx->mres = mres;
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
@@ -1489,7 +1631,7 @@ int CRYPTO_gcm128_decrypt_ctr32(GCM128_CONTEXT *ctx,
|
||||
long one;
|
||||
char little;
|
||||
} is_endian = { 1 };
|
||||
unsigned int n, ctr;
|
||||
unsigned int n, ctr, mres;
|
||||
size_t i;
|
||||
u64 mlen = ctx->len.u[1];
|
||||
void *key = ctx->key;
|
||||
@@ -1506,9 +1648,23 @@ int CRYPTO_gcm128_decrypt_ctr32(GCM128_CONTEXT *ctx,
|
||||
return -1;
|
||||
ctx->len.u[1] = mlen;
|
||||
|
||||
mres = ctx->mres;
|
||||
|
||||
if (ctx->ares) {
|
||||
/* First call to decrypt finalizes GHASH(AAD) */
|
||||
# if defined(GHASH)
|
||||
if (len == 0) {
|
||||
GCM_MUL(ctx);
|
||||
ctx->ares = 0;
|
||||
return 0;
|
||||
}
|
||||
memcpy(ctx->Xn, ctx->Xi.c, sizeof(ctx->Xi));
|
||||
ctx->Xi.u[0] = 0;
|
||||
ctx->Xi.u[1] = 0;
|
||||
mres = sizeof(ctx->Xi);
|
||||
# else
|
||||
GCM_MUL(ctx);
|
||||
# endif
|
||||
ctx->ares = 0;
|
||||
}
|
||||
|
||||
@@ -1521,8 +1677,22 @@ int CRYPTO_gcm128_decrypt_ctr32(GCM128_CONTEXT *ctx,
|
||||
else
|
||||
ctr = ctx->Yi.d[3];
|
||||
|
||||
n = ctx->mres;
|
||||
n = mres % 16;
|
||||
if (n) {
|
||||
# if defined(GHASH)
|
||||
while (n && len) {
|
||||
*(out++) = (ctx->Xn[mres++] = *(in++)) ^ ctx->EKi.c[n];
|
||||
--len;
|
||||
n = (n + 1) % 16;
|
||||
}
|
||||
if (n == 0) {
|
||||
GHASH(ctx, ctx->Xn, mres);
|
||||
mres = 0;
|
||||
} else {
|
||||
ctx->mres = mres;
|
||||
return 0;
|
||||
}
|
||||
# else
|
||||
while (n && len) {
|
||||
u8 c = *(in++);
|
||||
*(out++) = c ^ ctx->EKi.c[n];
|
||||
@@ -1530,30 +1700,38 @@ int CRYPTO_gcm128_decrypt_ctr32(GCM128_CONTEXT *ctx,
|
||||
--len;
|
||||
n = (n + 1) % 16;
|
||||
}
|
||||
if (n == 0)
|
||||
if (n == 0) {
|
||||
GCM_MUL(ctx);
|
||||
else {
|
||||
mres = 0;
|
||||
} else {
|
||||
ctx->mres = n;
|
||||
return 0;
|
||||
}
|
||||
# endif
|
||||
}
|
||||
# if defined(GHASH) && defined(GHASH_CHUNK)
|
||||
# if defined(GHASH)
|
||||
if (len >= 16 && mres) {
|
||||
GHASH(ctx, ctx->Xn, mres);
|
||||
mres = 0;
|
||||
}
|
||||
# if defined(GHASH_CHUNK)
|
||||
while (len >= GHASH_CHUNK) {
|
||||
GHASH(ctx, in, GHASH_CHUNK);
|
||||
(*stream) (in, out, GHASH_CHUNK / 16, key, ctx->Yi.c);
|
||||
ctr += GHASH_CHUNK / 16;
|
||||
if (is_endian.little)
|
||||
# ifdef BSWAP4
|
||||
# ifdef BSWAP4
|
||||
ctx->Yi.d[3] = BSWAP4(ctr);
|
||||
# else
|
||||
# else
|
||||
PUTU32(ctx->Yi.c + 12, ctr);
|
||||
# endif
|
||||
# endif
|
||||
else
|
||||
ctx->Yi.d[3] = ctr;
|
||||
out += GHASH_CHUNK;
|
||||
in += GHASH_CHUNK;
|
||||
len -= GHASH_CHUNK;
|
||||
}
|
||||
# endif
|
||||
# endif
|
||||
if ((i = (len & (size_t)-16))) {
|
||||
size_t j = i / 16;
|
||||
@@ -1597,14 +1775,18 @@ int CRYPTO_gcm128_decrypt_ctr32(GCM128_CONTEXT *ctx,
|
||||
else
|
||||
ctx->Yi.d[3] = ctr;
|
||||
while (len--) {
|
||||
# if defined(GHASH)
|
||||
out[n] = (ctx->Xn[mres++] = in[n]) ^ ctx->EKi.c[n];
|
||||
# else
|
||||
u8 c = in[n];
|
||||
ctx->Xi.c[n] ^= c;
|
||||
ctx->Xi.c[mres++] ^= c;
|
||||
out[n] = c ^ ctx->EKi.c[n];
|
||||
# endif
|
||||
++n;
|
||||
}
|
||||
}
|
||||
|
||||
ctx->mres = n;
|
||||
ctx->mres = mres;
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
@@ -1620,10 +1802,32 @@ int CRYPTO_gcm128_finish(GCM128_CONTEXT *ctx, const unsigned char *tag,
|
||||
u64 clen = ctx->len.u[1] << 3;
|
||||
#ifdef GCM_FUNCREF_4BIT
|
||||
void (*gcm_gmult_p) (u64 Xi[2], const u128 Htable[16]) = ctx->gmult;
|
||||
# if defined(GHASH) && !defined(OPENSSL_SMALL_FOOTPRINT)
|
||||
void (*gcm_ghash_p) (u64 Xi[2], const u128 Htable[16],
|
||||
const u8 *inp, size_t len) = ctx->ghash;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(GHASH) && !defined(OPENSSL_SMALL_FOOTPRINT)
|
||||
u128 bitlen;
|
||||
unsigned int mres = ctx->mres;
|
||||
|
||||
if (mres) {
|
||||
unsigned blocks = (mres + 15) & -16;
|
||||
|
||||
memset(ctx->Xn + mres, 0, blocks - mres);
|
||||
mres = blocks;
|
||||
if (mres == sizeof(ctx->Xn)) {
|
||||
GHASH(ctx, ctx->Xn, mres);
|
||||
mres = 0;
|
||||
}
|
||||
} else if (ctx->ares) {
|
||||
GCM_MUL(ctx);
|
||||
}
|
||||
#else
|
||||
if (ctx->mres || ctx->ares)
|
||||
GCM_MUL(ctx);
|
||||
#endif
|
||||
|
||||
if (is_endian.little) {
|
||||
#ifdef BSWAP8
|
||||
@@ -1640,9 +1844,17 @@ int CRYPTO_gcm128_finish(GCM128_CONTEXT *ctx, const unsigned char *tag,
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(GHASH) && !defined(OPENSSL_SMALL_FOOTPRINT)
|
||||
bitlen.hi = alen;
|
||||
bitlen.lo = clen;
|
||||
memcpy(ctx->Xn + mres, &bitlen, sizeof(bitlen));
|
||||
mres += sizeof(bitlen);
|
||||
GHASH(ctx, ctx->Xn, mres);
|
||||
#else
|
||||
ctx->Xi.u[0] ^= alen;
|
||||
ctx->Xi.u[1] ^= clen;
|
||||
GCM_MUL(ctx);
|
||||
#endif
|
||||
|
||||
ctx->Xi.u[0] ^= ctx->EK0.u[0];
|
||||
ctx->Xi.u[1] ^= ctx->EK0.u[1];
|
||||
|
||||
@@ -128,6 +128,9 @@ struct gcm128_context {
|
||||
unsigned int mres, ares;
|
||||
block128_f block;
|
||||
void *key;
|
||||
#if !defined(OPENSSL_SMALL_FOOTPRINT)
|
||||
unsigned char Xn[48];
|
||||
#endif
|
||||
};
|
||||
|
||||
struct xts128_context {
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
# PPC970 7.00/+114% 3.51/+205%
|
||||
# POWER7 3.75/+260% 1.93/+100%
|
||||
# POWER8 - 2.03/+200%
|
||||
# POWER9 - 1.56/+150%
|
||||
# POWER9 - 2.00/+150%
|
||||
#
|
||||
# Do we need floating-point implementation for PPC? Results presented
|
||||
# in poly1305_ieee754.c are tricky to compare to, because they are for
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
# PPC970 6.03/+80%
|
||||
# POWER7 3.50/+30%
|
||||
# POWER8 3.75/+10%
|
||||
# POWER9 2.80/+12%
|
||||
|
||||
$flavour = shift;
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
* POWER6 4.92
|
||||
* POWER7 4.50
|
||||
* POWER8 4.10
|
||||
* POWER9 3.14
|
||||
*
|
||||
* z10 11.2
|
||||
* z196+ 7.30
|
||||
|
||||
+41
-29
@@ -15,6 +15,7 @@
|
||||
#include "rand_lcl.h"
|
||||
#include "internal/rand_int.h"
|
||||
#include <stdio.h>
|
||||
#include "internal/dso.h"
|
||||
#if defined(__linux)
|
||||
# include <sys/syscall.h>
|
||||
#endif
|
||||
@@ -23,7 +24,7 @@
|
||||
# include <sys/sysctl.h>
|
||||
# include <sys/param.h>
|
||||
#endif
|
||||
#if defined(__OpenBSD__)
|
||||
#if defined(__OpenBSD__) || defined(__NetBSD__)
|
||||
# include <sys/param.h>
|
||||
#endif
|
||||
#ifdef OPENSSL_SYS_UNIX
|
||||
@@ -163,20 +164,6 @@ size_t rand_pool_acquire_entropy(RAND_POOL *pool)
|
||||
# error "Seeding uses urandom but DEVRANDOM is not configured"
|
||||
# endif
|
||||
|
||||
# if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
|
||||
# if __GLIBC_PREREQ(2, 25)
|
||||
# define OPENSSL_HAVE_GETRANDOM
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# if (defined(__FreeBSD__) && __FreeBSD_version >= 1200061)
|
||||
# define OPENSSL_HAVE_GETRANDOM
|
||||
# endif
|
||||
|
||||
# if defined(OPENSSL_HAVE_GETRANDOM)
|
||||
# include <sys/random.h>
|
||||
# endif
|
||||
|
||||
# if defined(OPENSSL_RAND_SEED_OS)
|
||||
# if !defined(DEVRANDOM)
|
||||
# error "OS seeding requires DEVRANDOM to be configured"
|
||||
@@ -189,7 +176,7 @@ size_t rand_pool_acquire_entropy(RAND_POOL *pool)
|
||||
# error "librandom not (yet) supported"
|
||||
# endif
|
||||
|
||||
# if defined(__FreeBSD__) && defined(KERN_ARND)
|
||||
# if (defined(__FreeBSD__) || defined(__NetBSD__)) && defined(KERN_ARND)
|
||||
/*
|
||||
* sysctl_random(): Use sysctl() to read a random number from the kernel
|
||||
* Returns the size on success, 0 on failure.
|
||||
@@ -201,14 +188,25 @@ static size_t sysctl_random(char *buf, size_t buflen)
|
||||
size_t len;
|
||||
|
||||
/*
|
||||
* Old implementations returned longs, newer versions support variable
|
||||
* sizes up to 256 byte. The code below would not work properly when
|
||||
* the sysctl returns long and we want to request something not a multiple
|
||||
* of longs, which should never be the case.
|
||||
* On FreeBSD old implementations returned longs, newer versions support
|
||||
* variable sizes up to 256 byte. The code below would not work properly
|
||||
* when the sysctl returns long and we want to request something not a
|
||||
* multiple of longs, which should never be the case.
|
||||
*/
|
||||
if (!ossl_assert(buflen % sizeof(long) == 0))
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* On NetBSD before 4.0 KERN_ARND was an alias for KERN_URND, and only
|
||||
* filled in an int, leaving the rest uninitialized. Since NetBSD 4.0
|
||||
* it returns a variable number of bytes with the current version supporting
|
||||
* up to 256 bytes.
|
||||
* Just return an error on older NetBSD versions.
|
||||
*/
|
||||
#if defined(__NetBSD__) && __NetBSD_Version__ < 400000000
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_ARND;
|
||||
|
||||
@@ -231,23 +229,37 @@ static size_t sysctl_random(char *buf, size_t buflen)
|
||||
*/
|
||||
int syscall_random(void *buf, size_t buflen)
|
||||
{
|
||||
# if defined(OPENSSL_HAVE_GETRANDOM)
|
||||
return (int)getrandom(buf, buflen, 0);
|
||||
# endif
|
||||
union {
|
||||
void *p;
|
||||
int (*f)(void *buffer, size_t length);
|
||||
} p_getentropy;
|
||||
|
||||
/*
|
||||
* Do runtime detection to find getentropy().
|
||||
*
|
||||
* We could cache the result of the lookup, but we normally don't
|
||||
* call this function often.
|
||||
*
|
||||
* Known OSs that should support this:
|
||||
* - Darwin since 16 (OSX 10.12, IOS 10.0).
|
||||
* - Solaris since 11.3
|
||||
* - OpenBSD since 5.6
|
||||
* - Linux since 3.17 with glibc 2.25
|
||||
* - FreeBSD since 12.0 (1200061)
|
||||
*/
|
||||
p_getentropy.p = DSO_global_lookup("getentropy");
|
||||
if (p_getentropy.p != NULL)
|
||||
return p_getentropy.f(buf, buflen) == 0 ? buflen : 0;
|
||||
|
||||
/* Linux supports this since version 3.17 */
|
||||
# if defined(__linux) && defined(SYS_getrandom)
|
||||
return (int)syscall(SYS_getrandom, buf, buflen, 0);
|
||||
# endif
|
||||
|
||||
# if defined(__FreeBSD__) && defined(KERN_ARND)
|
||||
# if (defined(__FreeBSD__) || defined(__NetBSD__)) && defined(KERN_ARND)
|
||||
return (int)sysctl_random(buf, buflen);
|
||||
# endif
|
||||
|
||||
/* Supported since OpenBSD 5.6 */
|
||||
# if defined(__OpenBSD__) && OpenBSD >= 201411
|
||||
return getentropy(buf, buflen);
|
||||
# endif
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
# PPC970/G5 14.6/+120%
|
||||
# POWER7 10.3/+100%
|
||||
# POWER8 11.5/+85%
|
||||
# POWER9 7.2/+45%
|
||||
# POWER9 9.4/+45%
|
||||
#
|
||||
# (*) Corresponds to SHA3-256. Percentage after slash is improvement
|
||||
# over gcc-4.x-generated KECCAK_1X_ALT code. Newer compilers do
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
# buffer for r=1088, which matches SHA3-256. This is 17% better than
|
||||
# scalar PPC64 code. It probably should be noted that if POWER8's
|
||||
# successor can achieve higher scalar instruction issue rate, then
|
||||
# this module will loose... And it does on POWER9 with 8.8 vs. 7.2.
|
||||
# this module will loose... And it does on POWER9 with 12.0 vs. 9.4.
|
||||
|
||||
$flavour = shift;
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@
|
||||
# build of sha512-ppc.pl, presented for reference.
|
||||
#
|
||||
# POWER8 POWER9
|
||||
# SHA256 9.9 [15.8] 9.2 [9.3]
|
||||
# SHA512 6.3 [10.3] 5.8 [5.9]
|
||||
# SHA256 9.7 [15.8] 11.2 [12.5]
|
||||
# SHA512 6.1 [10.3] 7.0 [7.9]
|
||||
|
||||
$flavour=shift;
|
||||
$output =shift;
|
||||
@@ -79,7 +79,8 @@ if ($output =~ /512/) {
|
||||
}
|
||||
|
||||
$func="sha${bits}_block_p8";
|
||||
$FRAME=8*$SIZE_T;
|
||||
$LOCALS=8*$SIZE_T+8*16;
|
||||
$FRAME=$LOCALS+9*16+6*$SIZE_T;
|
||||
|
||||
$sp ="r1";
|
||||
$toc="r2";
|
||||
@@ -91,16 +92,17 @@ $idx="r7";
|
||||
$lrsave="r8";
|
||||
$offload="r11";
|
||||
$vrsave="r12";
|
||||
($x00,$x10,$x20,$x30,$x40,$x50,$x60,$x70)=map("r$_",(0,10,26..31));
|
||||
$x00=0 if ($flavour =~ /osx/);
|
||||
@I = ($x00,$x10,$x20,$x30,$x40,$x50,$x60,$x70)=map("r$_",(0,10,26..31));
|
||||
$x00=0 if ($flavour =~ /osx/);
|
||||
|
||||
@V=($A,$B,$C,$D,$E,$F,$G,$H)=map("v$_",(0..7));
|
||||
@X=map("v$_",(8..23));
|
||||
($Ki,$Func,$S0,$S1,$s0,$s1,$lemask)=map("v$_",(24..31));
|
||||
@X=map("v$_",(8..19,24..27));
|
||||
($Ki,$Func,$Sigma,$lemask)=map("v$_",(28..31));
|
||||
|
||||
sub ROUND {
|
||||
my ($i,$a,$b,$c,$d,$e,$f,$g,$h)=@_;
|
||||
my $j=($i+1)%16;
|
||||
my $k=($i+2)%8;
|
||||
|
||||
$code.=<<___ if ($i<15 && ($i%(16/$SZ))==(16/$SZ-1));
|
||||
lvx_u @X[$i+1],0,$inp ; load X[i] in advance
|
||||
@@ -112,26 +114,30 @@ ___
|
||||
$code.=<<___ if ($LENDIAN && $i<16 && ($i%(16/$SZ))==0);
|
||||
vperm @X[$i],@X[$i],@X[$i],$lemask
|
||||
___
|
||||
$code.=<<___ if ($i>=15);
|
||||
vshasigma${sz} $Sigma,@X[($j+1)%16],0,0
|
||||
vaddu${sz}m @X[$j],@X[$j],$Sigma
|
||||
vshasigma${sz} $Sigma,@X[($j+14)%16],0,15
|
||||
vaddu${sz}m @X[$j],@X[$j],$Sigma
|
||||
vaddu${sz}m @X[$j],@X[$j],@X[($j+9)%16]
|
||||
___
|
||||
$code.=<<___;
|
||||
`"vshasigma${sz} $s0,@X[($j+1)%16],0,0" if ($i>=15)`
|
||||
vsel $Func,$g,$f,$e ; Ch(e,f,g)
|
||||
vshasigma${sz} $S1,$e,1,15 ; Sigma1(e)
|
||||
vaddu${sz}m $h,$h,@X[$i%16] ; h+=X[i]
|
||||
vshasigma${sz} $S0,$a,1,0 ; Sigma0(a)
|
||||
`"vshasigma${sz} $s1,@X[($j+14)%16],0,15" if ($i>=15)`
|
||||
vaddu${sz}m $h,$h,$Func ; h+=Ch(e,f,g)
|
||||
vxor $Func,$a,$b
|
||||
`"vaddu${sz}m @X[$j],@X[$j],@X[($j+9)%16]" if ($i>=15)`
|
||||
vaddu${sz}m $h,$h,$S1 ; h+=Sigma1(e)
|
||||
vsel $Func,$b,$c,$Func ; Maj(a,b,c)
|
||||
vsel $Func,$g,$f,$e ; Ch(e,f,g)
|
||||
vaddu${sz}m $g,$g,$Ki ; future h+=K[i]
|
||||
vaddu${sz}m $h,$h,$Func ; h+=Ch(e,f,g)
|
||||
vshasigma${sz} $Sigma,$e,1,15 ; Sigma1(e)
|
||||
vaddu${sz}m $h,$h,$Sigma ; h+=Sigma1(e)
|
||||
vxor $Func,$a,$b
|
||||
vsel $Func,$b,$c,$Func ; Maj(a,b,c)
|
||||
vaddu${sz}m $d,$d,$h ; d+=h
|
||||
vaddu${sz}m $S0,$S0,$Func ; Sigma0(a)+Maj(a,b,c)
|
||||
`"vaddu${sz}m @X[$j],@X[$j],$s0" if ($i>=15)`
|
||||
lvx $Ki,$idx,$Tbl ; load next K[i]
|
||||
addi $idx,$idx,16
|
||||
vaddu${sz}m $h,$h,$S0 ; h+=Sigma0(a)+Maj(a,b,c)
|
||||
`"vaddu${sz}m @X[$j],@X[$j],$s1" if ($i>=15)`
|
||||
vshasigma${sz} $Sigma,$a,1,0 ; Sigma0(a)
|
||||
vaddu${sz}m $Sigma,$Sigma,$Func ; Sigma0(a)+Maj(a,b,c)
|
||||
vaddu${sz}m $h,$h,$Sigma ; h+=Sigma0(a)+Maj(a,b,c)
|
||||
lvx $Ki,@I[$k],$idx ; load next K[i]
|
||||
___
|
||||
$code.=<<___ if ($k == 7);
|
||||
addi $idx,$idx,0x80
|
||||
___
|
||||
}
|
||||
|
||||
@@ -142,21 +148,13 @@ $code=<<___;
|
||||
.globl $func
|
||||
.align 6
|
||||
$func:
|
||||
$STU $sp,-`($FRAME+21*16+6*$SIZE_T)`($sp)
|
||||
$STU $sp,-$FRAME($sp)
|
||||
mflr $lrsave
|
||||
li r10,`$FRAME+8*16+15`
|
||||
li r11,`$FRAME+8*16+31`
|
||||
stvx v20,r10,$sp # ABI says so
|
||||
li r10,`$LOCALS+15`
|
||||
li r11,`$LOCALS+31`
|
||||
stvx v24,r10,$sp # ABI says so
|
||||
addi r10,r10,32
|
||||
mfspr $vrsave,256
|
||||
stvx v21,r11,$sp
|
||||
addi r11,r11,32
|
||||
stvx v22,r10,$sp
|
||||
addi r10,r10,32
|
||||
stvx v23,r11,$sp
|
||||
addi r11,r11,32
|
||||
stvx v24,r10,$sp
|
||||
addi r10,r10,32
|
||||
stvx v25,r11,$sp
|
||||
addi r11,r11,32
|
||||
stvx v26,r10,$sp
|
||||
@@ -169,26 +167,26 @@ $func:
|
||||
addi r11,r11,32
|
||||
stvx v30,r10,$sp
|
||||
stvx v31,r11,$sp
|
||||
li r11,-1
|
||||
stw $vrsave,`$FRAME+21*16-4`($sp) # save vrsave
|
||||
li r11,-4096+255
|
||||
stw $vrsave,`$FRAME+6*$SIZE_T-4`($sp) # save vrsave
|
||||
li $x10,0x10
|
||||
$PUSH r26,`$FRAME+21*16+0*$SIZE_T`($sp)
|
||||
$PUSH r26,`$FRAME-6*$SIZE_T`($sp)
|
||||
li $x20,0x20
|
||||
$PUSH r27,`$FRAME+21*16+1*$SIZE_T`($sp)
|
||||
$PUSH r27,`$FRAME-5*$SIZE_T`($sp)
|
||||
li $x30,0x30
|
||||
$PUSH r28,`$FRAME+21*16+2*$SIZE_T`($sp)
|
||||
$PUSH r28,`$FRAME-4*$SIZE_T`($sp)
|
||||
li $x40,0x40
|
||||
$PUSH r29,`$FRAME+21*16+3*$SIZE_T`($sp)
|
||||
$PUSH r29,`$FRAME-3*$SIZE_T`($sp)
|
||||
li $x50,0x50
|
||||
$PUSH r30,`$FRAME+21*16+4*$SIZE_T`($sp)
|
||||
$PUSH r30,`$FRAME-2*$SIZE_T`($sp)
|
||||
li $x60,0x60
|
||||
$PUSH r31,`$FRAME+21*16+5*$SIZE_T`($sp)
|
||||
$PUSH r31,`$FRAME-1*$SIZE_T`($sp)
|
||||
li $x70,0x70
|
||||
$PUSH $lrsave,`$FRAME+21*16+6*$SIZE_T+$LRSAVE`($sp)
|
||||
$PUSH $lrsave,`$FRAME+$LRSAVE`($sp)
|
||||
mtspr 256,r11
|
||||
|
||||
bl LPICmeup
|
||||
addi $offload,$sp,$FRAME+15
|
||||
addi $offload,$sp,`8*$SIZE_T+15`
|
||||
___
|
||||
$code.=<<___ if ($LENDIAN);
|
||||
li $idx,8
|
||||
@@ -222,9 +220,9 @@ $code.=<<___;
|
||||
.align 5
|
||||
Loop:
|
||||
lvx $Ki,$x00,$Tbl
|
||||
li $idx,16
|
||||
lvx_u @X[0],0,$inp
|
||||
addi $inp,$inp,16
|
||||
mr $idx,$Tbl # copy $Tbl
|
||||
stvx $A,$x00,$offload # offload $A-$H
|
||||
stvx $B,$x10,$offload
|
||||
stvx $C,$x20,$offload
|
||||
@@ -234,8 +232,7 @@ Loop:
|
||||
stvx $G,$x60,$offload
|
||||
stvx $H,$x70,$offload
|
||||
vaddu${sz}m $H,$H,$Ki # h+K[i]
|
||||
lvx $Ki,$idx,$Tbl
|
||||
addi $idx,$idx,16
|
||||
lvx $Ki,$x10,$Tbl
|
||||
___
|
||||
for ($i=0;$i<16;$i++) { &ROUND($i,@V); unshift(@V,pop(@V)); }
|
||||
$code.=<<___;
|
||||
@@ -268,10 +265,9 @@ $code.=<<___;
|
||||
bne Loop
|
||||
___
|
||||
$code.=<<___ if ($SZ==4);
|
||||
lvx @X[0],$idx,$Tbl
|
||||
addi $idx,$idx,16
|
||||
lvx @X[0],$x20,$idx
|
||||
vperm $A,$A,$B,$Ki # pack the answer
|
||||
lvx @X[1],$idx,$Tbl
|
||||
lvx @X[1],$x30,$idx
|
||||
vperm $E,$E,$F,$Ki
|
||||
vperm $A,$A,$C,@X[0]
|
||||
vperm $E,$E,$G,@X[0]
|
||||
@@ -291,19 +287,11 @@ $code.=<<___ if ($SZ==8);
|
||||
stvx_u $G,$x30,$ctx
|
||||
___
|
||||
$code.=<<___;
|
||||
li r10,`$FRAME+8*16+15`
|
||||
li r10,`$LOCALS+15`
|
||||
mtlr $lrsave
|
||||
li r11,`$FRAME+8*16+31`
|
||||
li r11,`$LOCALS+31`
|
||||
mtspr 256,$vrsave
|
||||
lvx v20,r10,$sp # ABI says so
|
||||
addi r10,r10,32
|
||||
lvx v21,r11,$sp
|
||||
addi r11,r11,32
|
||||
lvx v22,r10,$sp
|
||||
addi r10,r10,32
|
||||
lvx v23,r11,$sp
|
||||
addi r11,r11,32
|
||||
lvx v24,r10,$sp
|
||||
lvx v24,r10,$sp # ABI says so
|
||||
addi r10,r10,32
|
||||
lvx v25,r11,$sp
|
||||
addi r11,r11,32
|
||||
@@ -317,13 +305,13 @@ $code.=<<___;
|
||||
addi r11,r11,32
|
||||
lvx v30,r10,$sp
|
||||
lvx v31,r11,$sp
|
||||
$POP r26,`$FRAME+21*16+0*$SIZE_T`($sp)
|
||||
$POP r27,`$FRAME+21*16+1*$SIZE_T`($sp)
|
||||
$POP r28,`$FRAME+21*16+2*$SIZE_T`($sp)
|
||||
$POP r29,`$FRAME+21*16+3*$SIZE_T`($sp)
|
||||
$POP r30,`$FRAME+21*16+4*$SIZE_T`($sp)
|
||||
$POP r31,`$FRAME+21*16+5*$SIZE_T`($sp)
|
||||
addi $sp,$sp,`$FRAME+21*16+6*$SIZE_T`
|
||||
$POP r26,`$FRAME-6*$SIZE_T`($sp)
|
||||
$POP r27,`$FRAME-5*$SIZE_T`($sp)
|
||||
$POP r28,`$FRAME-4*$SIZE_T`($sp)
|
||||
$POP r29,`$FRAME-3*$SIZE_T`($sp)
|
||||
$POP r30,`$FRAME-2*$SIZE_T`($sp)
|
||||
$POP r31,`$FRAME-1*$SIZE_T`($sp)
|
||||
addi $sp,$sp,$FRAME
|
||||
blr
|
||||
.long 0
|
||||
.byte 0,12,4,1,0x80,6,3,0
|
||||
|
||||
@@ -271,6 +271,18 @@ CRYPTO_memcmp:
|
||||
xor %r10,%r10
|
||||
cmp \$0,$arg3
|
||||
je .Lno_data
|
||||
cmp \$16,$arg3
|
||||
jne .Loop_cmp
|
||||
mov ($arg1),%r10
|
||||
mov 8($arg1),%r11
|
||||
mov \$1,$arg3
|
||||
xor ($arg2),%r10
|
||||
xor 8($arg2),%r11
|
||||
or %r11,%r10
|
||||
cmovnz $arg3,%rax
|
||||
ret
|
||||
|
||||
.align 16
|
||||
.Loop_cmp:
|
||||
mov ($arg1),%r10b
|
||||
lea 1($arg1),$arg1
|
||||
|
||||
@@ -121,6 +121,8 @@ returned as a newly allocated B<ECDSA_SIG> structure (or NULL on error).
|
||||
|
||||
=head1 RETURN VALUES
|
||||
|
||||
ECDSA_SIG_new() returns NULL if the allocation fails.
|
||||
|
||||
ECDSA_SIG_set0() returns 1 on success or 0 on failure.
|
||||
|
||||
ECDSA_SIG_get0_r() and ECDSA_SIG_get0_s() return the corresponding value,
|
||||
|
||||
+4
-4
@@ -171,7 +171,7 @@ static SSL_CIPHER ssl3_ciphers[] = {
|
||||
SSL_aRSA,
|
||||
SSL_3DES,
|
||||
SSL_SHA1,
|
||||
SSL3_VERSION, TLS1_VERSION,
|
||||
SSL3_VERSION, TLS1_2_VERSION,
|
||||
DTLS1_BAD_VER, DTLS1_2_VERSION,
|
||||
SSL_NOT_DEFAULT | SSL_MEDIUM | SSL_FIPS,
|
||||
SSL_HANDSHAKE_MAC_DEFAULT | TLS1_PRF,
|
||||
@@ -236,8 +236,8 @@ static SSL_CIPHER ssl3_ciphers[] = {
|
||||
SSL_aRSA,
|
||||
SSL_AES128,
|
||||
SSL_SHA1,
|
||||
SSL3_VERSION, TLS1_VERSION,
|
||||
DTLS1_BAD_VER, DTLS1_VERSION,
|
||||
SSL3_VERSION, TLS1_2_VERSION,
|
||||
DTLS1_BAD_VER, DTLS1_2_VERSION,
|
||||
SSL_HIGH | SSL_FIPS,
|
||||
SSL_HANDSHAKE_MAC_DEFAULT | TLS1_PRF,
|
||||
128,
|
||||
@@ -300,7 +300,7 @@ static SSL_CIPHER ssl3_ciphers[] = {
|
||||
SSL_aRSA,
|
||||
SSL_AES256,
|
||||
SSL_SHA1,
|
||||
SSL3_VERSION, TLS1_VERSION,
|
||||
SSL3_VERSION, TLS1_2_VERSION,
|
||||
DTLS1_BAD_VER, DTLS1_2_VERSION,
|
||||
SSL_HIGH | SSL_FIPS,
|
||||
SSL_HANDSHAKE_MAC_DEFAULT | TLS1_PRF,
|
||||
|
||||
Reference in New Issue
Block a user