OpenSSL 1.1.1-pre2
This commit is contained in:
@@ -8,6 +8,9 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file is dual-licensed and is also available under the following
|
||||
* terms:
|
||||
*
|
||||
* Copyright (c) 2004, Richard Levitte <richard@levitte.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file is dual-licensed and is also available under the following
|
||||
* terms:
|
||||
*
|
||||
* Copyright (c) 2004, Richard Levitte <richard@levitte.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file is dual-licensed and is also available under the following
|
||||
* terms:
|
||||
*
|
||||
* Copyright (c) 2004, Richard Levitte <richard@levitte.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file is dual-licensed and is also available under the following
|
||||
* terms:
|
||||
*
|
||||
* Copyright (c) 2004, Richard Levitte <richard@levitte.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file is dual-licensed and is also available under the following
|
||||
* terms:
|
||||
*
|
||||
* Copyright (c) 2004, Richard Levitte <richard@levitte.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file is dual-licensed and is also available under the following
|
||||
* terms:
|
||||
*
|
||||
* Copyright (c) 2004, Richard Levitte <richard@levitte.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
|
||||
@@ -14,9 +14,9 @@
|
||||
*
|
||||
* Optimised ANSI C code for the Rijndael cipher (now AES)
|
||||
*
|
||||
* @author Vincent Rijmen <vincent.rijmen@esat.kuleuven.ac.be>
|
||||
* @author Antoon Bosselaers <antoon.bosselaers@esat.kuleuven.ac.be>
|
||||
* @author Paulo Barreto <paulo.barreto@terra.com.br>
|
||||
* @author Vincent Rijmen
|
||||
* @author Antoon Bosselaers
|
||||
* @author Paulo Barreto
|
||||
*
|
||||
* This code is hereby placed in the public domain.
|
||||
*
|
||||
|
||||
+11
-12
@@ -7,6 +7,14 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is experimental x86[_64] derivative. It assumes little-endian
|
||||
* byte order and expects CPU to sustain unaligned memory references.
|
||||
* It is used as playground for cache-time attack mitigations and
|
||||
* serves as reference C implementation for x86[_64] as well as some
|
||||
* other assembly modules.
|
||||
*/
|
||||
|
||||
/**
|
||||
* rijndael-alg-fst.c
|
||||
*
|
||||
@@ -14,9 +22,9 @@
|
||||
*
|
||||
* Optimised ANSI C code for the Rijndael cipher (now AES)
|
||||
*
|
||||
* @author Vincent Rijmen <vincent.rijmen@esat.kuleuven.ac.be>
|
||||
* @author Antoon Bosselaers <antoon.bosselaers@esat.kuleuven.ac.be>
|
||||
* @author Paulo Barreto <paulo.barreto@terra.com.br>
|
||||
* @author Vincent Rijmen
|
||||
* @author Antoon Bosselaers
|
||||
* @author Paulo Barreto
|
||||
*
|
||||
* This code is hereby placed in the public domain.
|
||||
*
|
||||
@@ -33,15 +41,6 @@
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is experimental x86[_64] derivative. It assumes little-endian
|
||||
* byte order and expects CPU to sustain unaligned memory references.
|
||||
* It is used as playground for cache-time attack mitigations and
|
||||
* serves as reference C implementation for x86[_64] assembler.
|
||||
*
|
||||
* <appro@fy.chalmers.se>
|
||||
*/
|
||||
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
+17
-17
@@ -8,7 +8,7 @@
|
||||
|
||||
#
|
||||
# ====================================================================
|
||||
# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
|
||||
# Written by Andy Polyakov <appro@openssl.org> for the OpenSSL
|
||||
# project. The module is, however, dual licensed under OpenSSL and
|
||||
# CRYPTOGAMS licenses depending on where you obtain it. For further
|
||||
# details see http://www.openssl.org/~appro/cryptogams/.
|
||||
@@ -39,7 +39,7 @@
|
||||
# for scaling too, I [try to] avoid the latter by favoring off-by-2
|
||||
# shifts and masking the result with 0xFF<<2 instead of "boring" 0xFF.
|
||||
#
|
||||
# As was shown by Dean Gaudet <dean@arctic.org>, the above note turned
|
||||
# As was shown by Dean Gaudet, the above note turned out to be
|
||||
# void. Performance improvement with off-by-2 shifts was observed on
|
||||
# intermediate implementation, which was spilling yet another register
|
||||
# to stack... Final offset*4 code below runs just a tad faster on P4,
|
||||
@@ -55,8 +55,8 @@
|
||||
# better performance on most recent µ-archs...
|
||||
#
|
||||
# Third version adds AES_cbc_encrypt implementation, which resulted in
|
||||
# up to 40% performance imrovement of CBC benchmark results. 40% was
|
||||
# observed on P4 core, where "overall" imrovement coefficient, i.e. if
|
||||
# up to 40% performance improvement of CBC benchmark results. 40% was
|
||||
# observed on P4 core, where "overall" improvement coefficient, i.e. if
|
||||
# compared to PIC generated by GCC and in CBC mode, was observed to be
|
||||
# as large as 4x:-) CBC performance is virtually identical to ECB now
|
||||
# and on some platforms even better, e.g. 17.6 "small" cycles/byte on
|
||||
@@ -123,7 +123,7 @@
|
||||
# words every cache-line is *guaranteed* to be accessed within ~50
|
||||
# cycles window. Why just SSE? Because it's needed on hyper-threading
|
||||
# CPU! Which is also why it's prefetched with 64 byte stride. Best
|
||||
# part is that it has no negative effect on performance:-)
|
||||
# part is that it has no negative effect on performance:-)
|
||||
#
|
||||
# Version 4.3 implements switch between compact and non-compact block
|
||||
# functions in AES_cbc_encrypt depending on how much data was asked
|
||||
@@ -159,7 +159,7 @@
|
||||
# combinations then attack becomes infeasible. This is why revised
|
||||
# AES_cbc_encrypt "dares" to switch to larger S-box when larger chunk
|
||||
# of data is to be processed in one stroke. The current size limit of
|
||||
# 512 bytes is chosen to provide same [diminishigly low] probability
|
||||
# 512 bytes is chosen to provide same [diminishingly low] probability
|
||||
# for cache-line to remain untouched in large chunk operation with
|
||||
# large S-box as for single block operation with compact S-box and
|
||||
# surely needs more careful consideration...
|
||||
@@ -171,12 +171,12 @@
|
||||
# yield execution to process performing AES just before timer fires
|
||||
# off the scheduler, immediately regain control of CPU and analyze the
|
||||
# cache state. For this attack to be efficient attacker would have to
|
||||
# effectively slow down the operation by several *orders* of magnitute,
|
||||
# effectively slow down the operation by several *orders* of magnitude,
|
||||
# by ratio of time slice to duration of handful of AES rounds, which
|
||||
# unlikely to remain unnoticed. Not to mention that this also means
|
||||
# that he would spend correspondigly more time to collect enough
|
||||
# that he would spend correspondingly more time to collect enough
|
||||
# statistical data to mount the attack. It's probably appropriate to
|
||||
# say that if adeversary reckons that this attack is beneficial and
|
||||
# say that if adversary reckons that this attack is beneficial and
|
||||
# risks to be noticed, you probably have larger problems having him
|
||||
# mere opportunity. In other words suggested code design expects you
|
||||
# to preclude/mitigate this attack by overall system security design.
|
||||
@@ -202,7 +202,7 @@ $output = pop;
|
||||
open OUT,">$output";
|
||||
*STDOUT=*OUT;
|
||||
|
||||
&asm_init($ARGV[0],"aes-586.pl",$x86only = $ARGV[$#ARGV] eq "386");
|
||||
&asm_init($ARGV[0],$x86only = $ARGV[$#ARGV] eq "386");
|
||||
&static_label("AES_Te");
|
||||
&static_label("AES_Td");
|
||||
|
||||
@@ -240,7 +240,7 @@ $small_footprint=1; # $small_footprint=1 code is ~5% slower [on
|
||||
# contention and in hope to "collect" 5% back
|
||||
# in real-life applications...
|
||||
|
||||
$vertical_spin=0; # shift "verticaly" defaults to 0, because of
|
||||
$vertical_spin=0; # shift "vertically" defaults to 0, because of
|
||||
# its proof-of-concept status...
|
||||
# Note that there is no decvert(), as well as last encryption round is
|
||||
# performed with "horizontal" shifts. This is because this "vertical"
|
||||
@@ -585,7 +585,7 @@ sub enctransform()
|
||||
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
# | mm4 | mm0 |
|
||||
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
# | s3 | s2 | s1 | s0 |
|
||||
# | s3 | s2 | s1 | s0 |
|
||||
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
# |15|14|13|12|11|10| 9| 8| 7| 6| 5| 4| 3| 2| 1| 0|
|
||||
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
@@ -805,7 +805,7 @@ sub encstep()
|
||||
|
||||
if ($i==3) { $tmp=$s[3]; &mov ($s[2],$__s1); }##%ecx
|
||||
elsif($i==2){ &movz ($tmp,&HB($s[3])); }#%ebx[2]
|
||||
else { &mov ($tmp,$s[3]);
|
||||
else { &mov ($tmp,$s[3]);
|
||||
&shr ($tmp,24) }
|
||||
&xor ($out,&DWP(1,$te,$tmp,8));
|
||||
if ($i<2) { &mov (&DWP(4+4*$i,"esp"),$out); }
|
||||
@@ -1558,7 +1558,7 @@ sub sse_deccompact()
|
||||
&pxor ("mm1","mm3"); &pxor ("mm5","mm7"); # tp4
|
||||
&pshufw ("mm3","mm1",0xb1); &pshufw ("mm7","mm5",0xb1);
|
||||
&pxor ("mm0","mm1"); &pxor ("mm4","mm5"); # ^= tp4
|
||||
&pxor ("mm0","mm3"); &pxor ("mm4","mm7"); # ^= ROTATE(tp4,16)
|
||||
&pxor ("mm0","mm3"); &pxor ("mm4","mm7"); # ^= ROTATE(tp4,16)
|
||||
|
||||
&pxor ("mm3","mm3"); &pxor ("mm7","mm7");
|
||||
&pcmpgtb("mm3","mm1"); &pcmpgtb("mm7","mm5");
|
||||
@@ -1606,7 +1606,7 @@ sub decstep()
|
||||
# no instructions are reordered, as performance appears
|
||||
# optimal... or rather that all attempts to reorder didn't
|
||||
# result in better performance [which by the way is not a
|
||||
# bit lower than ecryption].
|
||||
# bit lower than encryption].
|
||||
if($i==3) { &mov ($key,$__key); }
|
||||
else { &mov ($out,$s[0]); }
|
||||
&and ($out,0xFF);
|
||||
@@ -2028,7 +2028,7 @@ sub declast()
|
||||
{
|
||||
# stack frame layout
|
||||
# -4(%esp) # return address 0(%esp)
|
||||
# 0(%esp) # s0 backing store 4(%esp)
|
||||
# 0(%esp) # s0 backing store 4(%esp)
|
||||
# 4(%esp) # s1 backing store 8(%esp)
|
||||
# 8(%esp) # s2 backing store 12(%esp)
|
||||
# 12(%esp) # s3 backing store 16(%esp)
|
||||
@@ -2738,7 +2738,7 @@ sub enckey()
|
||||
&mov (&DWP(80,"edi"),10); # setup number of rounds
|
||||
&xor ("eax","eax");
|
||||
&jmp (&label("exit"));
|
||||
|
||||
|
||||
&set_label("12rounds");
|
||||
&mov ("eax",&DWP(0,"esi")); # copy first 6 dwords
|
||||
&mov ("ebx",&DWP(4,"esi"));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#! /usr/bin/env perl
|
||||
# Copyright 2007-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
# Copyright 2007-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the OpenSSL license (the "License"). You may not use
|
||||
# this file except in compliance with the License. You can obtain a copy
|
||||
@@ -203,7 +203,7 @@ AES_encrypt:
|
||||
adr r3,.
|
||||
#endif
|
||||
stmdb sp!,{r1,r4-r12,lr}
|
||||
#if defined(__thumb2__) || defined(__APPLE__)
|
||||
#ifdef __APPLE__
|
||||
adr $tbl,AES_Te
|
||||
#else
|
||||
sub $tbl,r3,#AES_encrypt-AES_Te @ Te
|
||||
@@ -481,7 +481,7 @@ _armv4_AES_set_encrypt_key:
|
||||
mov lr,r1 @ bits
|
||||
mov $key,r2 @ key
|
||||
|
||||
#if defined(__thumb2__) || defined(__APPLE__)
|
||||
#ifdef __APPLE__
|
||||
adr $tbl,AES_Te+1024 @ Te4
|
||||
#else
|
||||
sub $tbl,r3,#_armv4_AES_set_encrypt_key-AES_Te-1024 @ Te4
|
||||
@@ -979,7 +979,7 @@ AES_decrypt:
|
||||
adr r3,.
|
||||
#endif
|
||||
stmdb sp!,{r1,r4-r12,lr}
|
||||
#if defined(__thumb2__) || defined(__APPLE__)
|
||||
#ifdef __APPLE__
|
||||
adr $tbl,AES_Td
|
||||
#else
|
||||
sub $tbl,r3,#AES_decrypt-AES_Td @ Td
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
// https://www.openssl.org/source/license.html
|
||||
//
|
||||
// ====================================================================
|
||||
// Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
|
||||
// Written by Andy Polyakov <appro@openssl.org> for the OpenSSL
|
||||
// project. Rights for redistribution and usage in source and binary
|
||||
// forms are granted according to the OpenSSL license.
|
||||
// ====================================================================
|
||||
@@ -33,7 +33,7 @@
|
||||
// 64 bytes line size and L2 - 128 bytes...
|
||||
|
||||
.ident "aes-ia64.S, version 1.2"
|
||||
.ident "IA-64 ISA artwork by Andy Polyakov <appro@fy.chalmers.se>"
|
||||
.ident "IA-64 ISA artwork by Andy Polyakov <appro@openssl.org>"
|
||||
.explicit
|
||||
.text
|
||||
|
||||
|
||||
+66
-27
@@ -65,8 +65,8 @@ $flavour = shift || "o32"; # supported flavours are o32,n32,64,nubi32,nubi64
|
||||
|
||||
if ($flavour =~ /64|n32/i) {
|
||||
$PTR_LA="dla";
|
||||
$PTR_ADD="dadd"; # incidentally works even on n32
|
||||
$PTR_SUB="dsub"; # incidentally works even on n32
|
||||
$PTR_ADD="daddu"; # incidentally works even on n32
|
||||
$PTR_SUB="dsubu"; # incidentally works even on n32
|
||||
$PTR_INS="dins";
|
||||
$REG_S="sd";
|
||||
$REG_L="ld";
|
||||
@@ -74,8 +74,8 @@ if ($flavour =~ /64|n32/i) {
|
||||
$SZREG=8;
|
||||
} else {
|
||||
$PTR_LA="la";
|
||||
$PTR_ADD="add";
|
||||
$PTR_SUB="sub";
|
||||
$PTR_ADD="addu";
|
||||
$PTR_SUB="subu";
|
||||
$PTR_INS="ins";
|
||||
$REG_S="sw";
|
||||
$REG_L="lw";
|
||||
@@ -102,15 +102,9 @@ open STDOUT,">$output";
|
||||
my ($MSB,$LSB)=(0,3); # automatically converted to little-endian
|
||||
|
||||
$code.=<<___;
|
||||
#include "mips_arch.h"
|
||||
|
||||
.text
|
||||
#ifdef OPENSSL_FIPSCANISTER
|
||||
# include <openssl/fipssyms.h>
|
||||
#endif
|
||||
|
||||
#if defined(__mips_smartmips) && !defined(_MIPS_ARCH_MIPS32R2)
|
||||
#define _MIPS_ARCH_MIPS32R2
|
||||
#endif
|
||||
|
||||
#if !defined(__mips_eabi) && (!defined(__vxworks) || defined(__pic__))
|
||||
.option pic2
|
||||
#endif
|
||||
@@ -126,7 +120,7 @@ my ($i0,$i1,$i2,$i3)=($at,$t0,$t1,$t2);
|
||||
my ($t0,$t1,$t2,$t3,$t4,$t5,$t6,$t7,$t8,$t9,$t10,$t11) = map("\$$_",(12..23));
|
||||
my ($key0,$cnt)=($gp,$fp);
|
||||
|
||||
# instuction ordering is "stolen" from output from MIPSpro assembler
|
||||
# instruction ordering is "stolen" from output from MIPSpro assembler
|
||||
# invoked with -mips3 -O3 arguments...
|
||||
$code.=<<___;
|
||||
.align 5
|
||||
@@ -146,7 +140,7 @@ _mips_AES_encrypt:
|
||||
xor $s2,$t2
|
||||
xor $s3,$t3
|
||||
|
||||
sub $cnt,1
|
||||
subu $cnt,1
|
||||
#if defined(__mips_smartmips)
|
||||
ext $i0,$s1,16,8
|
||||
.Loop_enc:
|
||||
@@ -218,7 +212,7 @@ _mips_AES_encrypt:
|
||||
xor $t2,$t6
|
||||
xor $t3,$t7
|
||||
|
||||
sub $cnt,1
|
||||
subu $cnt,1
|
||||
$PTR_ADD $key0,16
|
||||
xor $s0,$t0
|
||||
xor $s1,$t1
|
||||
@@ -409,7 +403,7 @@ _mips_AES_encrypt:
|
||||
xor $t2,$t6
|
||||
xor $t3,$t7
|
||||
|
||||
sub $cnt,1
|
||||
subu $cnt,1
|
||||
$PTR_ADD $key0,16
|
||||
xor $s0,$t0
|
||||
xor $s1,$t1
|
||||
@@ -657,6 +651,12 @@ $code.=<<___;
|
||||
.set reorder
|
||||
$PTR_LA $Tbl,AES_Te # PIC-ified 'load address'
|
||||
|
||||
#if defined(_MIPS_ARCH_MIPS32R6) || defined(_MIPS_ARCH_MIPS64R6)
|
||||
lw $s0,0($inp)
|
||||
lw $s1,4($inp)
|
||||
lw $s2,8($inp)
|
||||
lw $s3,12($inp)
|
||||
#else
|
||||
lwl $s0,0+$MSB($inp)
|
||||
lwl $s1,4+$MSB($inp)
|
||||
lwl $s2,8+$MSB($inp)
|
||||
@@ -665,9 +665,16 @@ $code.=<<___;
|
||||
lwr $s1,4+$LSB($inp)
|
||||
lwr $s2,8+$LSB($inp)
|
||||
lwr $s3,12+$LSB($inp)
|
||||
#endif
|
||||
|
||||
bal _mips_AES_encrypt
|
||||
|
||||
#if defined(_MIPS_ARCH_MIPS32R6) || defined(_MIPS_ARCH_MIPS64R6)
|
||||
sw $s0,0($out)
|
||||
sw $s1,4($out)
|
||||
sw $s2,8($out)
|
||||
sw $s3,12($out)
|
||||
#else
|
||||
swr $s0,0+$LSB($out)
|
||||
swr $s1,4+$LSB($out)
|
||||
swr $s2,8+$LSB($out)
|
||||
@@ -676,6 +683,7 @@ $code.=<<___;
|
||||
swl $s1,4+$MSB($out)
|
||||
swl $s2,8+$MSB($out)
|
||||
swl $s3,12+$MSB($out)
|
||||
#endif
|
||||
|
||||
.set noreorder
|
||||
$REG_L $ra,$FRAMESIZE-1*$SZREG($sp)
|
||||
@@ -720,7 +728,7 @@ _mips_AES_decrypt:
|
||||
xor $s2,$t2
|
||||
xor $s3,$t3
|
||||
|
||||
sub $cnt,1
|
||||
subu $cnt,1
|
||||
#if defined(__mips_smartmips)
|
||||
ext $i0,$s3,16,8
|
||||
.Loop_dec:
|
||||
@@ -792,7 +800,7 @@ _mips_AES_decrypt:
|
||||
xor $t2,$t6
|
||||
xor $t3,$t7
|
||||
|
||||
sub $cnt,1
|
||||
subu $cnt,1
|
||||
$PTR_ADD $key0,16
|
||||
xor $s0,$t0
|
||||
xor $s1,$t1
|
||||
@@ -985,7 +993,7 @@ _mips_AES_decrypt:
|
||||
xor $t2,$t6
|
||||
xor $t3,$t7
|
||||
|
||||
sub $cnt,1
|
||||
subu $cnt,1
|
||||
$PTR_ADD $key0,16
|
||||
xor $s0,$t0
|
||||
xor $s1,$t1
|
||||
@@ -1228,6 +1236,12 @@ $code.=<<___;
|
||||
.set reorder
|
||||
$PTR_LA $Tbl,AES_Td # PIC-ified 'load address'
|
||||
|
||||
#if defined(_MIPS_ARCH_MIPS32R6) || defined(_MIPS_ARCH_MIPS64R6)
|
||||
lw $s0,0($inp)
|
||||
lw $s1,4($inp)
|
||||
lw $s2,8($inp)
|
||||
lw $s3,12($inp)
|
||||
#else
|
||||
lwl $s0,0+$MSB($inp)
|
||||
lwl $s1,4+$MSB($inp)
|
||||
lwl $s2,8+$MSB($inp)
|
||||
@@ -1236,9 +1250,16 @@ $code.=<<___;
|
||||
lwr $s1,4+$LSB($inp)
|
||||
lwr $s2,8+$LSB($inp)
|
||||
lwr $s3,12+$LSB($inp)
|
||||
#endif
|
||||
|
||||
bal _mips_AES_decrypt
|
||||
|
||||
#if defined(_MIPS_ARCH_MIPS32R6) || defined(_MIPS_ARCH_MIPS64R6)
|
||||
sw $s0,0($out)
|
||||
sw $s1,4($out)
|
||||
sw $s2,8($out)
|
||||
sw $s3,12($out)
|
||||
#else
|
||||
swr $s0,0+$LSB($out)
|
||||
swr $s1,4+$LSB($out)
|
||||
swr $s2,8+$LSB($out)
|
||||
@@ -1247,6 +1268,7 @@ $code.=<<___;
|
||||
swl $s1,4+$MSB($out)
|
||||
swl $s2,8+$MSB($out)
|
||||
swl $s3,12+$MSB($out)
|
||||
#endif
|
||||
|
||||
.set noreorder
|
||||
$REG_L $ra,$FRAMESIZE-1*$SZREG($sp)
|
||||
@@ -1295,35 +1317,52 @@ _mips_AES_set_encrypt_key:
|
||||
$PTR_ADD $rcon,$Tbl,256
|
||||
|
||||
.set reorder
|
||||
#if defined(_MIPS_ARCH_MIPS32R6) || defined(_MIPS_ARCH_MIPS64R6)
|
||||
lw $rk0,0($inp) # load 128 bits
|
||||
lw $rk1,4($inp)
|
||||
lw $rk2,8($inp)
|
||||
lw $rk3,12($inp)
|
||||
#else
|
||||
lwl $rk0,0+$MSB($inp) # load 128 bits
|
||||
lwl $rk1,4+$MSB($inp)
|
||||
lwl $rk2,8+$MSB($inp)
|
||||
lwl $rk3,12+$MSB($inp)
|
||||
li $at,128
|
||||
lwr $rk0,0+$LSB($inp)
|
||||
lwr $rk1,4+$LSB($inp)
|
||||
lwr $rk2,8+$LSB($inp)
|
||||
lwr $rk3,12+$LSB($inp)
|
||||
#endif
|
||||
li $at,128
|
||||
.set noreorder
|
||||
beq $bits,$at,.L128bits
|
||||
li $cnt,10
|
||||
|
||||
.set reorder
|
||||
#if defined(_MIPS_ARCH_MIPS32R6) || defined(_MIPS_ARCH_MIPS64R6)
|
||||
lw $rk4,16($inp) # load 192 bits
|
||||
lw $rk5,20($inp)
|
||||
#else
|
||||
lwl $rk4,16+$MSB($inp) # load 192 bits
|
||||
lwl $rk5,20+$MSB($inp)
|
||||
li $at,192
|
||||
lwr $rk4,16+$LSB($inp)
|
||||
lwr $rk5,20+$LSB($inp)
|
||||
#endif
|
||||
li $at,192
|
||||
.set noreorder
|
||||
beq $bits,$at,.L192bits
|
||||
li $cnt,8
|
||||
|
||||
.set reorder
|
||||
#if defined(_MIPS_ARCH_MIPS32R6) || defined(_MIPS_ARCH_MIPS64R6)
|
||||
lw $rk6,24($inp) # load 256 bits
|
||||
lw $rk7,28($inp)
|
||||
#else
|
||||
lwl $rk6,24+$MSB($inp) # load 256 bits
|
||||
lwl $rk7,28+$MSB($inp)
|
||||
li $at,256
|
||||
lwr $rk6,24+$LSB($inp)
|
||||
lwr $rk7,28+$LSB($inp)
|
||||
#endif
|
||||
li $at,256
|
||||
.set noreorder
|
||||
beq $bits,$at,.L256bits
|
||||
li $cnt,7
|
||||
@@ -1353,7 +1392,7 @@ _mips_AES_set_encrypt_key:
|
||||
sw $rk1,4($key)
|
||||
sw $rk2,8($key)
|
||||
sw $rk3,12($key)
|
||||
sub $cnt,1
|
||||
subu $cnt,1
|
||||
$PTR_ADD $key,16
|
||||
|
||||
_bias $i0,24
|
||||
@@ -1410,7 +1449,7 @@ _mips_AES_set_encrypt_key:
|
||||
sw $rk3,12($key)
|
||||
sw $rk4,16($key)
|
||||
sw $rk5,20($key)
|
||||
sub $cnt,1
|
||||
subu $cnt,1
|
||||
$PTR_ADD $key,24
|
||||
|
||||
_bias $i0,24
|
||||
@@ -1471,7 +1510,7 @@ _mips_AES_set_encrypt_key:
|
||||
sw $rk5,20($key)
|
||||
sw $rk6,24($key)
|
||||
sw $rk7,28($key)
|
||||
sub $cnt,1
|
||||
subu $cnt,1
|
||||
|
||||
_bias $i0,24
|
||||
_bias $i1,16
|
||||
@@ -1653,7 +1692,7 @@ $code.=<<___;
|
||||
|
||||
lw $tp1,16($key) # modulo-scheduled
|
||||
lui $x80808080,0x8080
|
||||
sub $cnt,1
|
||||
subu $cnt,1
|
||||
or $x80808080,0x8080
|
||||
sll $cnt,2
|
||||
$PTR_ADD $key,16
|
||||
@@ -1716,7 +1755,7 @@ $code.=<<___;
|
||||
lw $tp1,4($key) # modulo-scheduled
|
||||
xor $tpe,$tp2
|
||||
#endif
|
||||
sub $cnt,1
|
||||
subu $cnt,1
|
||||
sw $tpe,0($key)
|
||||
$PTR_ADD $key,4
|
||||
bnez $cnt,.Lmix
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
# ====================================================================
|
||||
# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
|
||||
# Written by Andy Polyakov <appro@openssl.org> for the OpenSSL
|
||||
# project. The module is, however, dual licensed under OpenSSL and
|
||||
# CRYPTOGAMS licenses depending on where you obtain it. For further
|
||||
# details see http://www.openssl.org/~appro/cryptogams/.
|
||||
@@ -1015,7 +1015,7 @@ ___
|
||||
foreach (split("\n",$code)) {
|
||||
s/\`([^\`]*)\`/eval $1/ge;
|
||||
|
||||
# translate made up instructons: _ror, _srm
|
||||
# translate made up instructions: _ror, _srm
|
||||
s/_ror(\s+)(%r[0-9]+),/shd$1$2,$2,/ or
|
||||
|
||||
s/_srm(\s+%r[0-9]+),([0-9]+),/
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
# ====================================================================
|
||||
# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
|
||||
# Written by Andy Polyakov <appro@openssl.org> for the OpenSSL
|
||||
# project. The module is, however, dual licensed under OpenSSL and
|
||||
# CRYPTOGAMS licenses depending on where you obtain it. For further
|
||||
# details see http://www.openssl.org/~appro/cryptogams/.
|
||||
@@ -1433,10 +1433,10 @@ $code.=<<___;
|
||||
xor $s1,$s1,$acc05
|
||||
xor $s2,$s2,$acc06
|
||||
xor $s3,$s3,$acc07
|
||||
xor $s0,$s0,$acc08 # ^= ROTATE(r8,8)
|
||||
xor $s1,$s1,$acc09
|
||||
xor $s2,$s2,$acc10
|
||||
xor $s3,$s3,$acc11
|
||||
xor $s0,$s0,$acc08 # ^= ROTATE(r8,8)
|
||||
xor $s1,$s1,$acc09
|
||||
xor $s2,$s2,$acc10
|
||||
xor $s3,$s3,$acc11
|
||||
|
||||
b Ldec_compact_loop
|
||||
.align 4
|
||||
|
||||
+78
-22
@@ -1,5 +1,5 @@
|
||||
#! /usr/bin/env perl
|
||||
# Copyright 2007-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
# Copyright 2007-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the OpenSSL license (the "License"). You may not use
|
||||
# this file except in compliance with the License. You can obtain a copy
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
# ====================================================================
|
||||
# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
|
||||
# Written by Andy Polyakov <appro@openssl.org> for the OpenSSL
|
||||
# project. The module is, however, dual licensed under OpenSSL and
|
||||
# CRYPTOGAMS licenses depending on where you obtain it. For further
|
||||
# details see http://www.openssl.org/~appro/cryptogams/.
|
||||
@@ -44,7 +44,7 @@
|
||||
# minimize/avoid Address Generation Interlock hazard and to favour
|
||||
# dual-issue z10 pipeline. This gave ~25% improvement on z10 and
|
||||
# almost 50% on z9. The gain is smaller on z10, because being dual-
|
||||
# issue z10 makes it improssible to eliminate the interlock condition:
|
||||
# issue z10 makes it impossible to eliminate the interlock condition:
|
||||
# critial path is not long enough. Yet it spends ~24 cycles per byte
|
||||
# processed with 128-bit key.
|
||||
#
|
||||
@@ -129,6 +129,8 @@ sub _data_word()
|
||||
}
|
||||
|
||||
$code=<<___;
|
||||
#include "s390x_arch.h"
|
||||
|
||||
.text
|
||||
|
||||
.type AES_Te,\@object
|
||||
@@ -404,7 +406,7 @@ _s390x_AES_encrypt:
|
||||
or $s1,$t1
|
||||
or $t2,$i2
|
||||
or $t3,$i3
|
||||
|
||||
|
||||
srlg $i1,$s2,`8-3` # i0
|
||||
srlg $i2,$s2,`16-3` # i1
|
||||
nr $i1,$mask
|
||||
@@ -457,7 +459,7 @@ _s390x_AES_encrypt:
|
||||
x $s2,24($key)
|
||||
x $s3,28($key)
|
||||
|
||||
br $ra
|
||||
br $ra
|
||||
.size _s390x_AES_encrypt,.-_s390x_AES_encrypt
|
||||
___
|
||||
|
||||
@@ -779,7 +781,7 @@ _s390x_AES_decrypt:
|
||||
x $s2,24($key)
|
||||
x $s3,28($key)
|
||||
|
||||
br $ra
|
||||
br $ra
|
||||
.size _s390x_AES_decrypt,.-_s390x_AES_decrypt
|
||||
___
|
||||
|
||||
@@ -823,8 +825,8 @@ $code.=<<___ if (!$softonly);
|
||||
larl %r1,OPENSSL_s390xcap_P
|
||||
llihh %r0,0x8000
|
||||
srlg %r0,%r0,0(%r5)
|
||||
ng %r0,32(%r1) # check availability of both km...
|
||||
ng %r0,48(%r1) # ...and kmc support for given key length
|
||||
ng %r0,S390X_KM(%r1) # check availability of both km...
|
||||
ng %r0,S390X_KMC(%r1) # ...and kmc support for given key length
|
||||
jz .Lekey_internal
|
||||
|
||||
lmg %r0,%r1,0($inp) # just copy 128 bits...
|
||||
@@ -1084,7 +1086,7 @@ $code.=<<___ if (!$softonly);
|
||||
lhi $t1,16
|
||||
cr $t0,$t1
|
||||
jl .Lgo
|
||||
oill $t0,0x80 # set "decrypt" bit
|
||||
oill $t0,S390X_DECRYPT # set "decrypt" bit
|
||||
st $t0,240($key)
|
||||
br $ra
|
||||
___
|
||||
@@ -1223,7 +1225,7 @@ $code.=<<___ if (!$softonly);
|
||||
.align 16
|
||||
.Lkmc_truncated:
|
||||
ahi $key,-1 # it's the way it's encoded in mvc
|
||||
tmll %r0,0x80
|
||||
tmll %r0,S390X_DECRYPT
|
||||
jnz .Lkmc_truncated_dec
|
||||
lghi %r1,0
|
||||
stg %r1,16*$SIZE_T($sp)
|
||||
@@ -1294,7 +1296,7 @@ $code.=<<___;
|
||||
.Lcbc_enc_done:
|
||||
l${g} $ivp,6*$SIZE_T($sp)
|
||||
st $s0,0($ivp)
|
||||
st $s1,4($ivp)
|
||||
st $s1,4($ivp)
|
||||
st $s2,8($ivp)
|
||||
st $s3,12($ivp)
|
||||
|
||||
@@ -1403,7 +1405,61 @@ $code.=<<___ if (!$softonly);
|
||||
clr %r0,%r1
|
||||
jl .Lctr32_software
|
||||
|
||||
stm${g} %r6,$s3,6*$SIZE_T($sp)
|
||||
st${g} $s2,10*$SIZE_T($sp)
|
||||
st${g} $s3,11*$SIZE_T($sp)
|
||||
|
||||
clr $len,%r1 # does work even in 64-bit mode
|
||||
jle .Lctr32_nokma # kma is slower for <= 16 blocks
|
||||
|
||||
larl %r1,OPENSSL_s390xcap_P
|
||||
lr $s2,%r0
|
||||
llihh $s3,0x8000
|
||||
srlg $s3,$s3,0($s2)
|
||||
ng $s3,S390X_KMA(%r1) # check kma capability vector
|
||||
jz .Lctr32_nokma
|
||||
|
||||
l${g}hi %r1,-$stdframe-112
|
||||
l${g}r $s3,$sp
|
||||
la $sp,0(%r1,$sp) # prepare parameter block
|
||||
|
||||
lhi %r1,0x0600
|
||||
sllg $len,$len,4
|
||||
or %r0,%r1 # set HS and LAAD flags
|
||||
|
||||
st${g} $s3,0($sp) # backchain
|
||||
la %r1,$stdframe($sp)
|
||||
|
||||
lmg $s2,$s3,0($key) # copy key
|
||||
stg $s2,$stdframe+80($sp)
|
||||
stg $s3,$stdframe+88($sp)
|
||||
lmg $s2,$s3,16($key)
|
||||
stg $s2,$stdframe+96($sp)
|
||||
stg $s3,$stdframe+104($sp)
|
||||
|
||||
lmg $s2,$s3,0($ivp) # copy iv
|
||||
stg $s2,$stdframe+64($sp)
|
||||
ahi $s3,-1 # kma requires counter-1
|
||||
stg $s3,$stdframe+72($sp)
|
||||
st $s3,$stdframe+12($sp) # copy counter
|
||||
|
||||
lghi $s2,0 # no AAD
|
||||
lghi $s3,0
|
||||
|
||||
.long 0xb929a042 # kma $out,$s2,$inp
|
||||
brc 1,.-4 # pay attention to "partial completion"
|
||||
|
||||
stg %r0,$stdframe+80($sp) # wipe key
|
||||
stg %r0,$stdframe+88($sp)
|
||||
stg %r0,$stdframe+96($sp)
|
||||
stg %r0,$stdframe+104($sp)
|
||||
la $sp,$stdframe+112($sp)
|
||||
|
||||
lm${g} $s2,$s3,10*$SIZE_T($sp)
|
||||
br $ra
|
||||
|
||||
.align 16
|
||||
.Lctr32_nokma:
|
||||
stm${g} %r6,$s1,6*$SIZE_T($sp)
|
||||
|
||||
slgr $out,$inp
|
||||
la %r1,0($key) # %r1 is permanent copy of $key
|
||||
@@ -1442,7 +1498,7 @@ $code.=<<___ if (!$softonly && 0);# kmctr code was measured to be ~12% slower
|
||||
larl %r1,OPENSSL_s390xcap_P
|
||||
llihh %r0,0x8000 # check if kmctr supports the function code
|
||||
srlg %r0,%r0,0($s0)
|
||||
ng %r0,64(%r1) # check kmctr capability vector
|
||||
ng %r0,S390X_KMCTR(%r1) # check kmctr capability vector
|
||||
lgr %r0,$s0
|
||||
lgr %r1,$s1
|
||||
jz .Lctr32_km_loop
|
||||
@@ -1567,8 +1623,8 @@ ___
|
||||
}
|
||||
|
||||
########################################################################
|
||||
# void AES_xts_encrypt(const char *inp,char *out,size_t len,
|
||||
# const AES_KEY *key1, const AES_KEY *key2,
|
||||
# void AES_xts_encrypt(const unsigned char *inp, unsigned char *out,
|
||||
# size_t len, const AES_KEY *key1, const AES_KEY *key2,
|
||||
# const unsigned char iv[16]);
|
||||
#
|
||||
{
|
||||
@@ -1592,7 +1648,7 @@ $code.=<<___ if(1);
|
||||
larl %r1,OPENSSL_s390xcap_P
|
||||
llihh %r0,0x8000
|
||||
srlg %r0,%r0,32($s1) # check for 32+function code
|
||||
ng %r0,32(%r1) # check km capability vector
|
||||
ng %r0,S390X_KM(%r1) # check km capability vector
|
||||
lgr %r0,$s0 # restore the function code
|
||||
la %r1,0($key1) # restore $key1
|
||||
jz .Lxts_km_vanilla
|
||||
@@ -1627,7 +1683,7 @@ $code.=<<___ if(1);
|
||||
llgc $len,2*$SIZE_T-1($sp)
|
||||
nill $len,0x0f # $len%=16
|
||||
br $ra
|
||||
|
||||
|
||||
.align 16
|
||||
.Lxts_km_vanilla:
|
||||
___
|
||||
@@ -1854,7 +1910,7 @@ $code.=<<___;
|
||||
xgr $s1,%r1
|
||||
lrvgr $s1,$s1 # flip byte order
|
||||
lrvgr $s3,$s3
|
||||
srlg $s0,$s1,32 # smash the tweak to 4x32-bits
|
||||
srlg $s0,$s1,32 # smash the tweak to 4x32-bits
|
||||
stg $s1,$tweak+0($sp) # save the tweak
|
||||
llgfr $s1,$s1
|
||||
srlg $s2,$s3,32
|
||||
@@ -1905,7 +1961,7 @@ $code.=<<___;
|
||||
xgr $s1,%r1
|
||||
lrvgr $s1,$s1 # flip byte order
|
||||
lrvgr $s3,$s3
|
||||
srlg $s0,$s1,32 # smash the tweak to 4x32-bits
|
||||
srlg $s0,$s1,32 # smash the tweak to 4x32-bits
|
||||
stg $s1,$tweak+0($sp) # save the tweak
|
||||
llgfr $s1,$s1
|
||||
srlg $s2,$s3,32
|
||||
@@ -1936,8 +1992,8 @@ $code.=<<___;
|
||||
br $ra
|
||||
.size AES_xts_encrypt,.-AES_xts_encrypt
|
||||
___
|
||||
# void AES_xts_decrypt(const char *inp,char *out,size_t len,
|
||||
# const AES_KEY *key1, const AES_KEY *key2,
|
||||
# void AES_xts_decrypt(const unsigned char *inp, unsigned char *out,
|
||||
# size_t len, const AES_KEY *key1, const AES_KEY *key2,
|
||||
# const unsigned char iv[16]);
|
||||
#
|
||||
$code.=<<___;
|
||||
@@ -2097,7 +2153,7 @@ $code.=<<___;
|
||||
xgr $s1,%r1
|
||||
lrvgr $s1,$s1 # flip byte order
|
||||
lrvgr $s3,$s3
|
||||
srlg $s0,$s1,32 # smash the tweak to 4x32-bits
|
||||
srlg $s0,$s1,32 # smash the tweak to 4x32-bits
|
||||
stg $s1,$tweak+0($sp) # save the tweak
|
||||
llgfr $s1,$s1
|
||||
srlg $s2,$s3,32
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#
|
||||
# ====================================================================
|
||||
# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
|
||||
# Written by Andy Polyakov <appro@openssl.org> for the OpenSSL
|
||||
# project. Rights for redistribution and usage in source and binary
|
||||
# forms are granted according to the OpenSSL license.
|
||||
# ====================================================================
|
||||
|
||||
+108
-26
@@ -8,7 +8,7 @@
|
||||
|
||||
#
|
||||
# ====================================================================
|
||||
# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
|
||||
# Written by Andy Polyakov <appro@openssl.org> for the OpenSSL
|
||||
# project. The module is, however, dual licensed under OpenSSL and
|
||||
# CRYPTOGAMS licenses depending on where you obtain it. For further
|
||||
# details see http://www.openssl.org/~appro/cryptogams/.
|
||||
@@ -599,15 +599,23 @@ $code.=<<___;
|
||||
.hidden asm_AES_encrypt
|
||||
asm_AES_encrypt:
|
||||
AES_encrypt:
|
||||
.cfi_startproc
|
||||
mov %rsp,%rax
|
||||
.cfi_def_cfa_register %rax
|
||||
push %rbx
|
||||
.cfi_push %rbx
|
||||
push %rbp
|
||||
.cfi_push %rbp
|
||||
push %r12
|
||||
.cfi_push %r12
|
||||
push %r13
|
||||
.cfi_push %r13
|
||||
push %r14
|
||||
.cfi_push %r14
|
||||
push %r15
|
||||
.cfi_push %r15
|
||||
|
||||
# allocate frame "above" key schedule
|
||||
mov %rsp,%r10
|
||||
lea -63(%rdx),%rcx # %rdx is key argument
|
||||
and \$-64,%rsp
|
||||
sub %rsp,%rcx
|
||||
@@ -617,7 +625,8 @@ AES_encrypt:
|
||||
sub \$32,%rsp
|
||||
|
||||
mov %rsi,16(%rsp) # save out
|
||||
mov %r10,24(%rsp) # save real stack pointer
|
||||
mov %rax,24(%rsp) # save original stack pointer
|
||||
.cfi_cfa_expression %rsp+24,deref,+8
|
||||
.Lenc_prologue:
|
||||
|
||||
mov %rdx,$key
|
||||
@@ -644,20 +653,29 @@ AES_encrypt:
|
||||
|
||||
mov 16(%rsp),$out # restore out
|
||||
mov 24(%rsp),%rsi # restore saved stack pointer
|
||||
.cfi_def_cfa %rsi,8
|
||||
mov $s0,0($out) # write output vector
|
||||
mov $s1,4($out)
|
||||
mov $s2,8($out)
|
||||
mov $s3,12($out)
|
||||
|
||||
mov (%rsi),%r15
|
||||
mov 8(%rsi),%r14
|
||||
mov 16(%rsi),%r13
|
||||
mov 24(%rsi),%r12
|
||||
mov 32(%rsi),%rbp
|
||||
mov 40(%rsi),%rbx
|
||||
lea 48(%rsi),%rsp
|
||||
mov -48(%rsi),%r15
|
||||
.cfi_restore %r15
|
||||
mov -40(%rsi),%r14
|
||||
.cfi_restore %r14
|
||||
mov -32(%rsi),%r13
|
||||
.cfi_restore %r13
|
||||
mov -24(%rsi),%r12
|
||||
.cfi_restore %r12
|
||||
mov -16(%rsi),%rbp
|
||||
.cfi_restore %rbp
|
||||
mov -8(%rsi),%rbx
|
||||
.cfi_restore %rbx
|
||||
lea (%rsi),%rsp
|
||||
.cfi_def_cfa_register %rsp
|
||||
.Lenc_epilogue:
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size AES_encrypt,.-AES_encrypt
|
||||
___
|
||||
|
||||
@@ -1197,15 +1215,23 @@ $code.=<<___;
|
||||
.hidden asm_AES_decrypt
|
||||
asm_AES_decrypt:
|
||||
AES_decrypt:
|
||||
.cfi_startproc
|
||||
mov %rsp,%rax
|
||||
.cfi_def_cfa_register %rax
|
||||
push %rbx
|
||||
.cfi_push %rbx
|
||||
push %rbp
|
||||
.cfi_push %rbp
|
||||
push %r12
|
||||
.cfi_push %r12
|
||||
push %r13
|
||||
.cfi_push %r13
|
||||
push %r14
|
||||
.cfi_push %r14
|
||||
push %r15
|
||||
.cfi_push %r15
|
||||
|
||||
# allocate frame "above" key schedule
|
||||
mov %rsp,%r10
|
||||
lea -63(%rdx),%rcx # %rdx is key argument
|
||||
and \$-64,%rsp
|
||||
sub %rsp,%rcx
|
||||
@@ -1215,7 +1241,8 @@ AES_decrypt:
|
||||
sub \$32,%rsp
|
||||
|
||||
mov %rsi,16(%rsp) # save out
|
||||
mov %r10,24(%rsp) # save real stack pointer
|
||||
mov %rax,24(%rsp) # save original stack pointer
|
||||
.cfi_cfa_expression %rsp+24,deref,+8
|
||||
.Ldec_prologue:
|
||||
|
||||
mov %rdx,$key
|
||||
@@ -1244,20 +1271,29 @@ AES_decrypt:
|
||||
|
||||
mov 16(%rsp),$out # restore out
|
||||
mov 24(%rsp),%rsi # restore saved stack pointer
|
||||
.cfi_def_cfa %rsi,8
|
||||
mov $s0,0($out) # write output vector
|
||||
mov $s1,4($out)
|
||||
mov $s2,8($out)
|
||||
mov $s3,12($out)
|
||||
|
||||
mov (%rsi),%r15
|
||||
mov 8(%rsi),%r14
|
||||
mov 16(%rsi),%r13
|
||||
mov 24(%rsi),%r12
|
||||
mov 32(%rsi),%rbp
|
||||
mov 40(%rsi),%rbx
|
||||
lea 48(%rsi),%rsp
|
||||
mov -48(%rsi),%r15
|
||||
.cfi_restore %r15
|
||||
mov -40(%rsi),%r14
|
||||
.cfi_restore %r14
|
||||
mov -32(%rsi),%r13
|
||||
.cfi_restore %r13
|
||||
mov -24(%rsi),%r12
|
||||
.cfi_restore %r12
|
||||
mov -16(%rsi),%rbp
|
||||
.cfi_restore %rbp
|
||||
mov -8(%rsi),%rbx
|
||||
.cfi_restore %rbx
|
||||
lea (%rsi),%rsp
|
||||
.cfi_def_cfa_register %rsp
|
||||
.Ldec_epilogue:
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size AES_decrypt,.-AES_decrypt
|
||||
___
|
||||
#------------------------------------------------------------------#
|
||||
@@ -1296,22 +1332,34 @@ $code.=<<___;
|
||||
.type AES_set_encrypt_key,\@function,3
|
||||
.align 16
|
||||
AES_set_encrypt_key:
|
||||
.cfi_startproc
|
||||
push %rbx
|
||||
.cfi_push %rbx
|
||||
push %rbp
|
||||
push %r12 # redundant, but allows to share
|
||||
.cfi_push %rbp
|
||||
push %r12 # redundant, but allows to share
|
||||
.cfi_push %r12
|
||||
push %r13 # exception handler...
|
||||
.cfi_push %r13
|
||||
push %r14
|
||||
.cfi_push %r14
|
||||
push %r15
|
||||
.cfi_push %r15
|
||||
sub \$8,%rsp
|
||||
.cfi_adjust_cfa_offset 8
|
||||
.Lenc_key_prologue:
|
||||
|
||||
call _x86_64_AES_set_encrypt_key
|
||||
|
||||
mov 40(%rsp),%rbp
|
||||
.cfi_restore %rbp
|
||||
mov 48(%rsp),%rbx
|
||||
.cfi_restore %rbx
|
||||
add \$56,%rsp
|
||||
.cfi_adjust_cfa_offset -56
|
||||
.Lenc_key_epilogue:
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size AES_set_encrypt_key,.-AES_set_encrypt_key
|
||||
|
||||
.type _x86_64_AES_set_encrypt_key,\@abi-omnipotent
|
||||
@@ -1424,7 +1472,7 @@ $code.=<<___;
|
||||
xor %rax,%rax
|
||||
jmp .Lexit
|
||||
|
||||
.L14rounds:
|
||||
.L14rounds:
|
||||
mov 0(%rsi),%rax # copy first 8 dwords
|
||||
mov 8(%rsi),%rbx
|
||||
mov 16(%rsi),%rcx
|
||||
@@ -1562,13 +1610,21 @@ $code.=<<___;
|
||||
.type AES_set_decrypt_key,\@function,3
|
||||
.align 16
|
||||
AES_set_decrypt_key:
|
||||
.cfi_startproc
|
||||
push %rbx
|
||||
.cfi_push %rbx
|
||||
push %rbp
|
||||
.cfi_push %rbp
|
||||
push %r12
|
||||
.cfi_push %r12
|
||||
push %r13
|
||||
.cfi_push %r13
|
||||
push %r14
|
||||
.cfi_push %r14
|
||||
push %r15
|
||||
.cfi_push %r15
|
||||
push %rdx # save key schedule
|
||||
.cfi_adjust_cfa_offset 8
|
||||
.Ldec_key_prologue:
|
||||
|
||||
call _x86_64_AES_set_encrypt_key
|
||||
@@ -1622,14 +1678,22 @@ $code.=<<___;
|
||||
xor %rax,%rax
|
||||
.Labort:
|
||||
mov 8(%rsp),%r15
|
||||
.cfi_restore %r15
|
||||
mov 16(%rsp),%r14
|
||||
.cfi_restore %r14
|
||||
mov 24(%rsp),%r13
|
||||
.cfi_restore %r13
|
||||
mov 32(%rsp),%r12
|
||||
.cfi_restore %r12
|
||||
mov 40(%rsp),%rbp
|
||||
.cfi_restore %rbp
|
||||
mov 48(%rsp),%rbx
|
||||
.cfi_restore %rbx
|
||||
add \$56,%rsp
|
||||
.cfi_adjust_cfa_offset -56
|
||||
.Ldec_key_epilogue:
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size AES_set_decrypt_key,.-AES_set_decrypt_key
|
||||
___
|
||||
|
||||
@@ -1660,25 +1724,32 @@ $code.=<<___;
|
||||
.hidden asm_AES_cbc_encrypt
|
||||
asm_AES_cbc_encrypt:
|
||||
AES_cbc_encrypt:
|
||||
.cfi_startproc
|
||||
cmp \$0,%rdx # check length
|
||||
je .Lcbc_epilogue
|
||||
pushfq
|
||||
.cfi_push 49 # %rflags
|
||||
push %rbx
|
||||
.cfi_push %rbx
|
||||
push %rbp
|
||||
.cfi_push %rbp
|
||||
push %r12
|
||||
.cfi_push %r12
|
||||
push %r13
|
||||
.cfi_push %r13
|
||||
push %r14
|
||||
.cfi_push %r14
|
||||
push %r15
|
||||
.cfi_push %r15
|
||||
.Lcbc_prologue:
|
||||
|
||||
cld
|
||||
mov %r9d,%r9d # clear upper half of enc
|
||||
|
||||
lea .LAES_Te(%rip),$sbox
|
||||
lea .LAES_Td(%rip),%r10
|
||||
cmp \$0,%r9
|
||||
jne .Lcbc_picked_te
|
||||
lea .LAES_Td(%rip),$sbox
|
||||
.Lcbc_picked_te:
|
||||
cmoveq %r10,$sbox
|
||||
|
||||
mov OPENSSL_ia32cap_P(%rip),%r10d
|
||||
cmp \$$speed_limit,%rdx
|
||||
@@ -1714,8 +1785,10 @@ AES_cbc_encrypt:
|
||||
.Lcbc_te_ok:
|
||||
|
||||
xchg %rsp,$key
|
||||
.cfi_def_cfa_register $key
|
||||
#add \$8,%rsp # reserve for return address!
|
||||
mov $key,$_rsp # save %rsp
|
||||
.cfi_cfa_expression $_rsp,deref,+64
|
||||
.Lcbc_fast_body:
|
||||
mov %rdi,$_inp # save copy of inp
|
||||
mov %rsi,$_out # save copy of out
|
||||
@@ -1945,7 +2018,7 @@ AES_cbc_encrypt:
|
||||
lea ($key,%rax),%rax
|
||||
mov %rax,$keyend
|
||||
|
||||
# pick Te4 copy which can't "overlap" with stack frame or key scdedule
|
||||
# pick Te4 copy which can't "overlap" with stack frame or key schedule
|
||||
lea 2048($sbox),$sbox
|
||||
lea 768-8(%rsp),%rax
|
||||
sub $sbox,%rax
|
||||
@@ -2097,17 +2170,27 @@ AES_cbc_encrypt:
|
||||
.align 16
|
||||
.Lcbc_exit:
|
||||
mov $_rsp,%rsi
|
||||
.cfi_def_cfa %rsi,64
|
||||
mov (%rsi),%r15
|
||||
.cfi_restore %r15
|
||||
mov 8(%rsi),%r14
|
||||
.cfi_restore %r14
|
||||
mov 16(%rsi),%r13
|
||||
.cfi_restore %r13
|
||||
mov 24(%rsi),%r12
|
||||
.cfi_restore %r12
|
||||
mov 32(%rsi),%rbp
|
||||
.cfi_restore %rbp
|
||||
mov 40(%rsi),%rbx
|
||||
.cfi_restore %rbx
|
||||
lea 48(%rsi),%rsp
|
||||
.cfi_def_cfa %rsp,16
|
||||
.Lcbc_popfq:
|
||||
popfq
|
||||
.cfi_pop 49 # %rflags
|
||||
.Lcbc_epilogue:
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size AES_cbc_encrypt,.-AES_cbc_encrypt
|
||||
___
|
||||
}
|
||||
@@ -2580,7 +2663,6 @@ block_se_handler:
|
||||
jae .Lin_block_prologue
|
||||
|
||||
mov 24(%rax),%rax # pull saved real stack pointer
|
||||
lea 48(%rax),%rax # adjust...
|
||||
|
||||
mov -8(%rax),%rbx
|
||||
mov -16(%rax),%rbp
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
# April 2016
|
||||
#
|
||||
# Add "teaser" CBC and CTR mode-specific subroutines. "Teaser" means
|
||||
# that parallelizeable nature of CBC decrypt and CTR is not utilized
|
||||
# that parallelizable nature of CBC decrypt and CTR is not utilized
|
||||
# yet. CBC encrypt on the other hand is as good as it can possibly
|
||||
# get processing one byte in 4.1 cycles with 128-bit key on SPARC64 X.
|
||||
# This is ~6x faster than pure software implementation...
|
||||
|
||||
@@ -105,6 +105,7 @@ $code.=<<___;
|
||||
.type aesni_multi_cbc_encrypt,\@function,3
|
||||
.align 32
|
||||
aesni_multi_cbc_encrypt:
|
||||
.cfi_startproc
|
||||
___
|
||||
$code.=<<___ if ($avx);
|
||||
cmp \$2,$num
|
||||
@@ -118,12 +119,19 @@ $code.=<<___ if ($avx);
|
||||
___
|
||||
$code.=<<___;
|
||||
mov %rsp,%rax
|
||||
.cfi_def_cfa_register %rax
|
||||
push %rbx
|
||||
.cfi_push %rbx
|
||||
push %rbp
|
||||
.cfi_push %rbp
|
||||
push %r12
|
||||
.cfi_push %r12
|
||||
push %r13
|
||||
.cfi_push %r13
|
||||
push %r14
|
||||
.cfi_push %r14
|
||||
push %r15
|
||||
.cfi_push %r15
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
lea -0xa8(%rsp),%rsp
|
||||
@@ -134,7 +142,7 @@ $code.=<<___ if ($win64);
|
||||
movaps %xmm10,0x40(%rsp)
|
||||
movaps %xmm11,0x50(%rsp)
|
||||
movaps %xmm12,0x60(%rsp)
|
||||
movaps %xmm13,-0x68(%rax) # not used, saved to share se_handler
|
||||
movaps %xmm13,-0x68(%rax) # not used, saved to share se_handler
|
||||
movaps %xmm14,-0x58(%rax)
|
||||
movaps %xmm15,-0x48(%rax)
|
||||
___
|
||||
@@ -148,6 +156,7 @@ $code.=<<___;
|
||||
sub \$48,%rsp
|
||||
and \$-64,%rsp
|
||||
mov %rax,16(%rsp) # original %rsp
|
||||
.cfi_cfa_expression %rsp+16,deref,+8
|
||||
|
||||
.Lenc4x_body:
|
||||
movdqu ($key),$zero # 0-round key
|
||||
@@ -308,9 +317,9 @@ $code.=<<___;
|
||||
|
||||
movups @out[0],-16(@outptr[0],$offset)
|
||||
pxor @inp[0],@out[0]
|
||||
movups @out[1],-16(@outptr[1],$offset)
|
||||
movups @out[1],-16(@outptr[1],$offset)
|
||||
pxor @inp[1],@out[1]
|
||||
movups @out[2],-16(@outptr[2],$offset)
|
||||
movups @out[2],-16(@outptr[2],$offset)
|
||||
pxor @inp[2],@out[2]
|
||||
movups @out[3],-16(@outptr[3],$offset)
|
||||
pxor @inp[3],@out[3]
|
||||
@@ -319,6 +328,7 @@ $code.=<<___;
|
||||
jnz .Loop_enc4x
|
||||
|
||||
mov 16(%rsp),%rax # original %rsp
|
||||
.cfi_def_cfa %rax,8
|
||||
mov 24(%rsp),$num
|
||||
|
||||
#pxor @inp[0],@out[0]
|
||||
@@ -350,20 +360,29 @@ $code.=<<___ if ($win64);
|
||||
___
|
||||
$code.=<<___;
|
||||
mov -48(%rax),%r15
|
||||
.cfi_restore %r15
|
||||
mov -40(%rax),%r14
|
||||
.cfi_restore %r14
|
||||
mov -32(%rax),%r13
|
||||
.cfi_restore %r13
|
||||
mov -24(%rax),%r12
|
||||
.cfi_restore %r12
|
||||
mov -16(%rax),%rbp
|
||||
.cfi_restore %rbp
|
||||
mov -8(%rax),%rbx
|
||||
.cfi_restore %rbx
|
||||
lea (%rax),%rsp
|
||||
.cfi_def_cfa_register %rsp
|
||||
.Lenc4x_epilogue:
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aesni_multi_cbc_encrypt,.-aesni_multi_cbc_encrypt
|
||||
|
||||
.globl aesni_multi_cbc_decrypt
|
||||
.type aesni_multi_cbc_decrypt,\@function,3
|
||||
.align 32
|
||||
aesni_multi_cbc_decrypt:
|
||||
.cfi_startproc
|
||||
___
|
||||
$code.=<<___ if ($avx);
|
||||
cmp \$2,$num
|
||||
@@ -377,12 +396,19 @@ $code.=<<___ if ($avx);
|
||||
___
|
||||
$code.=<<___;
|
||||
mov %rsp,%rax
|
||||
.cfi_def_cfa_register %rax
|
||||
push %rbx
|
||||
.cfi_push %rbx
|
||||
push %rbp
|
||||
.cfi_push %rbp
|
||||
push %r12
|
||||
.cfi_push %r12
|
||||
push %r13
|
||||
.cfi_push %r13
|
||||
push %r14
|
||||
.cfi_push %r14
|
||||
push %r15
|
||||
.cfi_push %r15
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
lea -0xa8(%rsp),%rsp
|
||||
@@ -393,7 +419,7 @@ $code.=<<___ if ($win64);
|
||||
movaps %xmm10,0x40(%rsp)
|
||||
movaps %xmm11,0x50(%rsp)
|
||||
movaps %xmm12,0x60(%rsp)
|
||||
movaps %xmm13,-0x68(%rax) # not used, saved to share se_handler
|
||||
movaps %xmm13,-0x68(%rax) # not used, saved to share se_handler
|
||||
movaps %xmm14,-0x58(%rax)
|
||||
movaps %xmm15,-0x48(%rax)
|
||||
___
|
||||
@@ -407,6 +433,7 @@ $code.=<<___;
|
||||
sub \$48,%rsp
|
||||
and \$-64,%rsp
|
||||
mov %rax,16(%rsp) # original %rsp
|
||||
.cfi_cfa_expression %rsp+16,deref,+8
|
||||
|
||||
.Ldec4x_body:
|
||||
movdqu ($key),$zero # 0-round key
|
||||
@@ -563,10 +590,10 @@ $code.=<<___;
|
||||
|
||||
movups @out[0],-16(@outptr[0],$offset)
|
||||
movdqu (@inptr[0],$offset),@out[0]
|
||||
movups @out[1],-16(@outptr[1],$offset)
|
||||
movups @out[1],-16(@outptr[1],$offset)
|
||||
movdqu (@inptr[1],$offset),@out[1]
|
||||
pxor $zero,@out[0]
|
||||
movups @out[2],-16(@outptr[2],$offset)
|
||||
movups @out[2],-16(@outptr[2],$offset)
|
||||
movdqu (@inptr[2],$offset),@out[2]
|
||||
pxor $zero,@out[1]
|
||||
movups @out[3],-16(@outptr[3],$offset)
|
||||
@@ -578,6 +605,7 @@ $code.=<<___;
|
||||
jnz .Loop_dec4x
|
||||
|
||||
mov 16(%rsp),%rax # original %rsp
|
||||
.cfi_def_cfa %rax,8
|
||||
mov 24(%rsp),$num
|
||||
|
||||
lea `40*4`($inp),$inp
|
||||
@@ -600,14 +628,22 @@ $code.=<<___ if ($win64);
|
||||
___
|
||||
$code.=<<___;
|
||||
mov -48(%rax),%r15
|
||||
.cfi_restore %r15
|
||||
mov -40(%rax),%r14
|
||||
.cfi_restore %r14
|
||||
mov -32(%rax),%r13
|
||||
.cfi_restore %r13
|
||||
mov -24(%rax),%r12
|
||||
.cfi_restore %r12
|
||||
mov -16(%rax),%rbp
|
||||
.cfi_restore %rbp
|
||||
mov -8(%rax),%rbx
|
||||
.cfi_restore %rbx
|
||||
lea (%rax),%rsp
|
||||
.cfi_def_cfa_register %rsp
|
||||
.Ldec4x_epilogue:
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aesni_multi_cbc_decrypt,.-aesni_multi_cbc_decrypt
|
||||
___
|
||||
|
||||
@@ -623,14 +659,22 @@ $code.=<<___;
|
||||
.type aesni_multi_cbc_encrypt_avx,\@function,3
|
||||
.align 32
|
||||
aesni_multi_cbc_encrypt_avx:
|
||||
.cfi_startproc
|
||||
_avx_cbc_enc_shortcut:
|
||||
mov %rsp,%rax
|
||||
.cfi_def_cfa_register %rax
|
||||
push %rbx
|
||||
.cfi_push %rbx
|
||||
push %rbp
|
||||
.cfi_push %rbp
|
||||
push %r12
|
||||
.cfi_push %r12
|
||||
push %r13
|
||||
.cfi_push %r13
|
||||
push %r14
|
||||
.cfi_push %r14
|
||||
push %r15
|
||||
.cfi_push %r15
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
lea -0xa8(%rsp),%rsp
|
||||
@@ -657,6 +701,7 @@ $code.=<<___;
|
||||
sub \$192,%rsp
|
||||
and \$-128,%rsp
|
||||
mov %rax,16(%rsp) # original %rsp
|
||||
.cfi_cfa_expression %rsp+16,deref,+8
|
||||
|
||||
.Lenc8x_body:
|
||||
vzeroupper
|
||||
@@ -835,10 +880,10 @@ $code.=<<___;
|
||||
vmovups @out[0],-16(@ptr[0]) # write output
|
||||
sub $offset,@ptr[0] # switch to input
|
||||
vpxor 0x00($offload),@out[0],@out[0]
|
||||
vmovups @out[1],-16(@ptr[1])
|
||||
vmovups @out[1],-16(@ptr[1])
|
||||
sub `64+1*8`(%rsp),@ptr[1]
|
||||
vpxor 0x10($offload),@out[1],@out[1]
|
||||
vmovups @out[2],-16(@ptr[2])
|
||||
vmovups @out[2],-16(@ptr[2])
|
||||
sub `64+2*8`(%rsp),@ptr[2]
|
||||
vpxor 0x20($offload),@out[2],@out[2]
|
||||
vmovups @out[3],-16(@ptr[3])
|
||||
@@ -847,10 +892,10 @@ $code.=<<___;
|
||||
vmovups @out[4],-16(@ptr[4])
|
||||
sub `64+4*8`(%rsp),@ptr[4]
|
||||
vpxor @inp[0],@out[4],@out[4]
|
||||
vmovups @out[5],-16(@ptr[5])
|
||||
vmovups @out[5],-16(@ptr[5])
|
||||
sub `64+5*8`(%rsp),@ptr[5]
|
||||
vpxor @inp[1],@out[5],@out[5]
|
||||
vmovups @out[6],-16(@ptr[6])
|
||||
vmovups @out[6],-16(@ptr[6])
|
||||
sub `64+6*8`(%rsp),@ptr[6]
|
||||
vpxor @inp[2],@out[6],@out[6]
|
||||
vmovups @out[7],-16(@ptr[7])
|
||||
@@ -861,6 +906,7 @@ $code.=<<___;
|
||||
jnz .Loop_enc8x
|
||||
|
||||
mov 16(%rsp),%rax # original %rsp
|
||||
.cfi_def_cfa %rax,8
|
||||
#mov 24(%rsp),$num
|
||||
#lea `40*8`($inp),$inp
|
||||
#dec $num
|
||||
@@ -883,27 +929,43 @@ $code.=<<___ if ($win64);
|
||||
___
|
||||
$code.=<<___;
|
||||
mov -48(%rax),%r15
|
||||
.cfi_restore %r15
|
||||
mov -40(%rax),%r14
|
||||
.cfi_restore %r14
|
||||
mov -32(%rax),%r13
|
||||
.cfi_restore %r13
|
||||
mov -24(%rax),%r12
|
||||
.cfi_restore %r12
|
||||
mov -16(%rax),%rbp
|
||||
.cfi_restore %rbp
|
||||
mov -8(%rax),%rbx
|
||||
.cfi_restore %rbx
|
||||
lea (%rax),%rsp
|
||||
.cfi_def_cfa_register %rsp
|
||||
.Lenc8x_epilogue:
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aesni_multi_cbc_encrypt_avx,.-aesni_multi_cbc_encrypt_avx
|
||||
|
||||
.type aesni_multi_cbc_decrypt_avx,\@function,3
|
||||
.align 32
|
||||
aesni_multi_cbc_decrypt_avx:
|
||||
.cfi_startproc
|
||||
_avx_cbc_dec_shortcut:
|
||||
mov %rsp,%rax
|
||||
.cfi_def_cfa_register %rax
|
||||
push %rbx
|
||||
.cfi_push %rbx
|
||||
push %rbp
|
||||
.cfi_push %rbp
|
||||
push %r12
|
||||
.cfi_push %r12
|
||||
push %r13
|
||||
.cfi_push %r13
|
||||
push %r14
|
||||
.cfi_push %r14
|
||||
push %r15
|
||||
.cfi_push %r15
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
lea -0xa8(%rsp),%rsp
|
||||
@@ -932,6 +994,7 @@ $code.=<<___;
|
||||
and \$-256,%rsp
|
||||
sub \$192,%rsp
|
||||
mov %rax,16(%rsp) # original %rsp
|
||||
.cfi_cfa_expression %rsp+16,deref,+8
|
||||
|
||||
.Ldec8x_body:
|
||||
vzeroupper
|
||||
@@ -1128,12 +1191,12 @@ $code.=<<___;
|
||||
sub $offset,@ptr[0] # switch to input
|
||||
vmovdqu 128+0(%rsp),@out[0]
|
||||
vpxor 0x70($offload),@out[7],@out[7]
|
||||
vmovups @out[1],-16(@ptr[1])
|
||||
vmovups @out[1],-16(@ptr[1])
|
||||
sub `64+1*8`(%rsp),@ptr[1]
|
||||
vmovdqu @out[0],0x00($offload)
|
||||
vpxor $zero,@out[0],@out[0]
|
||||
vmovdqu 128+16(%rsp),@out[1]
|
||||
vmovups @out[2],-16(@ptr[2])
|
||||
vmovups @out[2],-16(@ptr[2])
|
||||
sub `64+2*8`(%rsp),@ptr[2]
|
||||
vmovdqu @out[1],0x10($offload)
|
||||
vpxor $zero,@out[1],@out[1]
|
||||
@@ -1149,11 +1212,11 @@ $code.=<<___;
|
||||
vpxor $zero,@out[3],@out[3]
|
||||
vmovdqu @inp[0],0x40($offload)
|
||||
vpxor @inp[0],$zero,@out[4]
|
||||
vmovups @out[5],-16(@ptr[5])
|
||||
vmovups @out[5],-16(@ptr[5])
|
||||
sub `64+5*8`(%rsp),@ptr[5]
|
||||
vmovdqu @inp[1],0x50($offload)
|
||||
vpxor @inp[1],$zero,@out[5]
|
||||
vmovups @out[6],-16(@ptr[6])
|
||||
vmovups @out[6],-16(@ptr[6])
|
||||
sub `64+6*8`(%rsp),@ptr[6]
|
||||
vmovdqu @inp[2],0x60($offload)
|
||||
vpxor @inp[2],$zero,@out[6]
|
||||
@@ -1167,6 +1230,7 @@ $code.=<<___;
|
||||
jnz .Loop_dec8x
|
||||
|
||||
mov 16(%rsp),%rax # original %rsp
|
||||
.cfi_def_cfa %rax,8
|
||||
#mov 24(%rsp),$num
|
||||
#lea `40*8`($inp),$inp
|
||||
#dec $num
|
||||
@@ -1189,14 +1253,22 @@ $code.=<<___ if ($win64);
|
||||
___
|
||||
$code.=<<___;
|
||||
mov -48(%rax),%r15
|
||||
.cfi_restore %r15
|
||||
mov -40(%rax),%r14
|
||||
.cfi_restore %r14
|
||||
mov -32(%rax),%r13
|
||||
.cfi_restore %r13
|
||||
mov -24(%rax),%r12
|
||||
.cfi_restore %r12
|
||||
mov -16(%rax),%rbp
|
||||
.cfi_restore %rbp
|
||||
mov -8(%rax),%rbx
|
||||
.cfi_restore %rbx
|
||||
lea (%rax),%rsp
|
||||
.cfi_def_cfa_register %rsp
|
||||
.Ldec8x_epilogue:
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aesni_multi_cbc_decrypt_avx,.-aesni_multi_cbc_decrypt_avx
|
||||
___
|
||||
}}}
|
||||
@@ -1253,10 +1325,10 @@ se_handler:
|
||||
mov -48(%rax),%r15
|
||||
mov %rbx,144($context) # restore context->Rbx
|
||||
mov %rbp,160($context) # restore context->Rbp
|
||||
mov %r12,216($context) # restore cotnext->R12
|
||||
mov %r13,224($context) # restore cotnext->R13
|
||||
mov %r14,232($context) # restore cotnext->R14
|
||||
mov %r15,240($context) # restore cotnext->R15
|
||||
mov %r12,216($context) # restore context->R12
|
||||
mov %r13,224($context) # restore context->R13
|
||||
mov %r14,232($context) # restore context->R14
|
||||
mov %r15,240($context) # restore context->R15
|
||||
|
||||
lea -56-10*16(%rax),%rsi
|
||||
lea 512($context),%rdi # &context.Xmm6
|
||||
|
||||
@@ -191,16 +191,24 @@ $code.=<<___;
|
||||
.type aesni_cbc_sha1_enc_ssse3,\@function,6
|
||||
.align 32
|
||||
aesni_cbc_sha1_enc_ssse3:
|
||||
.cfi_startproc
|
||||
mov `($win64?56:8)`(%rsp),$inp # load 7th argument
|
||||
#shr \$6,$len # debugging artefact
|
||||
#jz .Lepilogue_ssse3 # debugging artefact
|
||||
push %rbx
|
||||
.cfi_push %rbx
|
||||
push %rbp
|
||||
.cfi_push %rbp
|
||||
push %r12
|
||||
.cfi_push %r12
|
||||
push %r13
|
||||
.cfi_push %r13
|
||||
push %r14
|
||||
.cfi_push %r14
|
||||
push %r15
|
||||
.cfi_push %r15
|
||||
lea `-104-($win64?10*16:0)`(%rsp),%rsp
|
||||
.cfi_adjust_cfa_offset `104+($win64?10*16:0)`
|
||||
#mov $in0,$inp # debugging artefact
|
||||
#lea 64(%rsp),$ctx # debugging artefact
|
||||
___
|
||||
@@ -726,15 +734,24 @@ $code.=<<___ if ($win64);
|
||||
___
|
||||
$code.=<<___;
|
||||
lea `104+($win64?10*16:0)`(%rsp),%rsi
|
||||
.cfi_def_cfa %rsi,56
|
||||
mov 0(%rsi),%r15
|
||||
.cfi_restore %r15
|
||||
mov 8(%rsi),%r14
|
||||
.cfi_restore %r14
|
||||
mov 16(%rsi),%r13
|
||||
.cfi_restore %r13
|
||||
mov 24(%rsi),%r12
|
||||
.cfi_restore %r12
|
||||
mov 32(%rsi),%rbp
|
||||
.cfi_restore %rbp
|
||||
mov 40(%rsi),%rbx
|
||||
.cfi_restore %rbx
|
||||
lea 48(%rsi),%rsp
|
||||
.cfi_def_cfa %rsp,8
|
||||
.Lepilogue_ssse3:
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aesni_cbc_sha1_enc_ssse3,.-aesni_cbc_sha1_enc_ssse3
|
||||
___
|
||||
|
||||
@@ -798,7 +815,7 @@ sub body_00_19_dec () { # ((c^d)&b)^d
|
||||
sub body_20_39_dec () { # b^d^c
|
||||
# on entry @T[0]=b^d
|
||||
return &body_40_59_dec() if ($rx==39);
|
||||
|
||||
|
||||
my @r=@body_20_39;
|
||||
|
||||
unshift (@r,@aes256_dec[$rx]) if (@aes256_dec[$rx]);
|
||||
@@ -842,14 +859,22 @@ $code.=<<___;
|
||||
.type aesni256_cbc_sha1_dec_ssse3,\@function,6
|
||||
.align 32
|
||||
aesni256_cbc_sha1_dec_ssse3:
|
||||
.cfi_startproc
|
||||
mov `($win64?56:8)`(%rsp),$inp # load 7th argument
|
||||
push %rbx
|
||||
.cfi_push %rbx
|
||||
push %rbp
|
||||
.cfi_push %rbp
|
||||
push %r12
|
||||
.cfi_push %r12
|
||||
push %r13
|
||||
.cfi_push %r13
|
||||
push %r14
|
||||
.cfi_push %r14
|
||||
push %r15
|
||||
.cfi_push %r15
|
||||
lea `-104-($win64?10*16:0)`(%rsp),%rsp
|
||||
.cfi_adjust_cfa_offset `104+($win64?10*16:0)`
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
movaps %xmm6,96+0(%rsp)
|
||||
@@ -997,15 +1022,24 @@ $code.=<<___ if ($win64);
|
||||
___
|
||||
$code.=<<___;
|
||||
lea `104+($win64?10*16:0)`(%rsp),%rsi
|
||||
.cfi_cfa_def %rsi,56
|
||||
mov 0(%rsi),%r15
|
||||
.cfi_restore %r15
|
||||
mov 8(%rsi),%r14
|
||||
.cfi_restore %r14
|
||||
mov 16(%rsi),%r13
|
||||
.cfi_restore %r13
|
||||
mov 24(%rsi),%r12
|
||||
.cfi_restore %r12
|
||||
mov 32(%rsi),%rbp
|
||||
.cfi_restore %rbp
|
||||
mov 40(%rsi),%rbx
|
||||
.cfi_restore %rbx
|
||||
lea 48(%rsi),%rsp
|
||||
.cfi_cfa_def %rsp,8
|
||||
.Lepilogue_dec_ssse3:
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aesni256_cbc_sha1_dec_ssse3,.-aesni256_cbc_sha1_dec_ssse3
|
||||
___
|
||||
}}}
|
||||
@@ -1031,16 +1065,24 @@ $code.=<<___;
|
||||
.type aesni_cbc_sha1_enc_avx,\@function,6
|
||||
.align 32
|
||||
aesni_cbc_sha1_enc_avx:
|
||||
.cfi_startproc
|
||||
mov `($win64?56:8)`(%rsp),$inp # load 7th argument
|
||||
#shr \$6,$len # debugging artefact
|
||||
#jz .Lepilogue_avx # debugging artefact
|
||||
push %rbx
|
||||
.cfi_push %rbx
|
||||
push %rbp
|
||||
.cfi_push %rbp
|
||||
push %r12
|
||||
.cfi_push %r12
|
||||
push %r13
|
||||
.cfi_push %r13
|
||||
push %r14
|
||||
.cfi_push %r14
|
||||
push %r15
|
||||
.cfi_push %r15
|
||||
lea `-104-($win64?10*16:0)`(%rsp),%rsp
|
||||
.cfi_adjust_cfa_offset `104+($win64?10*16:0)`
|
||||
#mov $in0,$inp # debugging artefact
|
||||
#lea 64(%rsp),$ctx # debugging artefact
|
||||
___
|
||||
@@ -1439,15 +1481,24 @@ $code.=<<___ if ($win64);
|
||||
___
|
||||
$code.=<<___;
|
||||
lea `104+($win64?10*16:0)`(%rsp),%rsi
|
||||
.cfi_def_cfa %rsi,56
|
||||
mov 0(%rsi),%r15
|
||||
.cfi_restore %r15
|
||||
mov 8(%rsi),%r14
|
||||
.cfi_restore %r14
|
||||
mov 16(%rsi),%r13
|
||||
.cfi_restore %r13
|
||||
mov 24(%rsi),%r12
|
||||
.cfi_restore %r12
|
||||
mov 32(%rsi),%rbp
|
||||
.cfi_restore %rbp
|
||||
mov 40(%rsi),%rbx
|
||||
.cfi_restore %rbx
|
||||
lea 48(%rsi),%rsp
|
||||
.cfi_def_cfa %rsp,8
|
||||
.Lepilogue_avx:
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aesni_cbc_sha1_enc_avx,.-aesni_cbc_sha1_enc_avx
|
||||
___
|
||||
|
||||
@@ -1496,14 +1547,22 @@ $code.=<<___;
|
||||
.type aesni256_cbc_sha1_dec_avx,\@function,6
|
||||
.align 32
|
||||
aesni256_cbc_sha1_dec_avx:
|
||||
.cfi_startproc
|
||||
mov `($win64?56:8)`(%rsp),$inp # load 7th argument
|
||||
push %rbx
|
||||
.cfi_push %rbx
|
||||
push %rbp
|
||||
.cfi_push %rbp
|
||||
push %r12
|
||||
.cfi_push %r12
|
||||
push %r13
|
||||
.cfi_push %r13
|
||||
push %r14
|
||||
.cfi_push %r14
|
||||
push %r15
|
||||
.cfi_push %r15
|
||||
lea `-104-($win64?10*16:0)`(%rsp),%rsp
|
||||
.cfi_adjust_cfa_offset `104+($win64?10*16:0)`
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
movaps %xmm6,96+0(%rsp)
|
||||
@@ -1650,15 +1709,24 @@ $code.=<<___ if ($win64);
|
||||
___
|
||||
$code.=<<___;
|
||||
lea `104+($win64?10*16:0)`(%rsp),%rsi
|
||||
.cfi_def_cfa %rsi,56
|
||||
mov 0(%rsi),%r15
|
||||
.cfi_restore %r15
|
||||
mov 8(%rsi),%r14
|
||||
.cfi_restore %r14
|
||||
mov 16(%rsi),%r13
|
||||
.cfi_restore %r13
|
||||
mov 24(%rsi),%r12
|
||||
.cfi_restore %r12
|
||||
mov 32(%rsi),%rbp
|
||||
.cfi_restore %rbp
|
||||
mov 40(%rsi),%rbx
|
||||
.cfi_restore %rbx
|
||||
lea 48(%rsi),%rsp
|
||||
.cfi_def_cfa %rsp,8
|
||||
.Lepilogue_dec_avx:
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aesni256_cbc_sha1_dec_avx,.-aesni256_cbc_sha1_dec_avx
|
||||
___
|
||||
}}}
|
||||
|
||||
@@ -112,7 +112,7 @@ $_key="16*$SZ+3*8(%rsp)";
|
||||
$_ivp="16*$SZ+4*8(%rsp)";
|
||||
$_ctx="16*$SZ+5*8(%rsp)";
|
||||
$_in0="16*$SZ+6*8(%rsp)";
|
||||
$_rsp="16*$SZ+7*8(%rsp)";
|
||||
$_rsp="`16*$SZ+7*8`(%rsp)";
|
||||
$framesz=16*$SZ+8*8;
|
||||
|
||||
$code=<<___;
|
||||
@@ -342,15 +342,23 @@ $code.=<<___;
|
||||
.type ${func}_xop,\@function,6
|
||||
.align 64
|
||||
${func}_xop:
|
||||
.cfi_startproc
|
||||
.Lxop_shortcut:
|
||||
mov `($win64?56:8)`(%rsp),$in0 # load 7th parameter
|
||||
mov %rsp,%rax # copy %rsp
|
||||
.cfi_def_cfa_register %rax
|
||||
push %rbx
|
||||
.cfi_push %rbx
|
||||
push %rbp
|
||||
.cfi_push %rbp
|
||||
push %r12
|
||||
.cfi_push %r12
|
||||
push %r13
|
||||
.cfi_push %r13
|
||||
push %r14
|
||||
.cfi_push %r14
|
||||
push %r15
|
||||
mov %rsp,%r11 # copy %rsp
|
||||
.cfi_push %r15
|
||||
sub \$`$framesz+$win64*16*10`,%rsp
|
||||
and \$-64,%rsp # align stack frame
|
||||
|
||||
@@ -366,7 +374,8 @@ ${func}_xop:
|
||||
mov $ivp,$_ivp
|
||||
mov $ctx,$_ctx
|
||||
mov $in0,$_in0
|
||||
mov %r11,$_rsp
|
||||
mov %rax,$_rsp
|
||||
.cfi_cfa_expression $_rsp,deref,+8
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
movaps %xmm6,`$framesz+16*0`(%rsp)
|
||||
@@ -604,6 +613,7 @@ $code.=<<___;
|
||||
|
||||
mov $_ivp,$ivp
|
||||
mov $_rsp,%rsi
|
||||
.cfi_def_cfa %rsi,8
|
||||
vmovdqu $iv,($ivp) # output IV
|
||||
vzeroall
|
||||
___
|
||||
@@ -620,15 +630,23 @@ $code.=<<___ if ($win64);
|
||||
movaps `$framesz+16*9`(%rsp),%xmm15
|
||||
___
|
||||
$code.=<<___;
|
||||
mov (%rsi),%r15
|
||||
mov 8(%rsi),%r14
|
||||
mov 16(%rsi),%r13
|
||||
mov 24(%rsi),%r12
|
||||
mov 32(%rsi),%rbp
|
||||
mov 40(%rsi),%rbx
|
||||
lea 48(%rsi),%rsp
|
||||
mov -48(%rsi),%r15
|
||||
.cfi_restore %r15
|
||||
mov -40(%rsi),%r14
|
||||
.cfi_restore %r14
|
||||
mov -32(%rsi),%r13
|
||||
.cfi_restore %r13
|
||||
mov -24(%rsi),%r12
|
||||
.cfi_restore %r12
|
||||
mov -16(%rsi),%rbp
|
||||
.cfi_restore %rbp
|
||||
mov -8(%rsi),%rbx
|
||||
.cfi_restore %rbx
|
||||
lea (%rsi),%rsp
|
||||
.cfi_def_cfa_register %rsp
|
||||
.Lepilogue_xop:
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size ${func}_xop,.-${func}_xop
|
||||
___
|
||||
######################################################################
|
||||
@@ -640,15 +658,23 @@ $code.=<<___;
|
||||
.type ${func}_avx,\@function,6
|
||||
.align 64
|
||||
${func}_avx:
|
||||
.cfi_startproc
|
||||
.Lavx_shortcut:
|
||||
mov `($win64?56:8)`(%rsp),$in0 # load 7th parameter
|
||||
mov %rsp,%rax # copy %rsp
|
||||
.cfi_def_cfa_register %rax
|
||||
push %rbx
|
||||
.cfi_push %rbx
|
||||
push %rbp
|
||||
.cfi_push %rbp
|
||||
push %r12
|
||||
.cfi_push %r12
|
||||
push %r13
|
||||
.cfi_push %r13
|
||||
push %r14
|
||||
.cfi_push %r14
|
||||
push %r15
|
||||
mov %rsp,%r11 # copy %rsp
|
||||
.cfi_push %r15
|
||||
sub \$`$framesz+$win64*16*10`,%rsp
|
||||
and \$-64,%rsp # align stack frame
|
||||
|
||||
@@ -664,7 +690,8 @@ ${func}_avx:
|
||||
mov $ivp,$_ivp
|
||||
mov $ctx,$_ctx
|
||||
mov $in0,$_in0
|
||||
mov %r11,$_rsp
|
||||
mov %rax,$_rsp
|
||||
.cfi_cfa_expression $_rsp,deref,+8
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
movaps %xmm6,`$framesz+16*0`(%rsp)
|
||||
@@ -855,6 +882,7 @@ $code.=<<___;
|
||||
|
||||
mov $_ivp,$ivp
|
||||
mov $_rsp,%rsi
|
||||
.cfi_def_cfa %rsi,8
|
||||
vmovdqu $iv,($ivp) # output IV
|
||||
vzeroall
|
||||
___
|
||||
@@ -871,15 +899,23 @@ $code.=<<___ if ($win64);
|
||||
movaps `$framesz+16*9`(%rsp),%xmm15
|
||||
___
|
||||
$code.=<<___;
|
||||
mov (%rsi),%r15
|
||||
mov 8(%rsi),%r14
|
||||
mov 16(%rsi),%r13
|
||||
mov 24(%rsi),%r12
|
||||
mov 32(%rsi),%rbp
|
||||
mov 40(%rsi),%rbx
|
||||
lea 48(%rsi),%rsp
|
||||
mov -48(%rsi),%r15
|
||||
.cfi_restore %r15
|
||||
mov -40(%rsi),%r14
|
||||
.cfi_restore %r14
|
||||
mov -32(%rsi),%r13
|
||||
.cfi_restore %r13
|
||||
mov -24(%rsi),%r12
|
||||
.cfi_restore %r12
|
||||
mov -16(%rsi),%rbp
|
||||
.cfi_restore %rbp
|
||||
mov -8(%rsi),%rbx
|
||||
.cfi_restore %rbx
|
||||
lea (%rsi),%rsp
|
||||
.cfi_def_cfa_register %rsp
|
||||
.Lepilogue_avx:
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size ${func}_avx,.-${func}_avx
|
||||
___
|
||||
|
||||
@@ -887,7 +923,7 @@ if ($avx>1) {{
|
||||
######################################################################
|
||||
# AVX2+BMI code path
|
||||
#
|
||||
my $a5=$SZ==4?"%esi":"%rsi"; # zap $inp
|
||||
my $a5=$SZ==4?"%esi":"%rsi"; # zap $inp
|
||||
my $PUSH8=8*2*$SZ;
|
||||
use integer;
|
||||
|
||||
@@ -936,15 +972,23 @@ $code.=<<___;
|
||||
.type ${func}_avx2,\@function,6
|
||||
.align 64
|
||||
${func}_avx2:
|
||||
.cfi_startproc
|
||||
.Lavx2_shortcut:
|
||||
mov `($win64?56:8)`(%rsp),$in0 # load 7th parameter
|
||||
mov %rsp,%rax # copy %rsp
|
||||
.cfi_def_cfa_register %rax
|
||||
push %rbx
|
||||
.cfi_push %rbx
|
||||
push %rbp
|
||||
.cfi_push %rbp
|
||||
push %r12
|
||||
.cfi_push %r12
|
||||
push %r13
|
||||
.cfi_push %r13
|
||||
push %r14
|
||||
.cfi_push %r14
|
||||
push %r15
|
||||
mov %rsp,%r11 # copy %rsp
|
||||
.cfi_push %r15
|
||||
sub \$`2*$SZ*$rounds+8*8+$win64*16*10`,%rsp
|
||||
and \$-256*$SZ,%rsp # align stack frame
|
||||
add \$`2*$SZ*($rounds-8)`,%rsp
|
||||
@@ -961,7 +1005,8 @@ ${func}_avx2:
|
||||
mov $ivp,$_ivp
|
||||
mov $ctx,$_ctx
|
||||
mov $in0,$_in0
|
||||
mov %r11,$_rsp
|
||||
mov %rax,$_rsp
|
||||
.cfi_cfa_expression $_rsp,deref,+8
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
movaps %xmm6,`$framesz+16*0`(%rsp)
|
||||
@@ -1192,6 +1237,7 @@ $code.=<<___;
|
||||
lea ($Tbl),%rsp
|
||||
mov $_ivp,$ivp
|
||||
mov $_rsp,%rsi
|
||||
.cfi_def_cfa %rsi,8
|
||||
vmovdqu $iv,($ivp) # output IV
|
||||
vzeroall
|
||||
___
|
||||
@@ -1208,15 +1254,23 @@ $code.=<<___ if ($win64);
|
||||
movaps `$framesz+16*9`(%rsp),%xmm15
|
||||
___
|
||||
$code.=<<___;
|
||||
mov (%rsi),%r15
|
||||
mov 8(%rsi),%r14
|
||||
mov 16(%rsi),%r13
|
||||
mov 24(%rsi),%r12
|
||||
mov 32(%rsi),%rbp
|
||||
mov 40(%rsi),%rbx
|
||||
lea 48(%rsi),%rsp
|
||||
mov -48(%rsi),%r15
|
||||
.cfi_restore %r15
|
||||
mov -40(%rsi),%r14
|
||||
.cfi_restore %r14
|
||||
mov -32(%rsi),%r13
|
||||
.cfi_restore %r13
|
||||
mov -24(%rsi),%r12
|
||||
.cfi_restore %r12
|
||||
mov -16(%rsi),%rbp
|
||||
.cfi_restore %rbp
|
||||
mov -8(%rsi),%rbx
|
||||
.cfi_restore %rbx
|
||||
lea (%rsi),%rsp
|
||||
.cfi_def_cfa_register %rsp
|
||||
.Lepilogue_avx2:
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size ${func}_avx2,.-${func}_avx2
|
||||
___
|
||||
}}
|
||||
@@ -1573,7 +1627,6 @@ ___
|
||||
$code.=<<___;
|
||||
mov %rax,%rsi # put aside Rsp
|
||||
mov 16*$SZ+7*8(%rax),%rax # pull $_rsp
|
||||
lea 48(%rax),%rax
|
||||
|
||||
mov -8(%rax),%rbx
|
||||
mov -16(%rax),%rbp
|
||||
|
||||
@@ -62,7 +62,9 @@
|
||||
# Westmere 3.77/1.37 1.37 1.52 1.27
|
||||
# * Bridge 5.07/0.98 0.99 1.09 0.91 1.10
|
||||
# Haswell 4.44/0.80 0.97 1.03 0.72 0.76
|
||||
# Skylake 2.68/0.65 0.65 0.66 0.64 0.66
|
||||
# Silvermont 5.77/3.56 3.67 4.03 3.46 4.03
|
||||
# Goldmont 3.84/1.39 1.39 1.63 1.31 1.70
|
||||
# Bulldozer 5.80/0.98 1.05 1.24 0.93 1.23
|
||||
|
||||
$PREFIX="aesni"; # if $PREFIX is set to "AES", the script
|
||||
@@ -78,7 +80,7 @@ $output = pop;
|
||||
open OUT,">$output";
|
||||
*STDOUT=*OUT;
|
||||
|
||||
&asm_init($ARGV[0],$0);
|
||||
&asm_init($ARGV[0]);
|
||||
|
||||
&external_label("OPENSSL_ia32cap_P");
|
||||
&static_label("key_const");
|
||||
@@ -237,7 +239,7 @@ sub aesni_generate1 # fully unrolled loop
|
||||
# can schedule aes[enc|dec] every cycle optimal interleave factor
|
||||
# equals to corresponding instructions latency. 8x is optimal for
|
||||
# * Bridge, but it's unfeasible to accommodate such implementation
|
||||
# in XMM registers addreassable in 32-bit mode and therefore maximum
|
||||
# in XMM registers addressable in 32-bit mode and therefore maximum
|
||||
# of 6x is used instead...
|
||||
|
||||
sub aesni_generate2
|
||||
@@ -1051,7 +1053,7 @@ if ($PREFIX eq "aesni") {
|
||||
&set_label("ctr32_one_shortcut",16);
|
||||
&movups ($inout0,&QWP(0,$rounds_)); # load ivec
|
||||
&mov ($rounds,&DWP(240,$key));
|
||||
|
||||
|
||||
&set_label("ctr32_one");
|
||||
if ($inline)
|
||||
{ &aesni_inline_generate1("enc"); }
|
||||
|
||||
+217
-152
@@ -34,7 +34,7 @@
|
||||
# ECB 4.25/4.25 1.38/1.38 1.28/1.28 1.26/1.26 1.26/1.26
|
||||
# CTR 5.42/5.42 1.92/1.92 1.44/1.44 1.28/1.28 1.26/1.26
|
||||
# CBC 4.38/4.43 4.15/1.43 4.07/1.32 4.07/1.29 4.06/1.28
|
||||
# CCM 5.66/9.42 4.42/5.41 4.16/4.40 4.09/4.15 4.06/4.07
|
||||
# CCM 5.66/9.42 4.42/5.41 4.16/4.40 4.09/4.15 4.06/4.07
|
||||
# OFB 5.42/5.42 4.64/4.64 4.44/4.44 4.39/4.39 4.38/4.38
|
||||
# CFB 5.73/5.85 5.56/5.62 5.48/5.56 5.47/5.55 5.47/5.55
|
||||
#
|
||||
@@ -60,7 +60,7 @@
|
||||
# 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
|
||||
# "straghtforward" CCM implementation with CTR and CBC-MAC performed
|
||||
# "straightforward" CCM implementation with CTR and CBC-MAC performed
|
||||
# disjointly. Parallelizable modes practically achieve the theoretical
|
||||
# limit.
|
||||
#
|
||||
@@ -118,7 +118,7 @@
|
||||
# performance is achieved by interleaving instructions working on
|
||||
# independent blocks. In which case asymptotic limit for such modes
|
||||
# can be obtained by dividing above mentioned numbers by AES
|
||||
# instructions' interleave factor. Westmere can execute at most 3
|
||||
# instructions' interleave factor. Westmere can execute at most 3
|
||||
# instructions at a time, meaning that optimal interleave factor is 3,
|
||||
# and that's where the "magic" number of 1.25 come from. "Optimal
|
||||
# interleave factor" means that increase of interleave factor does
|
||||
@@ -143,14 +143,14 @@
|
||||
# asymptotic, if it can be surpassed, isn't it? What happens there?
|
||||
# Rewind to CBC paragraph for the answer. Yes, out-of-order execution
|
||||
# magic is responsible for this. Processor overlaps not only the
|
||||
# additional instructions with AES ones, but even AES instuctions
|
||||
# additional instructions with AES ones, but even AES instructions
|
||||
# processing adjacent triplets of independent blocks. In the 6x case
|
||||
# additional instructions still claim disproportionally small amount
|
||||
# of additional cycles, but in 8x case number of instructions must be
|
||||
# a tad too high for out-of-order logic to cope with, and AES unit
|
||||
# remains underutilized... As you can see 8x interleave is hardly
|
||||
# justifiable, so there no need to feel bad that 32-bit aesni-x86.pl
|
||||
# utilizies 6x interleave because of limited register bank capacity.
|
||||
# utilizes 6x interleave because of limited register bank capacity.
|
||||
#
|
||||
# Higher interleave factors do have negative impact on Westmere
|
||||
# performance. While for ECB mode it's negligible ~1.5%, other
|
||||
@@ -179,8 +179,10 @@
|
||||
# Haswell 4.44/0.63 0.63 0.73 0.63 0.70
|
||||
# Skylake 2.62/0.63 0.63 0.63 0.63
|
||||
# Silvermont 5.75/3.54 3.56 4.12 3.87(*) 4.11
|
||||
# Knights L 2.54/0.77 0.78 0.85 - 1.50
|
||||
# Goldmont 3.82/1.26 1.26 1.29 1.29 1.50
|
||||
# Bulldozer 5.77/0.70 0.72 0.90 0.70 0.95
|
||||
# Ryzen 2.71/0.35 0.35 0.44 0.38 0.49
|
||||
#
|
||||
# (*) Atom Silvermont ECB result is suboptimal because of penalties
|
||||
# incurred by operations on %xmm8-15. As ECB is not considered
|
||||
@@ -313,7 +315,7 @@ ___
|
||||
# on 2x subroutine on Atom Silvermont account. For processors that
|
||||
# can schedule aes[enc|dec] every cycle optimal interleave factor
|
||||
# equals to corresponding instructions latency. 8x is optimal for
|
||||
# * Bridge and "super-optimal" for other Intel CPUs...
|
||||
# * Bridge and "super-optimal" for other Intel CPUs...
|
||||
|
||||
sub aesni_generate2 {
|
||||
my $dir=shift;
|
||||
@@ -1172,7 +1174,7 @@ ___
|
||||
# with zero-round key xor.
|
||||
{
|
||||
my ($in0,$in1,$in2,$in3,$in4,$in5)=map("%xmm$_",(10..15));
|
||||
my ($key0,$ctr)=("${key_}d","${ivp}d");
|
||||
my ($key0,$ctr)=("%ebp","${ivp}d");
|
||||
my $frame_size = 0x80 + ($win64?160:0);
|
||||
|
||||
$code.=<<___;
|
||||
@@ -1180,6 +1182,7 @@ $code.=<<___;
|
||||
.type aesni_ctr32_encrypt_blocks,\@function,5
|
||||
.align 16
|
||||
aesni_ctr32_encrypt_blocks:
|
||||
.cfi_startproc
|
||||
cmp \$1,$len
|
||||
jne .Lctr32_bulk
|
||||
|
||||
@@ -1201,26 +1204,27 @@ $code.=<<___;
|
||||
|
||||
.align 16
|
||||
.Lctr32_bulk:
|
||||
lea (%rsp),%rax
|
||||
lea (%rsp),$key_ # use $key_ as frame pointer
|
||||
.cfi_def_cfa_register $key_
|
||||
push %rbp
|
||||
.cfi_push %rbp
|
||||
sub \$$frame_size,%rsp
|
||||
and \$-16,%rsp # Linux kernel stack can be incorrectly seeded
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
movaps %xmm6,-0xa8(%rax) # offload everything
|
||||
movaps %xmm7,-0x98(%rax)
|
||||
movaps %xmm8,-0x88(%rax)
|
||||
movaps %xmm9,-0x78(%rax)
|
||||
movaps %xmm10,-0x68(%rax)
|
||||
movaps %xmm11,-0x58(%rax)
|
||||
movaps %xmm12,-0x48(%rax)
|
||||
movaps %xmm13,-0x38(%rax)
|
||||
movaps %xmm14,-0x28(%rax)
|
||||
movaps %xmm15,-0x18(%rax)
|
||||
movaps %xmm6,-0xa8($key_) # offload everything
|
||||
movaps %xmm7,-0x98($key_)
|
||||
movaps %xmm8,-0x88($key_)
|
||||
movaps %xmm9,-0x78($key_)
|
||||
movaps %xmm10,-0x68($key_)
|
||||
movaps %xmm11,-0x58($key_)
|
||||
movaps %xmm12,-0x48($key_)
|
||||
movaps %xmm13,-0x38($key_)
|
||||
movaps %xmm14,-0x28($key_)
|
||||
movaps %xmm15,-0x18($key_)
|
||||
.Lctr32_body:
|
||||
___
|
||||
$code.=<<___;
|
||||
lea -8(%rax),%rbp
|
||||
|
||||
# 8 16-byte words on top of stack are counter values
|
||||
# xor-ed with zero-round key
|
||||
@@ -1272,7 +1276,7 @@ $code.=<<___;
|
||||
lea 7($ctr),%r9
|
||||
mov %r10d,0x60+12(%rsp)
|
||||
bswap %r9d
|
||||
mov OPENSSL_ia32cap_P+4(%rip),%r10d
|
||||
mov OPENSSL_ia32cap_P+4(%rip),%r10d
|
||||
xor $key0,%r9d
|
||||
and \$`1<<26|1<<22`,%r10d # isolate XSAVE+MOVBE
|
||||
mov %r9d,0x70+12(%rsp)
|
||||
@@ -1546,13 +1550,13 @@ $code.=<<___;
|
||||
sub \$8,$len
|
||||
jnc .Lctr32_loop8 # loop if $len-=8 didn't borrow
|
||||
|
||||
add \$8,$len # restore real remainig $len
|
||||
add \$8,$len # restore real remaining $len
|
||||
jz .Lctr32_done # done if ($len==0)
|
||||
lea -0x80($key),$key
|
||||
|
||||
.Lctr32_tail:
|
||||
# note that at this point $inout0..5 are populated with
|
||||
# counter values xor-ed with 0-round key
|
||||
# counter values xor-ed with 0-round key
|
||||
lea 16($key),$key
|
||||
cmp \$4,$len
|
||||
jb .Lctr32_loop3
|
||||
@@ -1663,7 +1667,7 @@ $code.=<<___;
|
||||
movups $inout2,0x20($out) # $len was 3, stop store
|
||||
|
||||
.Lctr32_done:
|
||||
xorps %xmm0,%xmm0 # clear regiser bank
|
||||
xorps %xmm0,%xmm0 # clear register bank
|
||||
xor $key0,$key0
|
||||
pxor %xmm1,%xmm1
|
||||
pxor %xmm2,%xmm2
|
||||
@@ -1692,26 +1696,26 @@ $code.=<<___ if (!$win64);
|
||||
pxor %xmm15,%xmm15
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
movaps -0xa0(%rbp),%xmm6
|
||||
movaps %xmm0,-0xa0(%rbp) # clear stack
|
||||
movaps -0x90(%rbp),%xmm7
|
||||
movaps %xmm0,-0x90(%rbp)
|
||||
movaps -0x80(%rbp),%xmm8
|
||||
movaps %xmm0,-0x80(%rbp)
|
||||
movaps -0x70(%rbp),%xmm9
|
||||
movaps %xmm0,-0x70(%rbp)
|
||||
movaps -0x60(%rbp),%xmm10
|
||||
movaps %xmm0,-0x60(%rbp)
|
||||
movaps -0x50(%rbp),%xmm11
|
||||
movaps %xmm0,-0x50(%rbp)
|
||||
movaps -0x40(%rbp),%xmm12
|
||||
movaps %xmm0,-0x40(%rbp)
|
||||
movaps -0x30(%rbp),%xmm13
|
||||
movaps %xmm0,-0x30(%rbp)
|
||||
movaps -0x20(%rbp),%xmm14
|
||||
movaps %xmm0,-0x20(%rbp)
|
||||
movaps -0x10(%rbp),%xmm15
|
||||
movaps %xmm0,-0x10(%rbp)
|
||||
movaps -0xa8($key_),%xmm6
|
||||
movaps %xmm0,-0xa8($key_) # clear stack
|
||||
movaps -0x98($key_),%xmm7
|
||||
movaps %xmm0,-0x98($key_)
|
||||
movaps -0x88($key_),%xmm8
|
||||
movaps %xmm0,-0x88($key_)
|
||||
movaps -0x78($key_),%xmm9
|
||||
movaps %xmm0,-0x78($key_)
|
||||
movaps -0x68($key_),%xmm10
|
||||
movaps %xmm0,-0x68($key_)
|
||||
movaps -0x58($key_),%xmm11
|
||||
movaps %xmm0,-0x58($key_)
|
||||
movaps -0x48($key_),%xmm12
|
||||
movaps %xmm0,-0x48($key_)
|
||||
movaps -0x38($key_),%xmm13
|
||||
movaps %xmm0,-0x38($key_)
|
||||
movaps -0x28($key_),%xmm14
|
||||
movaps %xmm0,-0x28($key_)
|
||||
movaps -0x18($key_),%xmm15
|
||||
movaps %xmm0,-0x18($key_)
|
||||
movaps %xmm0,0x00(%rsp)
|
||||
movaps %xmm0,0x10(%rsp)
|
||||
movaps %xmm0,0x20(%rsp)
|
||||
@@ -1722,10 +1726,13 @@ $code.=<<___ if ($win64);
|
||||
movaps %xmm0,0x70(%rsp)
|
||||
___
|
||||
$code.=<<___;
|
||||
lea (%rbp),%rsp
|
||||
pop %rbp
|
||||
mov -8($key_),%rbp
|
||||
.cfi_restore %rbp
|
||||
lea ($key_),%rsp
|
||||
.cfi_def_cfa_register %rsp
|
||||
.Lctr32_epilogue:
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aesni_ctr32_encrypt_blocks,.-aesni_ctr32_encrypt_blocks
|
||||
___
|
||||
}
|
||||
@@ -1740,32 +1747,35 @@ my @tweak=map("%xmm$_",(10..15));
|
||||
my ($twmask,$twres,$twtmp)=("%xmm8","%xmm9",@tweak[4]);
|
||||
my ($key2,$ivp,$len_)=("%r8","%r9","%r9");
|
||||
my $frame_size = 0x70 + ($win64?160:0);
|
||||
my $key_ = "%rbp"; # override so that we can use %r11 as FP
|
||||
|
||||
$code.=<<___;
|
||||
.globl aesni_xts_encrypt
|
||||
.type aesni_xts_encrypt,\@function,6
|
||||
.align 16
|
||||
aesni_xts_encrypt:
|
||||
lea (%rsp),%rax
|
||||
.cfi_startproc
|
||||
lea (%rsp),%r11 # frame pointer
|
||||
.cfi_def_cfa_register %r11
|
||||
push %rbp
|
||||
.cfi_push %rbp
|
||||
sub \$$frame_size,%rsp
|
||||
and \$-16,%rsp # Linux kernel stack can be incorrectly seeded
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
movaps %xmm6,-0xa8(%rax) # offload everything
|
||||
movaps %xmm7,-0x98(%rax)
|
||||
movaps %xmm8,-0x88(%rax)
|
||||
movaps %xmm9,-0x78(%rax)
|
||||
movaps %xmm10,-0x68(%rax)
|
||||
movaps %xmm11,-0x58(%rax)
|
||||
movaps %xmm12,-0x48(%rax)
|
||||
movaps %xmm13,-0x38(%rax)
|
||||
movaps %xmm14,-0x28(%rax)
|
||||
movaps %xmm15,-0x18(%rax)
|
||||
movaps %xmm6,-0xa8(%r11) # offload everything
|
||||
movaps %xmm7,-0x98(%r11)
|
||||
movaps %xmm8,-0x88(%r11)
|
||||
movaps %xmm9,-0x78(%r11)
|
||||
movaps %xmm10,-0x68(%r11)
|
||||
movaps %xmm11,-0x58(%r11)
|
||||
movaps %xmm12,-0x48(%r11)
|
||||
movaps %xmm13,-0x38(%r11)
|
||||
movaps %xmm14,-0x28(%r11)
|
||||
movaps %xmm15,-0x18(%r11)
|
||||
.Lxts_enc_body:
|
||||
___
|
||||
$code.=<<___;
|
||||
lea -8(%rax),%rbp
|
||||
movups ($ivp),$inout0 # load clear-text tweak
|
||||
mov 240(%r8),$rounds # key2->rounds
|
||||
mov 240($key),$rnds_ # key1->rounds
|
||||
@@ -1846,7 +1856,7 @@ $code.=<<___;
|
||||
lea `16*6`($inp),$inp
|
||||
pxor $twmask,$inout5
|
||||
|
||||
pxor $twres,@tweak[0] # calclulate tweaks^round[last]
|
||||
pxor $twres,@tweak[0] # calculate tweaks^round[last]
|
||||
aesenc $rndkey1,$inout4
|
||||
pxor $twres,@tweak[1]
|
||||
movdqa @tweak[0],`16*0`(%rsp) # put aside tweaks^round[last]
|
||||
@@ -2183,26 +2193,26 @@ $code.=<<___ if (!$win64);
|
||||
pxor %xmm15,%xmm15
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
movaps -0xa0(%rbp),%xmm6
|
||||
movaps %xmm0,-0xa0(%rbp) # clear stack
|
||||
movaps -0x90(%rbp),%xmm7
|
||||
movaps %xmm0,-0x90(%rbp)
|
||||
movaps -0x80(%rbp),%xmm8
|
||||
movaps %xmm0,-0x80(%rbp)
|
||||
movaps -0x70(%rbp),%xmm9
|
||||
movaps %xmm0,-0x70(%rbp)
|
||||
movaps -0x60(%rbp),%xmm10
|
||||
movaps %xmm0,-0x60(%rbp)
|
||||
movaps -0x50(%rbp),%xmm11
|
||||
movaps %xmm0,-0x50(%rbp)
|
||||
movaps -0x40(%rbp),%xmm12
|
||||
movaps %xmm0,-0x40(%rbp)
|
||||
movaps -0x30(%rbp),%xmm13
|
||||
movaps %xmm0,-0x30(%rbp)
|
||||
movaps -0x20(%rbp),%xmm14
|
||||
movaps %xmm0,-0x20(%rbp)
|
||||
movaps -0x10(%rbp),%xmm15
|
||||
movaps %xmm0,-0x10(%rbp)
|
||||
movaps -0xa8(%r11),%xmm6
|
||||
movaps %xmm0,-0xa8(%r11) # clear stack
|
||||
movaps -0x98(%r11),%xmm7
|
||||
movaps %xmm0,-0x98(%r11)
|
||||
movaps -0x88(%r11),%xmm8
|
||||
movaps %xmm0,-0x88(%r11)
|
||||
movaps -0x78(%r11),%xmm9
|
||||
movaps %xmm0,-0x78(%r11)
|
||||
movaps -0x68(%r11),%xmm10
|
||||
movaps %xmm0,-0x68(%r11)
|
||||
movaps -0x58(%r11),%xmm11
|
||||
movaps %xmm0,-0x58(%r11)
|
||||
movaps -0x48(%r11),%xmm12
|
||||
movaps %xmm0,-0x48(%r11)
|
||||
movaps -0x38(%r11),%xmm13
|
||||
movaps %xmm0,-0x38(%r11)
|
||||
movaps -0x28(%r11),%xmm14
|
||||
movaps %xmm0,-0x28(%r11)
|
||||
movaps -0x18(%r11),%xmm15
|
||||
movaps %xmm0,-0x18(%r11)
|
||||
movaps %xmm0,0x00(%rsp)
|
||||
movaps %xmm0,0x10(%rsp)
|
||||
movaps %xmm0,0x20(%rsp)
|
||||
@@ -2212,10 +2222,13 @@ $code.=<<___ if ($win64);
|
||||
movaps %xmm0,0x60(%rsp)
|
||||
___
|
||||
$code.=<<___;
|
||||
lea (%rbp),%rsp
|
||||
pop %rbp
|
||||
mov -8(%r11),%rbp
|
||||
.cfi_restore %rbp
|
||||
lea (%r11),%rsp
|
||||
.cfi_def_cfa_register %rsp
|
||||
.Lxts_enc_epilogue:
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aesni_xts_encrypt,.-aesni_xts_encrypt
|
||||
___
|
||||
|
||||
@@ -2224,26 +2237,28 @@ $code.=<<___;
|
||||
.type aesni_xts_decrypt,\@function,6
|
||||
.align 16
|
||||
aesni_xts_decrypt:
|
||||
lea (%rsp),%rax
|
||||
.cfi_startproc
|
||||
lea (%rsp),%r11 # frame pointer
|
||||
.cfi_def_cfa_register %r11
|
||||
push %rbp
|
||||
.cfi_push %rbp
|
||||
sub \$$frame_size,%rsp
|
||||
and \$-16,%rsp # Linux kernel stack can be incorrectly seeded
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
movaps %xmm6,-0xa8(%rax) # offload everything
|
||||
movaps %xmm7,-0x98(%rax)
|
||||
movaps %xmm8,-0x88(%rax)
|
||||
movaps %xmm9,-0x78(%rax)
|
||||
movaps %xmm10,-0x68(%rax)
|
||||
movaps %xmm11,-0x58(%rax)
|
||||
movaps %xmm12,-0x48(%rax)
|
||||
movaps %xmm13,-0x38(%rax)
|
||||
movaps %xmm14,-0x28(%rax)
|
||||
movaps %xmm15,-0x18(%rax)
|
||||
movaps %xmm6,-0xa8(%r11) # offload everything
|
||||
movaps %xmm7,-0x98(%r11)
|
||||
movaps %xmm8,-0x88(%r11)
|
||||
movaps %xmm9,-0x78(%r11)
|
||||
movaps %xmm10,-0x68(%r11)
|
||||
movaps %xmm11,-0x58(%r11)
|
||||
movaps %xmm12,-0x48(%r11)
|
||||
movaps %xmm13,-0x38(%r11)
|
||||
movaps %xmm14,-0x28(%r11)
|
||||
movaps %xmm15,-0x18(%r11)
|
||||
.Lxts_dec_body:
|
||||
___
|
||||
$code.=<<___;
|
||||
lea -8(%rax),%rbp
|
||||
movups ($ivp),$inout0 # load clear-text tweak
|
||||
mov 240($key2),$rounds # key2->rounds
|
||||
mov 240($key),$rnds_ # key1->rounds
|
||||
@@ -2327,7 +2342,7 @@ $code.=<<___;
|
||||
lea `16*6`($inp),$inp
|
||||
pxor $twmask,$inout5
|
||||
|
||||
pxor $twres,@tweak[0] # calclulate tweaks^round[last]
|
||||
pxor $twres,@tweak[0] # calculate tweaks^round[last]
|
||||
aesdec $rndkey1,$inout4
|
||||
pxor $twres,@tweak[1]
|
||||
movdqa @tweak[0],`16*0`(%rsp) # put aside tweaks^last round key
|
||||
@@ -2687,26 +2702,26 @@ $code.=<<___ if (!$win64);
|
||||
pxor %xmm15,%xmm15
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
movaps -0xa0(%rbp),%xmm6
|
||||
movaps %xmm0,-0xa0(%rbp) # clear stack
|
||||
movaps -0x90(%rbp),%xmm7
|
||||
movaps %xmm0,-0x90(%rbp)
|
||||
movaps -0x80(%rbp),%xmm8
|
||||
movaps %xmm0,-0x80(%rbp)
|
||||
movaps -0x70(%rbp),%xmm9
|
||||
movaps %xmm0,-0x70(%rbp)
|
||||
movaps -0x60(%rbp),%xmm10
|
||||
movaps %xmm0,-0x60(%rbp)
|
||||
movaps -0x50(%rbp),%xmm11
|
||||
movaps %xmm0,-0x50(%rbp)
|
||||
movaps -0x40(%rbp),%xmm12
|
||||
movaps %xmm0,-0x40(%rbp)
|
||||
movaps -0x30(%rbp),%xmm13
|
||||
movaps %xmm0,-0x30(%rbp)
|
||||
movaps -0x20(%rbp),%xmm14
|
||||
movaps %xmm0,-0x20(%rbp)
|
||||
movaps -0x10(%rbp),%xmm15
|
||||
movaps %xmm0,-0x10(%rbp)
|
||||
movaps -0xa8(%r11),%xmm6
|
||||
movaps %xmm0,-0xa8(%r11) # clear stack
|
||||
movaps -0x98(%r11),%xmm7
|
||||
movaps %xmm0,-0x98(%r11)
|
||||
movaps -0x88(%r11),%xmm8
|
||||
movaps %xmm0,-0x88(%r11)
|
||||
movaps -0x78(%r11),%xmm9
|
||||
movaps %xmm0,-0x78(%r11)
|
||||
movaps -0x68(%r11),%xmm10
|
||||
movaps %xmm0,-0x68(%r11)
|
||||
movaps -0x58(%r11),%xmm11
|
||||
movaps %xmm0,-0x58(%r11)
|
||||
movaps -0x48(%r11),%xmm12
|
||||
movaps %xmm0,-0x48(%r11)
|
||||
movaps -0x38(%r11),%xmm13
|
||||
movaps %xmm0,-0x38(%r11)
|
||||
movaps -0x28(%r11),%xmm14
|
||||
movaps %xmm0,-0x28(%r11)
|
||||
movaps -0x18(%r11),%xmm15
|
||||
movaps %xmm0,-0x18(%r11)
|
||||
movaps %xmm0,0x00(%rsp)
|
||||
movaps %xmm0,0x10(%rsp)
|
||||
movaps %xmm0,0x20(%rsp)
|
||||
@@ -2716,10 +2731,13 @@ $code.=<<___ if ($win64);
|
||||
movaps %xmm0,0x60(%rsp)
|
||||
___
|
||||
$code.=<<___;
|
||||
lea (%rbp),%rsp
|
||||
pop %rbp
|
||||
mov -8(%r11),%rbp
|
||||
.cfi_restore %rbp
|
||||
lea (%r11),%rsp
|
||||
.cfi_def_cfa_register %rsp
|
||||
.Lxts_dec_epilogue:
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aesni_xts_decrypt,.-aesni_xts_decrypt
|
||||
___
|
||||
}
|
||||
@@ -2744,12 +2762,18 @@ $code.=<<___;
|
||||
.type aesni_ocb_encrypt,\@function,6
|
||||
.align 32
|
||||
aesni_ocb_encrypt:
|
||||
.cfi_startproc
|
||||
lea (%rsp),%rax
|
||||
push %rbx
|
||||
.cfi_push %rbx
|
||||
push %rbp
|
||||
.cfi_push %rbp
|
||||
push %r12
|
||||
.cfi_push %r12
|
||||
push %r13
|
||||
.cfi_push %r13
|
||||
push %r14
|
||||
.cfi_push %r14
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
lea -0xa0(%rsp),%rsp
|
||||
@@ -2943,6 +2967,8 @@ $code.=<<___ if (!$win64);
|
||||
pxor %xmm13,%xmm13
|
||||
pxor %xmm14,%xmm14
|
||||
pxor %xmm15,%xmm15
|
||||
lea 0x28(%rsp),%rax
|
||||
.cfi_def_cfa %rax,8
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
movaps 0x00(%rsp),%xmm6
|
||||
@@ -2967,16 +2993,23 @@ $code.=<<___ if ($win64);
|
||||
movaps %xmm0,0x90(%rsp)
|
||||
lea 0xa0+0x28(%rsp),%rax
|
||||
.Locb_enc_pop:
|
||||
lea 0xa0(%rsp),%rsp
|
||||
___
|
||||
$code.=<<___;
|
||||
pop %r14
|
||||
pop %r13
|
||||
pop %r12
|
||||
pop %rbp
|
||||
pop %rbx
|
||||
mov -40(%rax),%r14
|
||||
.cfi_restore %r14
|
||||
mov -32(%rax),%r13
|
||||
.cfi_restore %r13
|
||||
mov -24(%rax),%r12
|
||||
.cfi_restore %r12
|
||||
mov -16(%rax),%rbp
|
||||
.cfi_restore %rbp
|
||||
mov -8(%rax),%rbx
|
||||
.cfi_restore %rbx
|
||||
lea (%rax),%rsp
|
||||
.cfi_def_cfa_register %rsp
|
||||
.Locb_enc_epilogue:
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aesni_ocb_encrypt,.-aesni_ocb_encrypt
|
||||
|
||||
.type __ocb_encrypt6,\@abi-omnipotent
|
||||
@@ -3189,12 +3222,18 @@ __ocb_encrypt1:
|
||||
.type aesni_ocb_decrypt,\@function,6
|
||||
.align 32
|
||||
aesni_ocb_decrypt:
|
||||
.cfi_startproc
|
||||
lea (%rsp),%rax
|
||||
push %rbx
|
||||
.cfi_push %rbx
|
||||
push %rbp
|
||||
.cfi_push %rbp
|
||||
push %r12
|
||||
.cfi_push %r12
|
||||
push %r13
|
||||
.cfi_push %r13
|
||||
push %r14
|
||||
.cfi_push %r14
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
lea -0xa0(%rsp),%rsp
|
||||
@@ -3410,6 +3449,8 @@ $code.=<<___ if (!$win64);
|
||||
pxor %xmm13,%xmm13
|
||||
pxor %xmm14,%xmm14
|
||||
pxor %xmm15,%xmm15
|
||||
lea 0x28(%rsp),%rax
|
||||
.cfi_def_cfa %rax,8
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
movaps 0x00(%rsp),%xmm6
|
||||
@@ -3434,16 +3475,23 @@ $code.=<<___ if ($win64);
|
||||
movaps %xmm0,0x90(%rsp)
|
||||
lea 0xa0+0x28(%rsp),%rax
|
||||
.Locb_dec_pop:
|
||||
lea 0xa0(%rsp),%rsp
|
||||
___
|
||||
$code.=<<___;
|
||||
pop %r14
|
||||
pop %r13
|
||||
pop %r12
|
||||
pop %rbp
|
||||
pop %rbx
|
||||
mov -40(%rax),%r14
|
||||
.cfi_restore %r14
|
||||
mov -32(%rax),%r13
|
||||
.cfi_restore %r13
|
||||
mov -24(%rax),%r12
|
||||
.cfi_restore %r12
|
||||
mov -16(%rax),%rbp
|
||||
.cfi_restore %rbp
|
||||
mov -8(%rax),%rbx
|
||||
.cfi_restore %rbx
|
||||
lea (%rax),%rsp
|
||||
.cfi_def_cfa_register %rsp
|
||||
.Locb_dec_epilogue:
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aesni_ocb_decrypt,.-aesni_ocb_decrypt
|
||||
|
||||
.type __ocb_decrypt6,\@abi-omnipotent
|
||||
@@ -3650,13 +3698,13 @@ ___
|
||||
{
|
||||
my $frame_size = 0x10 + ($win64?0xa0:0); # used in decrypt
|
||||
my ($iv,$in0,$in1,$in2,$in3,$in4)=map("%xmm$_",(10..15));
|
||||
my $inp_=$key_;
|
||||
|
||||
$code.=<<___;
|
||||
.globl ${PREFIX}_cbc_encrypt
|
||||
.type ${PREFIX}_cbc_encrypt,\@function,6
|
||||
.align 16
|
||||
${PREFIX}_cbc_encrypt:
|
||||
.cfi_startproc
|
||||
test $len,$len # check length
|
||||
jz .Lcbc_ret
|
||||
|
||||
@@ -3732,8 +3780,10 @@ $code.=<<___;
|
||||
jmp .Lcbc_ret
|
||||
.align 16
|
||||
.Lcbc_decrypt_bulk:
|
||||
lea (%rsp),%rax
|
||||
lea (%rsp),%r11 # frame pointer
|
||||
.cfi_def_cfa_register %r11
|
||||
push %rbp
|
||||
.cfi_push %rbp
|
||||
sub \$$frame_size,%rsp
|
||||
and \$-16,%rsp # Linux kernel stack can be incorrectly seeded
|
||||
___
|
||||
@@ -3750,8 +3800,11 @@ $code.=<<___ if ($win64);
|
||||
movaps %xmm15,0xa0(%rsp)
|
||||
.Lcbc_decrypt_body:
|
||||
___
|
||||
|
||||
my $inp_=$key_="%rbp"; # reassign $key_
|
||||
|
||||
$code.=<<___;
|
||||
lea -8(%rax),%rbp
|
||||
mov $key,$key_ # [re-]backup $key [after reassignment]
|
||||
movups ($ivp),$iv
|
||||
mov $rnds_,$rounds
|
||||
cmp \$0x50,$len
|
||||
@@ -3791,7 +3844,7 @@ $code.=<<___;
|
||||
pxor $rndkey0,$inout1
|
||||
$movkey 0x10-0x70($key),$rndkey1
|
||||
pxor $rndkey0,$inout2
|
||||
xor $inp_,$inp_
|
||||
mov \$-1,$inp_
|
||||
cmp \$0x70,$len # is there at least 0x60 bytes ahead?
|
||||
pxor $rndkey0,$inout3
|
||||
pxor $rndkey0,$inout4
|
||||
@@ -3807,8 +3860,8 @@ $code.=<<___;
|
||||
aesdec $rndkey1,$inout4
|
||||
aesdec $rndkey1,$inout5
|
||||
aesdec $rndkey1,$inout6
|
||||
setnc ${inp_}b
|
||||
shl \$7,$inp_
|
||||
adc \$0,$inp_
|
||||
and \$128,$inp_
|
||||
aesdec $rndkey1,$inout7
|
||||
add $inp,$inp_
|
||||
$movkey 0x30-0x70($key),$rndkey1
|
||||
@@ -4172,10 +4225,13 @@ $code.=<<___ if ($win64);
|
||||
movaps %xmm0,0xa0(%rsp)
|
||||
___
|
||||
$code.=<<___;
|
||||
lea (%rbp),%rsp
|
||||
pop %rbp
|
||||
mov -8(%r11),%rbp
|
||||
.cfi_restore %rbp
|
||||
lea (%r11),%rsp
|
||||
.cfi_def_cfa_register %rsp
|
||||
.Lcbc_ret:
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size ${PREFIX}_cbc_encrypt,.-${PREFIX}_cbc_encrypt
|
||||
___
|
||||
}
|
||||
@@ -4196,7 +4252,9 @@ $code.=<<___;
|
||||
.type ${PREFIX}_set_decrypt_key,\@abi-omnipotent
|
||||
.align 16
|
||||
${PREFIX}_set_decrypt_key:
|
||||
.cfi_startproc
|
||||
.byte 0x48,0x83,0xEC,0x08 # sub rsp,8
|
||||
.cfi_adjust_cfa_offset 8
|
||||
call __aesni_set_encrypt_key
|
||||
shl \$4,$bits # rounds-1 after _aesni_set_encrypt_key
|
||||
test %eax,%eax
|
||||
@@ -4229,15 +4287,16 @@ ${PREFIX}_set_decrypt_key:
|
||||
pxor %xmm0,%xmm0
|
||||
.Ldec_key_ret:
|
||||
add \$8,%rsp
|
||||
.cfi_adjust_cfa_offset -8
|
||||
ret
|
||||
.cfi_endproc
|
||||
.LSEH_end_set_decrypt_key:
|
||||
.size ${PREFIX}_set_decrypt_key,.-${PREFIX}_set_decrypt_key
|
||||
___
|
||||
|
||||
# This is based on submission by
|
||||
#
|
||||
# Huang Ying <ying.huang@intel.com>
|
||||
# Vinodh Gopal <vinodh.gopal@intel.com>
|
||||
# This is based on submission from Intel by
|
||||
# Huang Ying
|
||||
# Vinodh Gopal
|
||||
# Kahraman Akdemir
|
||||
#
|
||||
# Aggressively optimized in respect to aeskeygenassist's critical path
|
||||
@@ -4265,7 +4324,9 @@ $code.=<<___;
|
||||
.align 16
|
||||
${PREFIX}_set_encrypt_key:
|
||||
__aesni_set_encrypt_key:
|
||||
.cfi_startproc
|
||||
.byte 0x48,0x83,0xEC,0x08 # sub rsp,8
|
||||
.cfi_adjust_cfa_offset 8
|
||||
mov \$-1,%rax
|
||||
test $inp,$inp
|
||||
jz .Lenc_key_ret
|
||||
@@ -4454,7 +4515,7 @@ __aesni_set_encrypt_key:
|
||||
|
||||
.align 16
|
||||
.L14rounds:
|
||||
movups 16($inp),%xmm2 # remaning half of *userKey
|
||||
movups 16($inp),%xmm2 # remaining half of *userKey
|
||||
mov \$13,$bits # 14 rounds for 256
|
||||
lea 16(%rax),%rax
|
||||
cmp \$`1<<28`,%r10d # AVX, but no XOP
|
||||
@@ -4558,7 +4619,9 @@ __aesni_set_encrypt_key:
|
||||
pxor %xmm4,%xmm4
|
||||
pxor %xmm5,%xmm5
|
||||
add \$8,%rsp
|
||||
.cfi_adjust_cfa_offset -8
|
||||
ret
|
||||
.cfi_endproc
|
||||
.LSEH_end_set_encrypt_key:
|
||||
|
||||
.align 16
|
||||
@@ -4744,13 +4807,16 @@ ctr_xts_se_handler:
|
||||
cmp %r10,%rbx # context->Rip>=epilogue label
|
||||
jae .Lcommon_seh_tail
|
||||
|
||||
mov 160($context),%rax # pull context->Rbp
|
||||
lea -0xa0(%rax),%rsi # %xmm save area
|
||||
mov 208($context),%rax # pull context->R11
|
||||
|
||||
lea -0xa8(%rax),%rsi # %xmm save area
|
||||
lea 512($context),%rdi # & context.Xmm6
|
||||
mov \$20,%ecx # 10*sizeof(%xmm0)/sizeof(%rax)
|
||||
.long 0xa548f3fc # cld; rep movsq
|
||||
|
||||
jmp .Lcommon_rbp_tail
|
||||
mov -8(%rax),%rbp # restore saved %rbp
|
||||
mov %rbp,160($context) # restore context->Rbp
|
||||
jmp .Lcommon_seh_tail
|
||||
.size ctr_xts_se_handler,.-ctr_xts_se_handler
|
||||
|
||||
.type ocb_se_handler,\@abi-omnipotent
|
||||
@@ -4834,9 +4900,13 @@ cbc_se_handler:
|
||||
cmp %r10,%rbx # context->Rip<"prologue" label
|
||||
jb .Lcommon_seh_tail
|
||||
|
||||
mov 120($context),%rax # pull context->Rax
|
||||
|
||||
lea .Lcbc_decrypt_body(%rip),%r10
|
||||
cmp %r10,%rbx # context->Rip<cbc_decrypt_body
|
||||
jb .Lrestore_cbc_rax
|
||||
jb .Lcommon_seh_tail
|
||||
|
||||
mov 152($context),%rax # pull context->Rsp
|
||||
|
||||
lea .Lcbc_ret(%rip),%r10
|
||||
cmp %r10,%rbx # context->Rip>="epilogue" label
|
||||
@@ -4847,15 +4917,10 @@ cbc_se_handler:
|
||||
mov \$20,%ecx # 10*sizeof(%xmm0)/sizeof(%rax)
|
||||
.long 0xa548f3fc # cld; rep movsq
|
||||
|
||||
.Lcommon_rbp_tail:
|
||||
mov 160($context),%rax # pull context->Rbp
|
||||
mov (%rax),%rbp # restore saved %rbp
|
||||
lea 8(%rax),%rax # adjust stack pointer
|
||||
mov %rbp,160($context) # restore context->Rbp
|
||||
jmp .Lcommon_seh_tail
|
||||
mov 208($context),%rax # pull context->R11
|
||||
|
||||
.Lrestore_cbc_rax:
|
||||
mov 120($context),%rax
|
||||
mov -8(%rax),%rbp # restore saved %rbp
|
||||
mov %rbp,160($context) # restore context->Rbp
|
||||
|
||||
.Lcommon_seh_tail:
|
||||
mov 8(%rax),%rdi
|
||||
|
||||
@@ -3773,7 +3773,7 @@ foreach(split("\n",$code)) {
|
||||
if ($flavour =~ /le$/o) {
|
||||
SWITCH: for($conv) {
|
||||
/\?inv/ && do { @bytes=map($_^0xf,@bytes); last; };
|
||||
/\?rev/ && do { @bytes=reverse(@bytes); last; };
|
||||
/\?rev/ && do { @bytes=reverse(@bytes); last; };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
|
||||
|
||||
# ====================================================================
|
||||
# Written by David S. Miller <davem@devemloft.net> and Andy Polyakov
|
||||
# <appro@openssl.org>. The module is licensed under 2-clause BSD
|
||||
# license. October 2012. All rights reserved.
|
||||
# Written by David S. Miller and Andy Polyakov.
|
||||
# The module is licensed under 2-clause BSD license. October 2012.
|
||||
# All rights reserved.
|
||||
# ====================================================================
|
||||
|
||||
######################################################################
|
||||
@@ -44,7 +44,7 @@
|
||||
# instructions with those on critical path. Amazing!
|
||||
#
|
||||
# As with Intel AES-NI, question is if it's possible to improve
|
||||
# performance of parallelizeable modes by interleaving round
|
||||
# performance of parallelizable modes by interleaving round
|
||||
# instructions. Provided round instruction latency and throughput
|
||||
# optimal interleave factor is 2. But can we expect 2x performance
|
||||
# improvement? Well, as round instructions can be issued one per
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
# Cortex-A57(*) 1.95 0.85 0.93
|
||||
# Denver 1.96 0.86 0.80
|
||||
# Mongoose 1.33 1.20 1.20
|
||||
# Kryo 1.26 0.94 1.00
|
||||
#
|
||||
# (*) original 3.64/1.34/1.32 results were for r0p0 revision
|
||||
# and are still same even for updated module;
|
||||
@@ -929,7 +930,7 @@ if ($flavour =~ /64/) { ######## 64-bit code
|
||||
s/^(\s+)v/$1/o or # strip off v prefix
|
||||
s/\bbx\s+lr\b/ret/o;
|
||||
|
||||
# fix up remainig legacy suffixes
|
||||
# fix up remaining legacy suffixes
|
||||
s/\.[ui]?8//o;
|
||||
m/\],#8/o and s/\.16b/\.8b/go;
|
||||
s/\.[ui]?32//o and s/\.16b/\.4s/go;
|
||||
@@ -964,21 +965,21 @@ if ($flavour =~ /64/) { ######## 64-bit code
|
||||
|
||||
$arg =~ m/q([0-9]+),\s*\{q([0-9]+)\},\s*q([0-9]+)/o &&
|
||||
sprintf "vtbl.8 d%d,{q%d},d%d\n\t".
|
||||
"vtbl.8 d%d,{q%d},d%d", 2*$1,$2,2*$3, 2*$1+1,$2,2*$3+1;
|
||||
"vtbl.8 d%d,{q%d},d%d", 2*$1,$2,2*$3, 2*$1+1,$2,2*$3+1;
|
||||
}
|
||||
|
||||
sub unvdup32 {
|
||||
my $arg=shift;
|
||||
|
||||
$arg =~ m/q([0-9]+),\s*q([0-9]+)\[([0-3])\]/o &&
|
||||
sprintf "vdup.32 q%d,d%d[%d]",$1,2*$2+($3>>1),$3&1;
|
||||
sprintf "vdup.32 q%d,d%d[%d]",$1,2*$2+($3>>1),$3&1;
|
||||
}
|
||||
|
||||
sub unvmov32 {
|
||||
my $arg=shift;
|
||||
|
||||
$arg =~ m/q([0-9]+)\[([0-3])\],(.*)/o &&
|
||||
sprintf "vmov.32 d%d[%d],%s",2*$1+($2>>1),$2&1,$3;
|
||||
sprintf "vmov.32 d%d[%d],%s",2*$1+($2>>1),$2&1,$3;
|
||||
}
|
||||
|
||||
foreach(split("\n",$code)) {
|
||||
@@ -988,7 +989,7 @@ if ($flavour =~ /64/) { ######## 64-bit code
|
||||
s/\bv([0-9])\.[12468]+[bsd]\b/q$1/go; # new->old registers
|
||||
s/\/\/\s?/@ /o; # new->old style commentary
|
||||
|
||||
# fix up remainig new-style suffixes
|
||||
# fix up remaining new-style suffixes
|
||||
s/\{q([0-9]+)\},\s*\[(.+)\],#8/sprintf "{d%d},[$2]!",2*$1/eo or
|
||||
s/\],#[0-9]+/]!/o;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#! /usr/bin/env perl
|
||||
# Copyright 2012-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
# Copyright 2012-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the OpenSSL license (the "License"). You may not use
|
||||
# this file except in compliance with the License. You can obtain a copy
|
||||
@@ -14,8 +14,7 @@
|
||||
# details see http://www.openssl.org/~appro/cryptogams/.
|
||||
#
|
||||
# Specific modes and adaptation for Linux kernel by Ard Biesheuvel
|
||||
# <ard.biesheuvel@linaro.org>. Permission to use under GPL terms is
|
||||
# granted.
|
||||
# of Linaro. Permission to use under GPL terms is granted.
|
||||
# ====================================================================
|
||||
|
||||
# Bit-sliced AES for ARM NEON
|
||||
@@ -49,10 +48,7 @@
|
||||
# <appro@openssl.org>
|
||||
|
||||
# April-August 2013
|
||||
#
|
||||
# Add CBC, CTR and XTS subroutines, adapt for kernel use.
|
||||
#
|
||||
# <ard.biesheuvel@linaro.org>
|
||||
# Add CBC, CTR and XTS subroutines and adapt for kernel use; courtesy of Ard.
|
||||
|
||||
$flavour = shift;
|
||||
if ($flavour=~/\w[\w\-]*\.\w+$/) { $output=$flavour; undef $flavour; }
|
||||
@@ -91,7 +87,7 @@ my @s=@_[12..15];
|
||||
|
||||
sub InBasisChange {
|
||||
# input in lsb > [b0, b1, b2, b3, b4, b5, b6, b7] < msb
|
||||
# output in lsb > [b6, b5, b0, b3, b7, b1, b4, b2] < msb
|
||||
# output in lsb > [b6, b5, b0, b3, b7, b1, b4, b2] < msb
|
||||
my @b=@_[0..7];
|
||||
$code.=<<___;
|
||||
veor @b[2], @b[2], @b[1]
|
||||
@@ -746,7 +742,7 @@ $code.=<<___;
|
||||
_bsaes_decrypt8:
|
||||
adr $const,.
|
||||
vldmia $key!, {@XMM[9]} @ round 0 key
|
||||
#if defined(__thumb2__) || defined(__APPLE__)
|
||||
#ifdef __APPLE__
|
||||
adr $const,.LM0ISR
|
||||
#else
|
||||
add $const,$const,#.LM0ISR-_bsaes_decrypt8
|
||||
@@ -845,7 +841,7 @@ _bsaes_const:
|
||||
_bsaes_encrypt8:
|
||||
adr $const,.
|
||||
vldmia $key!, {@XMM[9]} @ round 0 key
|
||||
#if defined(__thumb2__) || defined(__APPLE__)
|
||||
#ifdef __APPLE__
|
||||
adr $const,.LM0SR
|
||||
#else
|
||||
sub $const,$const,#_bsaes_encrypt8-.LM0SR
|
||||
@@ -953,7 +949,7 @@ $code.=<<___;
|
||||
_bsaes_key_convert:
|
||||
adr $const,.
|
||||
vld1.8 {@XMM[7]}, [$inp]! @ load round 0 key
|
||||
#if defined(__thumb2__) || defined(__APPLE__)
|
||||
#ifdef __APPLE__
|
||||
adr $const,.LM0
|
||||
#else
|
||||
sub $const,$const,#_bsaes_key_convert-.LM0
|
||||
|
||||
+196
-74
@@ -131,7 +131,7 @@ my @s=@_[12..15];
|
||||
|
||||
sub InBasisChange {
|
||||
# input in lsb > [b0, b1, b2, b3, b4, b5, b6, b7] < msb
|
||||
# output in lsb > [b6, b5, b0, b3, b7, b1, b4, b2] < msb
|
||||
# output in lsb > [b6, b5, b0, b3, b7, b1, b4, b2] < msb
|
||||
my @b=@_[0..7];
|
||||
$code.=<<___;
|
||||
pxor @b[6], @b[5]
|
||||
@@ -381,7 +381,7 @@ $code.=<<___;
|
||||
pxor @s[0], @t[3]
|
||||
pxor @s[1], @t[2]
|
||||
pxor @s[2], @t[1]
|
||||
pxor @s[3], @t[0]
|
||||
pxor @s[3], @t[0]
|
||||
|
||||
#Inv_GF16 \t0, \t1, \t2, \t3, \s0, \s1, \s2, \s3
|
||||
|
||||
@@ -1165,15 +1165,23 @@ $code.=<<___;
|
||||
.type bsaes_ecb_encrypt_blocks,\@abi-omnipotent
|
||||
.align 16
|
||||
bsaes_ecb_encrypt_blocks:
|
||||
.cfi_startproc
|
||||
mov %rsp, %rax
|
||||
.Lecb_enc_prologue:
|
||||
push %rbp
|
||||
.cfi_push %rbp
|
||||
push %rbx
|
||||
.cfi_push %rbx
|
||||
push %r12
|
||||
.cfi_push %r12
|
||||
push %r13
|
||||
.cfi_push %r13
|
||||
push %r14
|
||||
.cfi_push %r14
|
||||
push %r15
|
||||
.cfi_push %r15
|
||||
lea -0x48(%rsp),%rsp
|
||||
.cfi_adjust_cfa_offset 0x48
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
lea -0xa0(%rsp), %rsp
|
||||
@@ -1191,6 +1199,7 @@ $code.=<<___ if ($win64);
|
||||
___
|
||||
$code.=<<___;
|
||||
mov %rsp,%rbp # backup %rsp
|
||||
.cfi_def_cfa_register %rbp
|
||||
mov 240($arg4),%eax # rounds
|
||||
mov $arg1,$inp # backup arguments
|
||||
mov $arg2,$out
|
||||
@@ -1334,7 +1343,8 @@ $code.=<<___;
|
||||
cmp %rax, %rbp
|
||||
jb .Lecb_enc_bzero
|
||||
|
||||
lea (%rbp),%rsp # restore %rsp
|
||||
lea 0x78(%rbp),%rax
|
||||
.cfi_def_cfa %rax,8
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
movaps 0x40(%rbp), %xmm6
|
||||
@@ -1347,34 +1357,50 @@ $code.=<<___ if ($win64);
|
||||
movaps 0xb0(%rbp), %xmm13
|
||||
movaps 0xc0(%rbp), %xmm14
|
||||
movaps 0xd0(%rbp), %xmm15
|
||||
lea 0xa0(%rbp), %rsp
|
||||
lea 0xa0(%rax), %rax
|
||||
.Lecb_enc_tail:
|
||||
___
|
||||
$code.=<<___;
|
||||
mov 0x48(%rsp), %r15
|
||||
mov 0x50(%rsp), %r14
|
||||
mov 0x58(%rsp), %r13
|
||||
mov 0x60(%rsp), %r12
|
||||
mov 0x68(%rsp), %rbx
|
||||
mov 0x70(%rsp), %rax
|
||||
lea 0x78(%rsp), %rsp
|
||||
mov %rax, %rbp
|
||||
mov -48(%rax), %r15
|
||||
.cfi_restore %r15
|
||||
mov -40(%rax), %r14
|
||||
.cfi_restore %r14
|
||||
mov -32(%rax), %r13
|
||||
.cfi_restore %r13
|
||||
mov -24(%rax), %r12
|
||||
.cfi_restore %r12
|
||||
mov -16(%rax), %rbx
|
||||
.cfi_restore %rbx
|
||||
mov -8(%rax), %rbp
|
||||
.cfi_restore %rbp
|
||||
lea (%rax), %rsp # restore %rsp
|
||||
.cfi_def_cfa_register %rsp
|
||||
.Lecb_enc_epilogue:
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size bsaes_ecb_encrypt_blocks,.-bsaes_ecb_encrypt_blocks
|
||||
|
||||
.globl bsaes_ecb_decrypt_blocks
|
||||
.type bsaes_ecb_decrypt_blocks,\@abi-omnipotent
|
||||
.align 16
|
||||
bsaes_ecb_decrypt_blocks:
|
||||
.cfi_startproc
|
||||
mov %rsp, %rax
|
||||
.Lecb_dec_prologue:
|
||||
push %rbp
|
||||
.cfi_push %rbp
|
||||
push %rbx
|
||||
.cfi_push %rbx
|
||||
push %r12
|
||||
.cfi_push %r12
|
||||
push %r13
|
||||
.cfi_push %r13
|
||||
push %r14
|
||||
.cfi_push %r14
|
||||
push %r15
|
||||
.cfi_push %r15
|
||||
lea -0x48(%rsp),%rsp
|
||||
.cfi_adjust_cfa_offset 0x48
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
lea -0xa0(%rsp), %rsp
|
||||
@@ -1392,6 +1418,7 @@ $code.=<<___ if ($win64);
|
||||
___
|
||||
$code.=<<___;
|
||||
mov %rsp,%rbp # backup %rsp
|
||||
.cfi_def_cfa_register %rbp
|
||||
mov 240($arg4),%eax # rounds
|
||||
mov $arg1,$inp # backup arguments
|
||||
mov $arg2,$out
|
||||
@@ -1536,7 +1563,8 @@ $code.=<<___;
|
||||
cmp %rax, %rbp
|
||||
jb .Lecb_dec_bzero
|
||||
|
||||
lea (%rbp),%rsp # restore %rsp
|
||||
lea 0x78(%rbp),%rax
|
||||
.cfi_def_cfa %rax,8
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
movaps 0x40(%rbp), %xmm6
|
||||
@@ -1549,19 +1577,27 @@ $code.=<<___ if ($win64);
|
||||
movaps 0xb0(%rbp), %xmm13
|
||||
movaps 0xc0(%rbp), %xmm14
|
||||
movaps 0xd0(%rbp), %xmm15
|
||||
lea 0xa0(%rbp), %rsp
|
||||
lea 0xa0(%rax), %rax
|
||||
.Lecb_dec_tail:
|
||||
___
|
||||
$code.=<<___;
|
||||
mov 0x48(%rsp), %r15
|
||||
mov 0x50(%rsp), %r14
|
||||
mov 0x58(%rsp), %r13
|
||||
mov 0x60(%rsp), %r12
|
||||
mov 0x68(%rsp), %rbx
|
||||
mov 0x70(%rsp), %rax
|
||||
lea 0x78(%rsp), %rsp
|
||||
mov %rax, %rbp
|
||||
mov -48(%rax), %r15
|
||||
.cfi_restore %r15
|
||||
mov -40(%rax), %r14
|
||||
.cfi_restore %r14
|
||||
mov -32(%rax), %r13
|
||||
.cfi_restore %r13
|
||||
mov -24(%rax), %r12
|
||||
.cfi_restore %r12
|
||||
mov -16(%rax), %rbx
|
||||
.cfi_restore %rbx
|
||||
mov -8(%rax), %rbp
|
||||
.cfi_restore %rbp
|
||||
lea (%rax), %rsp # restore %rsp
|
||||
.cfi_def_cfa_register %rsp
|
||||
.Lecb_dec_epilogue:
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size bsaes_ecb_decrypt_blocks,.-bsaes_ecb_decrypt_blocks
|
||||
___
|
||||
}
|
||||
@@ -1571,6 +1607,7 @@ $code.=<<___;
|
||||
.type bsaes_cbc_encrypt,\@abi-omnipotent
|
||||
.align 16
|
||||
bsaes_cbc_encrypt:
|
||||
.cfi_startproc
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
mov 48(%rsp),$arg6 # pull direction flag
|
||||
@@ -1584,12 +1621,19 @@ $code.=<<___;
|
||||
mov %rsp, %rax
|
||||
.Lcbc_dec_prologue:
|
||||
push %rbp
|
||||
.cfi_push %rbp
|
||||
push %rbx
|
||||
.cfi_push %rbx
|
||||
push %r12
|
||||
.cfi_push %r12
|
||||
push %r13
|
||||
.cfi_push %r13
|
||||
push %r14
|
||||
.cfi_push %r14
|
||||
push %r15
|
||||
.cfi_push %r15
|
||||
lea -0x48(%rsp), %rsp
|
||||
.cfi_adjust_cfa_offset 0x48
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
mov 0xa0(%rsp),$arg5 # pull ivp
|
||||
@@ -1608,6 +1652,7 @@ $code.=<<___ if ($win64);
|
||||
___
|
||||
$code.=<<___;
|
||||
mov %rsp, %rbp # backup %rsp
|
||||
.cfi_def_cfa_register %rbp
|
||||
mov 240($arg4), %eax # rounds
|
||||
mov $arg1, $inp # backup arguments
|
||||
mov $arg2, $out
|
||||
@@ -1826,7 +1871,8 @@ $code.=<<___;
|
||||
cmp %rax, %rbp
|
||||
ja .Lcbc_dec_bzero
|
||||
|
||||
lea (%rbp),%rsp # restore %rsp
|
||||
lea 0x78(%rbp),%rax
|
||||
.cfi_def_cfa %rax,8
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
movaps 0x40(%rbp), %xmm6
|
||||
@@ -1839,34 +1885,50 @@ $code.=<<___ if ($win64);
|
||||
movaps 0xb0(%rbp), %xmm13
|
||||
movaps 0xc0(%rbp), %xmm14
|
||||
movaps 0xd0(%rbp), %xmm15
|
||||
lea 0xa0(%rbp), %rsp
|
||||
lea 0xa0(%rax), %rax
|
||||
.Lcbc_dec_tail:
|
||||
___
|
||||
$code.=<<___;
|
||||
mov 0x48(%rsp), %r15
|
||||
mov 0x50(%rsp), %r14
|
||||
mov 0x58(%rsp), %r13
|
||||
mov 0x60(%rsp), %r12
|
||||
mov 0x68(%rsp), %rbx
|
||||
mov 0x70(%rsp), %rax
|
||||
lea 0x78(%rsp), %rsp
|
||||
mov %rax, %rbp
|
||||
mov -48(%rax), %r15
|
||||
.cfi_restore %r15
|
||||
mov -40(%rax), %r14
|
||||
.cfi_restore %r14
|
||||
mov -32(%rax), %r13
|
||||
.cfi_restore %r13
|
||||
mov -24(%rax), %r12
|
||||
.cfi_restore %r12
|
||||
mov -16(%rax), %rbx
|
||||
.cfi_restore %rbx
|
||||
mov -8(%rax), %rbp
|
||||
.cfi_restore %rbp
|
||||
lea (%rax), %rsp # restore %rsp
|
||||
.cfi_def_cfa_register %rsp
|
||||
.Lcbc_dec_epilogue:
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size bsaes_cbc_encrypt,.-bsaes_cbc_encrypt
|
||||
|
||||
.globl bsaes_ctr32_encrypt_blocks
|
||||
.type bsaes_ctr32_encrypt_blocks,\@abi-omnipotent
|
||||
.align 16
|
||||
bsaes_ctr32_encrypt_blocks:
|
||||
.cfi_startproc
|
||||
mov %rsp, %rax
|
||||
.Lctr_enc_prologue:
|
||||
push %rbp
|
||||
.cfi_push %rbp
|
||||
push %rbx
|
||||
.cfi_push %rbx
|
||||
push %r12
|
||||
.cfi_push %r12
|
||||
push %r13
|
||||
.cfi_push %r13
|
||||
push %r14
|
||||
.cfi_push %r14
|
||||
push %r15
|
||||
.cfi_push %r15
|
||||
lea -0x48(%rsp), %rsp
|
||||
.cfi_adjust_cfa_offset 0x48
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
mov 0xa0(%rsp),$arg5 # pull ivp
|
||||
@@ -1885,6 +1947,7 @@ $code.=<<___ if ($win64);
|
||||
___
|
||||
$code.=<<___;
|
||||
mov %rsp, %rbp # backup %rsp
|
||||
.cfi_def_cfa_register %rbp
|
||||
movdqu ($arg5), %xmm0 # load counter
|
||||
mov 240($arg4), %eax # rounds
|
||||
mov $arg1, $inp # backup arguments
|
||||
@@ -2058,7 +2121,8 @@ $code.=<<___;
|
||||
cmp %rax, %rbp
|
||||
ja .Lctr_enc_bzero
|
||||
|
||||
lea (%rbp),%rsp # restore %rsp
|
||||
lea 0x78(%rbp),%rax
|
||||
.cfi_def_cfa %rax,8
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
movaps 0x40(%rbp), %xmm6
|
||||
@@ -2071,19 +2135,27 @@ $code.=<<___ if ($win64);
|
||||
movaps 0xb0(%rbp), %xmm13
|
||||
movaps 0xc0(%rbp), %xmm14
|
||||
movaps 0xd0(%rbp), %xmm15
|
||||
lea 0xa0(%rbp), %rsp
|
||||
lea 0xa0(%rax), %rax
|
||||
.Lctr_enc_tail:
|
||||
___
|
||||
$code.=<<___;
|
||||
mov 0x48(%rsp), %r15
|
||||
mov 0x50(%rsp), %r14
|
||||
mov 0x58(%rsp), %r13
|
||||
mov 0x60(%rsp), %r12
|
||||
mov 0x68(%rsp), %rbx
|
||||
mov 0x70(%rsp), %rax
|
||||
lea 0x78(%rsp), %rsp
|
||||
mov %rax, %rbp
|
||||
mov -48(%rax), %r15
|
||||
.cfi_restore %r15
|
||||
mov -40(%rax), %r14
|
||||
.cfi_restore %r14
|
||||
mov -32(%rax), %r13
|
||||
.cfi_restore %r13
|
||||
mov -24(%rax), %r12
|
||||
.cfi_restore %r12
|
||||
mov -16(%rax), %rbx
|
||||
.cfi_restore %rbx
|
||||
mov -8(%rax), %rbp
|
||||
.cfi_restore %rbp
|
||||
lea (%rax), %rsp # restore %rsp
|
||||
.cfi_def_cfa_register %rsp
|
||||
.Lctr_enc_epilogue:
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size bsaes_ctr32_encrypt_blocks,.-bsaes_ctr32_encrypt_blocks
|
||||
___
|
||||
######################################################################
|
||||
@@ -2099,15 +2171,23 @@ $code.=<<___;
|
||||
.type bsaes_xts_encrypt,\@abi-omnipotent
|
||||
.align 16
|
||||
bsaes_xts_encrypt:
|
||||
.cfi_startproc
|
||||
mov %rsp, %rax
|
||||
.Lxts_enc_prologue:
|
||||
push %rbp
|
||||
.cfi_push %rbp
|
||||
push %rbx
|
||||
.cfi_push %rbx
|
||||
push %r12
|
||||
.cfi_push %r12
|
||||
push %r13
|
||||
.cfi_push %r13
|
||||
push %r14
|
||||
.cfi_push %r14
|
||||
push %r15
|
||||
.cfi_push %r15
|
||||
lea -0x48(%rsp), %rsp
|
||||
.cfi_adjust_cfa_offset 0x48
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
mov 0xa0(%rsp),$arg5 # pull key2
|
||||
@@ -2127,6 +2207,7 @@ $code.=<<___ if ($win64);
|
||||
___
|
||||
$code.=<<___;
|
||||
mov %rsp, %rbp # backup %rsp
|
||||
.cfi_def_cfa_register %rbp
|
||||
mov $arg1, $inp # backup arguments
|
||||
mov $arg2, $out
|
||||
mov $arg3, $len
|
||||
@@ -2448,7 +2529,8 @@ $code.=<<___;
|
||||
cmp %rax, %rbp
|
||||
ja .Lxts_enc_bzero
|
||||
|
||||
lea (%rbp),%rsp # restore %rsp
|
||||
lea 0x78(%rbp),%rax
|
||||
.cfi_def_cfa %rax,8
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
movaps 0x40(%rbp), %xmm6
|
||||
@@ -2461,34 +2543,50 @@ $code.=<<___ if ($win64);
|
||||
movaps 0xb0(%rbp), %xmm13
|
||||
movaps 0xc0(%rbp), %xmm14
|
||||
movaps 0xd0(%rbp), %xmm15
|
||||
lea 0xa0(%rbp), %rsp
|
||||
lea 0xa0(%rax), %rax
|
||||
.Lxts_enc_tail:
|
||||
___
|
||||
$code.=<<___;
|
||||
mov 0x48(%rsp), %r15
|
||||
mov 0x50(%rsp), %r14
|
||||
mov 0x58(%rsp), %r13
|
||||
mov 0x60(%rsp), %r12
|
||||
mov 0x68(%rsp), %rbx
|
||||
mov 0x70(%rsp), %rax
|
||||
lea 0x78(%rsp), %rsp
|
||||
mov %rax, %rbp
|
||||
mov -48(%rax), %r15
|
||||
.cfi_restore %r15
|
||||
mov -40(%rax), %r14
|
||||
.cfi_restore %r14
|
||||
mov -32(%rax), %r13
|
||||
.cfi_restore %r13
|
||||
mov -24(%rax), %r12
|
||||
.cfi_restore %r12
|
||||
mov -16(%rax), %rbx
|
||||
.cfi_restore %rbx
|
||||
mov -8(%rax), %rbp
|
||||
.cfi_restore %rbp
|
||||
lea (%rax), %rsp # restore %rsp
|
||||
.cfi_def_cfa_register %rsp
|
||||
.Lxts_enc_epilogue:
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size bsaes_xts_encrypt,.-bsaes_xts_encrypt
|
||||
|
||||
.globl bsaes_xts_decrypt
|
||||
.type bsaes_xts_decrypt,\@abi-omnipotent
|
||||
.align 16
|
||||
bsaes_xts_decrypt:
|
||||
.cfi_startproc
|
||||
mov %rsp, %rax
|
||||
.Lxts_dec_prologue:
|
||||
push %rbp
|
||||
.cfi_push %rbp
|
||||
push %rbx
|
||||
.cfi_push %rbx
|
||||
push %r12
|
||||
.cfi_push %r12
|
||||
push %r13
|
||||
.cfi_push %r13
|
||||
push %r14
|
||||
.cfi_push %r14
|
||||
push %r15
|
||||
.cfi_push %r15
|
||||
lea -0x48(%rsp), %rsp
|
||||
.cfi_adjust_cfa_offset 0x48
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
mov 0xa0(%rsp),$arg5 # pull key2
|
||||
@@ -2855,7 +2953,8 @@ $code.=<<___;
|
||||
cmp %rax, %rbp
|
||||
ja .Lxts_dec_bzero
|
||||
|
||||
lea (%rbp),%rsp # restore %rsp
|
||||
lea 0x78(%rbp),%rax
|
||||
.cfi_def_cfa %rax,8
|
||||
___
|
||||
$code.=<<___ if ($win64);
|
||||
movaps 0x40(%rbp), %xmm6
|
||||
@@ -2868,19 +2967,27 @@ $code.=<<___ if ($win64);
|
||||
movaps 0xb0(%rbp), %xmm13
|
||||
movaps 0xc0(%rbp), %xmm14
|
||||
movaps 0xd0(%rbp), %xmm15
|
||||
lea 0xa0(%rbp), %rsp
|
||||
lea 0xa0(%rax), %rax
|
||||
.Lxts_dec_tail:
|
||||
___
|
||||
$code.=<<___;
|
||||
mov 0x48(%rsp), %r15
|
||||
mov 0x50(%rsp), %r14
|
||||
mov 0x58(%rsp), %r13
|
||||
mov 0x60(%rsp), %r12
|
||||
mov 0x68(%rsp), %rbx
|
||||
mov 0x70(%rsp), %rax
|
||||
lea 0x78(%rsp), %rsp
|
||||
mov %rax, %rbp
|
||||
mov -48(%rax), %r15
|
||||
.cfi_restore %r15
|
||||
mov -40(%rax), %r14
|
||||
.cfi_restore %r14
|
||||
mov -32(%rax), %r13
|
||||
.cfi_restore %r13
|
||||
mov -24(%rax), %r12
|
||||
.cfi_restore %r12
|
||||
mov -16(%rax), %rbx
|
||||
.cfi_restore %rbx
|
||||
mov -8(%rax), %rbp
|
||||
.cfi_restore %rbp
|
||||
lea (%rax), %rsp # restore %rsp
|
||||
.cfi_def_cfa_register %rsp
|
||||
.Lxts_dec_epilogue:
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size bsaes_xts_decrypt,.-bsaes_xts_decrypt
|
||||
___
|
||||
}
|
||||
@@ -2974,31 +3081,34 @@ se_handler:
|
||||
|
||||
mov 0(%r11),%r10d # HandlerData[0]
|
||||
lea (%rsi,%r10),%r10 # prologue label
|
||||
cmp %r10,%rbx # context->Rip<prologue label
|
||||
jb .Lin_prologue
|
||||
|
||||
mov 152($context),%rax # pull context->Rsp
|
||||
cmp %r10,%rbx # context->Rip<=prologue label
|
||||
jbe .Lin_prologue
|
||||
|
||||
mov 4(%r11),%r10d # HandlerData[1]
|
||||
lea (%rsi,%r10),%r10 # epilogue label
|
||||
cmp %r10,%rbx # context->Rip>=epilogue label
|
||||
jae .Lin_prologue
|
||||
|
||||
mov 8(%r11),%r10d # HandlerData[2]
|
||||
lea (%rsi,%r10),%r10 # epilogue label
|
||||
cmp %r10,%rbx # context->Rip>=tail label
|
||||
jae .Lin_tail
|
||||
|
||||
mov 160($context),%rax # pull context->Rbp
|
||||
|
||||
lea 0x40(%rax),%rsi # %xmm save area
|
||||
lea 512($context),%rdi # &context.Xmm6
|
||||
mov \$20,%ecx # 10*sizeof(%xmm0)/sizeof(%rax)
|
||||
.long 0xa548f3fc # cld; rep movsq
|
||||
lea 0xa0(%rax),%rax # adjust stack pointer
|
||||
lea 0xa0+0x78(%rax),%rax # adjust stack pointer
|
||||
|
||||
mov 0x70(%rax),%rbp
|
||||
mov 0x68(%rax),%rbx
|
||||
mov 0x60(%rax),%r12
|
||||
mov 0x58(%rax),%r13
|
||||
mov 0x50(%rax),%r14
|
||||
mov 0x48(%rax),%r15
|
||||
lea 0x78(%rax),%rax # adjust stack pointer
|
||||
.Lin_tail:
|
||||
mov -48(%rax),%rbp
|
||||
mov -40(%rax),%rbx
|
||||
mov -32(%rax),%r12
|
||||
mov -24(%rax),%r13
|
||||
mov -16(%rax),%r14
|
||||
mov -8(%rax),%r15
|
||||
mov %rbx,144($context) # restore context->Rbx
|
||||
mov %rbp,160($context) # restore context->Rbp
|
||||
mov %r12,216($context) # restore context->R12
|
||||
@@ -3079,28 +3189,40 @@ $code.=<<___ if ($ecb);
|
||||
.byte 9,0,0,0
|
||||
.rva se_handler
|
||||
.rva .Lecb_enc_body,.Lecb_enc_epilogue # HandlerData[]
|
||||
.rva .Lecb_enc_tail
|
||||
.long 0
|
||||
.Lecb_dec_info:
|
||||
.byte 9,0,0,0
|
||||
.rva se_handler
|
||||
.rva .Lecb_dec_body,.Lecb_dec_epilogue # HandlerData[]
|
||||
.rva .Lecb_dec_tail
|
||||
.long 0
|
||||
___
|
||||
$code.=<<___;
|
||||
.Lcbc_dec_info:
|
||||
.byte 9,0,0,0
|
||||
.rva se_handler
|
||||
.rva .Lcbc_dec_body,.Lcbc_dec_epilogue # HandlerData[]
|
||||
.rva .Lcbc_dec_tail
|
||||
.long 0
|
||||
.Lctr_enc_info:
|
||||
.byte 9,0,0,0
|
||||
.rva se_handler
|
||||
.rva .Lctr_enc_body,.Lctr_enc_epilogue # HandlerData[]
|
||||
.rva .Lctr_enc_tail
|
||||
.long 0
|
||||
.Lxts_enc_info:
|
||||
.byte 9,0,0,0
|
||||
.rva se_handler
|
||||
.rva .Lxts_enc_body,.Lxts_enc_epilogue # HandlerData[]
|
||||
.rva .Lxts_enc_tail
|
||||
.long 0
|
||||
.Lxts_dec_info:
|
||||
.byte 9,0,0,0
|
||||
.rva se_handler
|
||||
.rva .Lxts_dec_body,.Lxts_dec_epilogue # HandlerData[]
|
||||
.rva .Lxts_dec_tail
|
||||
.long 0
|
||||
___
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
# Apple A7(***) 22.7(**) 10.9/14.3 [8.45/10.0 ]
|
||||
# Mongoose(***) 26.3(**) 21.0/25.0(**) [13.3/16.8 ]
|
||||
#
|
||||
# (*) ECB denotes approximate result for parallelizeable modes
|
||||
# (*) ECB denotes approximate result for parallelizable modes
|
||||
# such as CBC decrypt, CTR, etc.;
|
||||
# (**) these results are worse than scalar compiler-generated
|
||||
# code, but it's constant-time and therefore preferred;
|
||||
@@ -137,7 +137,7 @@ _vpaes_consts:
|
||||
.quad 0x07E4A34047A4E300, 0x1DFEB95A5DBEF91A
|
||||
.quad 0x5F36B5DC83EA6900, 0x2841C2ABF49D1E77
|
||||
|
||||
.asciz "Vector Permutaion AES for ARMv8, Mike Hamburg (Stanford University)"
|
||||
.asciz "Vector Permutation AES for ARMv8, Mike Hamburg (Stanford University)"
|
||||
.size _vpaes_consts,.-_vpaes_consts
|
||||
.align 6
|
||||
___
|
||||
@@ -769,7 +769,7 @@ _vpaes_schedule_core:
|
||||
ld1 {v0.16b}, [$inp] // vmovdqu 16(%rdi),%xmm0 # load key part 2 (unaligned)
|
||||
bl _vpaes_schedule_transform // input transform
|
||||
mov $inp, #7 // mov \$7, %esi
|
||||
|
||||
|
||||
.Loop_schedule_256:
|
||||
sub $inp, $inp, #1 // dec %esi
|
||||
bl _vpaes_schedule_mangle // output low result
|
||||
@@ -778,7 +778,7 @@ _vpaes_schedule_core:
|
||||
// high round
|
||||
bl _vpaes_schedule_round
|
||||
cbz $inp, .Lschedule_mangle_last
|
||||
bl _vpaes_schedule_mangle
|
||||
bl _vpaes_schedule_mangle
|
||||
|
||||
// low round. swap xmm7 and xmm6
|
||||
dup v0.4s, v0.s[3] // vpshufd \$0xFF, %xmm0, %xmm0
|
||||
@@ -787,7 +787,7 @@ _vpaes_schedule_core:
|
||||
mov v7.16b, v6.16b // vmovdqa %xmm6, %xmm7
|
||||
bl _vpaes_schedule_low_round
|
||||
mov v7.16b, v5.16b // vmovdqa %xmm5, %xmm7
|
||||
|
||||
|
||||
b .Loop_schedule_256
|
||||
|
||||
##
|
||||
@@ -814,7 +814,7 @@ _vpaes_schedule_core:
|
||||
|
||||
.Lschedule_mangle_last_dec:
|
||||
ld1 {v20.2d-v21.2d}, [x11] // reload constants
|
||||
sub $out, $out, #16 // add \$-16, %rdx
|
||||
sub $out, $out, #16 // add \$-16, %rdx
|
||||
eor v0.16b, v0.16b, v16.16b // vpxor .Lk_s63(%rip), %xmm0, %xmm0
|
||||
bl _vpaes_schedule_transform // output transform
|
||||
st1 {v0.2d}, [$out] // vmovdqu %xmm0, (%rdx) # save last key
|
||||
|
||||
@@ -1075,7 +1075,7 @@ Loop_schedule_256:
|
||||
# high round
|
||||
bl _vpaes_schedule_round
|
||||
bdz Lschedule_mangle_last # dec %esi
|
||||
bl _vpaes_schedule_mangle
|
||||
bl _vpaes_schedule_mangle
|
||||
|
||||
# low round. swap xmm7 and xmm6
|
||||
?vspltw v0, v0, 3 # vpshufd \$0xFF, %xmm0, %xmm0
|
||||
@@ -1083,7 +1083,7 @@ Loop_schedule_256:
|
||||
vmr v7, v6 # vmovdqa %xmm6, %xmm7
|
||||
bl _vpaes_schedule_low_round
|
||||
vmr v7, v5 # vmovdqa %xmm5, %xmm7
|
||||
|
||||
|
||||
b Loop_schedule_256
|
||||
##
|
||||
## .aes_schedule_mangle_last
|
||||
@@ -1131,7 +1131,7 @@ Lschedule_mangle_last:
|
||||
Lschedule_mangle_last_dec:
|
||||
lvx $iptlo, r11, r12 # reload $ipt
|
||||
lvx $ipthi, r9, r12
|
||||
addi $out, $out, -16 # add \$-16, %rdx
|
||||
addi $out, $out, -16 # add \$-16, %rdx
|
||||
vxor v0, v0, v26 # vpxor .Lk_s63(%rip), %xmm0, %xmm0
|
||||
bl _vpaes_schedule_transform # output transform
|
||||
|
||||
@@ -1566,7 +1566,7 @@ foreach (split("\n",$code)) {
|
||||
if ($flavour =~ /le$/o) {
|
||||
SWITCH: for($conv) {
|
||||
/\?inv/ && do { @bytes=map($_^0xf,@bytes); last; };
|
||||
/\?rev/ && do { @bytes=reverse(@bytes); last; };
|
||||
/\?rev/ && do { @bytes=reverse(@bytes); last; };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ $output = pop;
|
||||
open OUT,">$output";
|
||||
*STDOUT=*OUT;
|
||||
|
||||
&asm_init($ARGV[0],"vpaes-x86.pl",$x86only = $ARGV[$#ARGV] eq "386");
|
||||
&asm_init($ARGV[0],$x86only = $ARGV[$#ARGV] eq "386");
|
||||
|
||||
$PREFIX="vpaes";
|
||||
|
||||
@@ -445,7 +445,7 @@ $k_dsbo=0x2c0; # decryption sbox final output
|
||||
##
|
||||
&set_label("schedule_192",16);
|
||||
&movdqu ("xmm0",&QWP(8,$inp)); # load key part 2 (very unaligned)
|
||||
&call ("_vpaes_schedule_transform"); # input transform
|
||||
&call ("_vpaes_schedule_transform"); # input transform
|
||||
&movdqa ("xmm6","xmm0"); # save short part
|
||||
&pxor ("xmm4","xmm4"); # clear 4
|
||||
&movhlps("xmm6","xmm4"); # clobber low side with zeros
|
||||
@@ -476,7 +476,7 @@ $k_dsbo=0x2c0; # decryption sbox final output
|
||||
##
|
||||
&set_label("schedule_256",16);
|
||||
&movdqu ("xmm0",&QWP(16,$inp)); # load key part 2 (unaligned)
|
||||
&call ("_vpaes_schedule_transform"); # input transform
|
||||
&call ("_vpaes_schedule_transform"); # input transform
|
||||
&mov ($round,7);
|
||||
|
||||
&set_label("loop_schedule_256");
|
||||
@@ -487,7 +487,7 @@ $k_dsbo=0x2c0; # decryption sbox final output
|
||||
&call ("_vpaes_schedule_round");
|
||||
&dec ($round);
|
||||
&jz (&label("schedule_mangle_last"));
|
||||
&call ("_vpaes_schedule_mangle");
|
||||
&call ("_vpaes_schedule_mangle");
|
||||
|
||||
# low round. swap xmm7 and xmm6
|
||||
&pshufd ("xmm0","xmm0",0xFF);
|
||||
@@ -610,7 +610,7 @@ $k_dsbo=0x2c0; # decryption sbox final output
|
||||
# subbyte
|
||||
&movdqa ("xmm4",&QWP($k_s0F,$const));
|
||||
&movdqa ("xmm5",&QWP($k_inv,$const)); # 4 : 1/j
|
||||
&movdqa ("xmm1","xmm4");
|
||||
&movdqa ("xmm1","xmm4");
|
||||
&pandn ("xmm1","xmm0");
|
||||
&psrld ("xmm1",4); # 1 = i
|
||||
&pand ("xmm0","xmm4"); # 0 = k
|
||||
|
||||
@@ -172,7 +172,7 @@ _vpaes_encrypt_core:
|
||||
pshufb %xmm1, %xmm0
|
||||
ret
|
||||
.size _vpaes_encrypt_core,.-_vpaes_encrypt_core
|
||||
|
||||
|
||||
##
|
||||
## Decryption core
|
||||
##
|
||||
@@ -333,7 +333,7 @@ _vpaes_schedule_core:
|
||||
##
|
||||
.Lschedule_128:
|
||||
mov \$10, %esi
|
||||
|
||||
|
||||
.Loop_schedule_128:
|
||||
call _vpaes_schedule_round
|
||||
dec %rsi
|
||||
@@ -367,7 +367,7 @@ _vpaes_schedule_core:
|
||||
|
||||
.Loop_schedule_192:
|
||||
call _vpaes_schedule_round
|
||||
palignr \$8,%xmm6,%xmm0
|
||||
palignr \$8,%xmm6,%xmm0
|
||||
call _vpaes_schedule_mangle # save key n
|
||||
call _vpaes_schedule_192_smear
|
||||
call _vpaes_schedule_mangle # save key n+1
|
||||
@@ -393,7 +393,7 @@ _vpaes_schedule_core:
|
||||
movdqu 16(%rdi),%xmm0 # load key part 2 (unaligned)
|
||||
call _vpaes_schedule_transform # input transform
|
||||
mov \$7, %esi
|
||||
|
||||
|
||||
.Loop_schedule_256:
|
||||
call _vpaes_schedule_mangle # output low result
|
||||
movdqa %xmm0, %xmm6 # save cur_lo in xmm6
|
||||
@@ -402,7 +402,7 @@ _vpaes_schedule_core:
|
||||
call _vpaes_schedule_round
|
||||
dec %rsi
|
||||
jz .Lschedule_mangle_last
|
||||
call _vpaes_schedule_mangle
|
||||
call _vpaes_schedule_mangle
|
||||
|
||||
# low round. swap xmm7 and xmm6
|
||||
pshufd \$0xFF, %xmm0, %xmm0
|
||||
@@ -410,10 +410,10 @@ _vpaes_schedule_core:
|
||||
movdqa %xmm6, %xmm7
|
||||
call _vpaes_schedule_low_round
|
||||
movdqa %xmm5, %xmm7
|
||||
|
||||
|
||||
jmp .Loop_schedule_256
|
||||
|
||||
|
||||
|
||||
##
|
||||
## .aes_schedule_mangle_last
|
||||
##
|
||||
@@ -512,9 +512,9 @@ _vpaes_schedule_round:
|
||||
# rotate
|
||||
pshufd \$0xFF, %xmm0, %xmm0
|
||||
palignr \$1, %xmm0, %xmm0
|
||||
|
||||
|
||||
# fall through...
|
||||
|
||||
|
||||
# low round: same as high round, but no rotation and no rcon.
|
||||
_vpaes_schedule_low_round:
|
||||
# smear xmm7
|
||||
@@ -553,7 +553,7 @@ _vpaes_schedule_low_round:
|
||||
pxor %xmm4, %xmm0 # 0 = sbox output
|
||||
|
||||
# add in smeared stuff
|
||||
pxor %xmm7, %xmm0
|
||||
pxor %xmm7, %xmm0
|
||||
movdqa %xmm0, %xmm7
|
||||
ret
|
||||
.size _vpaes_schedule_round,.-_vpaes_schedule_round
|
||||
|
||||
+10
-3
@@ -5,11 +5,14 @@ SOURCE[../../libcrypto]=\
|
||||
|
||||
GENERATE[aes-ia64.s]=asm/aes-ia64.S
|
||||
|
||||
GENERATE[aes-586.s]=asm/aes-586.pl $(PERLASM_SCHEME) $(CFLAGS) $(LIB_CFLAGS) $(PROCESSOR)
|
||||
GENERATE[aes-586.s]=asm/aes-586.pl \
|
||||
$(PERLASM_SCHEME) $(LIB_CFLAGS) $(LIB_CPPFLAGS) $(PROCESSOR)
|
||||
DEPEND[aes-586.s]=../perlasm/x86asm.pl
|
||||
GENERATE[vpaes-x86.s]=asm/vpaes-x86.pl $(PERLASM_SCHEME) $(CFLAGS) $(LIB_CFLAGS) $(PROCESSOR)
|
||||
GENERATE[vpaes-x86.s]=asm/vpaes-x86.pl \
|
||||
$(PERLASM_SCHEME) $(LIB_CFLAGS) $(LIB_CPPFLAGS) $(PROCESSOR)
|
||||
DEPEND[vpaes-586.s]=../perlasm/x86asm.pl
|
||||
GENERATE[aesni-x86.s]=asm/aesni-x86.pl $(PERLASM_SCHEME) $(CFLAGS) $(LIB_CFLAGS) $(PROCESSOR)
|
||||
GENERATE[aesni-x86.s]=asm/aesni-x86.pl \
|
||||
$(PERLASM_SCHEME) $(LIB_CFLAGS) $(LIB_CPPFLAGS) $(PROCESSOR)
|
||||
DEPEND[aesni-586.s]=../perlasm/x86asm.pl
|
||||
|
||||
GENERATE[aes-x86_64.s]=asm/aes-x86_64.pl $(PERLASM_SCHEME)
|
||||
@@ -35,6 +38,7 @@ GENERATE[aesp8-ppc.s]=asm/aesp8-ppc.pl $(PERLASM_SCHEME)
|
||||
GENERATE[aes-parisc.s]=asm/aes-parisc.pl $(PERLASM_SCHEME)
|
||||
|
||||
GENERATE[aes-mips.S]=asm/aes-mips.pl $(PERLASM_SCHEME)
|
||||
INCLUDE[aes-mips.o]=..
|
||||
|
||||
GENERATE[aesv8-armx.S]=asm/aesv8-armx.pl $(PERLASM_SCHEME)
|
||||
INCLUDE[aesv8-armx.o]=..
|
||||
@@ -45,6 +49,9 @@ INCLUDE[aes-armv4.o]=..
|
||||
GENERATE[bsaes-armv7.S]=asm/bsaes-armv7.pl $(PERLASM_SCHEME)
|
||||
INCLUDE[bsaes-armv7.o]=..
|
||||
|
||||
GENERATE[aes-s390x.S]=asm/aes-s390x.pl $(PERLASM_SCHEME)
|
||||
INCLUDE[aes-s390x.o]=..
|
||||
|
||||
BEGINRAW[Makefile]
|
||||
##### AES assembler implementations
|
||||
|
||||
|
||||
+1212
@@ -0,0 +1,1212 @@
|
||||
/*
|
||||
* Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (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
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2017 National Security Research Institute. All Rights Reserved.
|
||||
*
|
||||
* Information for ARIA
|
||||
* http://210.104.33.10/ARIA/index-e.html (English)
|
||||
* http://seed.kisa.or.kr/ (Korean)
|
||||
*
|
||||
* Public domain version is distributed above.
|
||||
*/
|
||||
|
||||
#include <openssl/e_os2.h>
|
||||
#include "internal/aria.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef OPENSSL_SMALL_FOOTPRINT
|
||||
|
||||
/* Begin macro */
|
||||
|
||||
/* rotation */
|
||||
#define rotl32(v, r) (((uint32_t)(v) << (r)) | ((uint32_t)(v) >> (32 - r)))
|
||||
#define rotr32(v, r) (((uint32_t)(v) >> (r)) | ((uint32_t)(v) << (32 - r)))
|
||||
|
||||
#define bswap32(v) \
|
||||
(((v) << 24) ^ ((v) >> 24) ^ \
|
||||
(((v) & 0x0000ff00) << 8) ^ (((v) & 0x00ff0000) >> 8))
|
||||
|
||||
#define GET_U8_BE(X, Y) ((uint8_t)((X) >> ((3 - Y) * 8)))
|
||||
#define GET_U32_BE(X, Y) ( \
|
||||
((uint32_t)((const uint8_t *)(X))[Y * 4 ] << 24) ^ \
|
||||
((uint32_t)((const uint8_t *)(X))[Y * 4 + 1] << 16) ^ \
|
||||
((uint32_t)((const uint8_t *)(X))[Y * 4 + 2] << 8) ^ \
|
||||
((uint32_t)((const uint8_t *)(X))[Y * 4 + 3] ) )
|
||||
|
||||
#define PUT_U32_BE(DEST, IDX, VAL) \
|
||||
do { \
|
||||
((uint8_t *)(DEST))[IDX * 4 ] = GET_U8_BE(VAL, 0); \
|
||||
((uint8_t *)(DEST))[IDX * 4 + 1] = GET_U8_BE(VAL, 1); \
|
||||
((uint8_t *)(DEST))[IDX * 4 + 2] = GET_U8_BE(VAL, 2); \
|
||||
((uint8_t *)(DEST))[IDX * 4 + 3] = GET_U8_BE(VAL, 3); \
|
||||
} while(0)
|
||||
|
||||
#define MAKE_U32(V0, V1, V2, V3) ( \
|
||||
((uint32_t)((uint8_t)(V0)) << 24) | \
|
||||
((uint32_t)((uint8_t)(V1)) << 16) | \
|
||||
((uint32_t)((uint8_t)(V2)) << 8) | \
|
||||
((uint32_t)((uint8_t)(V3)) ) )
|
||||
|
||||
/* End Macro*/
|
||||
|
||||
/* Key Constant
|
||||
* 128bit : 0, 1, 2
|
||||
* 192bit : 1, 2, 3(0)
|
||||
* 256bit : 2, 3(0), 4(1)
|
||||
*/
|
||||
static const uint32_t Key_RC[5][4] = {
|
||||
{ 0x517cc1b7, 0x27220a94, 0xfe13abe8, 0xfa9a6ee0 },
|
||||
{ 0x6db14acc, 0x9e21c820, 0xff28b1d5, 0xef5de2b0 },
|
||||
{ 0xdb92371d, 0x2126e970, 0x03249775, 0x04e8c90e },
|
||||
{ 0x517cc1b7, 0x27220a94, 0xfe13abe8, 0xfa9a6ee0 },
|
||||
{ 0x6db14acc, 0x9e21c820, 0xff28b1d5, 0xef5de2b0 }
|
||||
};
|
||||
|
||||
/* 32bit expanded s-box */
|
||||
static const uint32_t S1[256] = {
|
||||
0x00636363, 0x007c7c7c, 0x00777777, 0x007b7b7b,
|
||||
0x00f2f2f2, 0x006b6b6b, 0x006f6f6f, 0x00c5c5c5,
|
||||
0x00303030, 0x00010101, 0x00676767, 0x002b2b2b,
|
||||
0x00fefefe, 0x00d7d7d7, 0x00ababab, 0x00767676,
|
||||
0x00cacaca, 0x00828282, 0x00c9c9c9, 0x007d7d7d,
|
||||
0x00fafafa, 0x00595959, 0x00474747, 0x00f0f0f0,
|
||||
0x00adadad, 0x00d4d4d4, 0x00a2a2a2, 0x00afafaf,
|
||||
0x009c9c9c, 0x00a4a4a4, 0x00727272, 0x00c0c0c0,
|
||||
0x00b7b7b7, 0x00fdfdfd, 0x00939393, 0x00262626,
|
||||
0x00363636, 0x003f3f3f, 0x00f7f7f7, 0x00cccccc,
|
||||
0x00343434, 0x00a5a5a5, 0x00e5e5e5, 0x00f1f1f1,
|
||||
0x00717171, 0x00d8d8d8, 0x00313131, 0x00151515,
|
||||
0x00040404, 0x00c7c7c7, 0x00232323, 0x00c3c3c3,
|
||||
0x00181818, 0x00969696, 0x00050505, 0x009a9a9a,
|
||||
0x00070707, 0x00121212, 0x00808080, 0x00e2e2e2,
|
||||
0x00ebebeb, 0x00272727, 0x00b2b2b2, 0x00757575,
|
||||
0x00090909, 0x00838383, 0x002c2c2c, 0x001a1a1a,
|
||||
0x001b1b1b, 0x006e6e6e, 0x005a5a5a, 0x00a0a0a0,
|
||||
0x00525252, 0x003b3b3b, 0x00d6d6d6, 0x00b3b3b3,
|
||||
0x00292929, 0x00e3e3e3, 0x002f2f2f, 0x00848484,
|
||||
0x00535353, 0x00d1d1d1, 0x00000000, 0x00ededed,
|
||||
0x00202020, 0x00fcfcfc, 0x00b1b1b1, 0x005b5b5b,
|
||||
0x006a6a6a, 0x00cbcbcb, 0x00bebebe, 0x00393939,
|
||||
0x004a4a4a, 0x004c4c4c, 0x00585858, 0x00cfcfcf,
|
||||
0x00d0d0d0, 0x00efefef, 0x00aaaaaa, 0x00fbfbfb,
|
||||
0x00434343, 0x004d4d4d, 0x00333333, 0x00858585,
|
||||
0x00454545, 0x00f9f9f9, 0x00020202, 0x007f7f7f,
|
||||
0x00505050, 0x003c3c3c, 0x009f9f9f, 0x00a8a8a8,
|
||||
0x00515151, 0x00a3a3a3, 0x00404040, 0x008f8f8f,
|
||||
0x00929292, 0x009d9d9d, 0x00383838, 0x00f5f5f5,
|
||||
0x00bcbcbc, 0x00b6b6b6, 0x00dadada, 0x00212121,
|
||||
0x00101010, 0x00ffffff, 0x00f3f3f3, 0x00d2d2d2,
|
||||
0x00cdcdcd, 0x000c0c0c, 0x00131313, 0x00ececec,
|
||||
0x005f5f5f, 0x00979797, 0x00444444, 0x00171717,
|
||||
0x00c4c4c4, 0x00a7a7a7, 0x007e7e7e, 0x003d3d3d,
|
||||
0x00646464, 0x005d5d5d, 0x00191919, 0x00737373,
|
||||
0x00606060, 0x00818181, 0x004f4f4f, 0x00dcdcdc,
|
||||
0x00222222, 0x002a2a2a, 0x00909090, 0x00888888,
|
||||
0x00464646, 0x00eeeeee, 0x00b8b8b8, 0x00141414,
|
||||
0x00dedede, 0x005e5e5e, 0x000b0b0b, 0x00dbdbdb,
|
||||
0x00e0e0e0, 0x00323232, 0x003a3a3a, 0x000a0a0a,
|
||||
0x00494949, 0x00060606, 0x00242424, 0x005c5c5c,
|
||||
0x00c2c2c2, 0x00d3d3d3, 0x00acacac, 0x00626262,
|
||||
0x00919191, 0x00959595, 0x00e4e4e4, 0x00797979,
|
||||
0x00e7e7e7, 0x00c8c8c8, 0x00373737, 0x006d6d6d,
|
||||
0x008d8d8d, 0x00d5d5d5, 0x004e4e4e, 0x00a9a9a9,
|
||||
0x006c6c6c, 0x00565656, 0x00f4f4f4, 0x00eaeaea,
|
||||
0x00656565, 0x007a7a7a, 0x00aeaeae, 0x00080808,
|
||||
0x00bababa, 0x00787878, 0x00252525, 0x002e2e2e,
|
||||
0x001c1c1c, 0x00a6a6a6, 0x00b4b4b4, 0x00c6c6c6,
|
||||
0x00e8e8e8, 0x00dddddd, 0x00747474, 0x001f1f1f,
|
||||
0x004b4b4b, 0x00bdbdbd, 0x008b8b8b, 0x008a8a8a,
|
||||
0x00707070, 0x003e3e3e, 0x00b5b5b5, 0x00666666,
|
||||
0x00484848, 0x00030303, 0x00f6f6f6, 0x000e0e0e,
|
||||
0x00616161, 0x00353535, 0x00575757, 0x00b9b9b9,
|
||||
0x00868686, 0x00c1c1c1, 0x001d1d1d, 0x009e9e9e,
|
||||
0x00e1e1e1, 0x00f8f8f8, 0x00989898, 0x00111111,
|
||||
0x00696969, 0x00d9d9d9, 0x008e8e8e, 0x00949494,
|
||||
0x009b9b9b, 0x001e1e1e, 0x00878787, 0x00e9e9e9,
|
||||
0x00cecece, 0x00555555, 0x00282828, 0x00dfdfdf,
|
||||
0x008c8c8c, 0x00a1a1a1, 0x00898989, 0x000d0d0d,
|
||||
0x00bfbfbf, 0x00e6e6e6, 0x00424242, 0x00686868,
|
||||
0x00414141, 0x00999999, 0x002d2d2d, 0x000f0f0f,
|
||||
0x00b0b0b0, 0x00545454, 0x00bbbbbb, 0x00161616
|
||||
};
|
||||
|
||||
static const uint32_t S2[256] = {
|
||||
0xe200e2e2, 0x4e004e4e, 0x54005454, 0xfc00fcfc,
|
||||
0x94009494, 0xc200c2c2, 0x4a004a4a, 0xcc00cccc,
|
||||
0x62006262, 0x0d000d0d, 0x6a006a6a, 0x46004646,
|
||||
0x3c003c3c, 0x4d004d4d, 0x8b008b8b, 0xd100d1d1,
|
||||
0x5e005e5e, 0xfa00fafa, 0x64006464, 0xcb00cbcb,
|
||||
0xb400b4b4, 0x97009797, 0xbe00bebe, 0x2b002b2b,
|
||||
0xbc00bcbc, 0x77007777, 0x2e002e2e, 0x03000303,
|
||||
0xd300d3d3, 0x19001919, 0x59005959, 0xc100c1c1,
|
||||
0x1d001d1d, 0x06000606, 0x41004141, 0x6b006b6b,
|
||||
0x55005555, 0xf000f0f0, 0x99009999, 0x69006969,
|
||||
0xea00eaea, 0x9c009c9c, 0x18001818, 0xae00aeae,
|
||||
0x63006363, 0xdf00dfdf, 0xe700e7e7, 0xbb00bbbb,
|
||||
0x00000000, 0x73007373, 0x66006666, 0xfb00fbfb,
|
||||
0x96009696, 0x4c004c4c, 0x85008585, 0xe400e4e4,
|
||||
0x3a003a3a, 0x09000909, 0x45004545, 0xaa00aaaa,
|
||||
0x0f000f0f, 0xee00eeee, 0x10001010, 0xeb00ebeb,
|
||||
0x2d002d2d, 0x7f007f7f, 0xf400f4f4, 0x29002929,
|
||||
0xac00acac, 0xcf00cfcf, 0xad00adad, 0x91009191,
|
||||
0x8d008d8d, 0x78007878, 0xc800c8c8, 0x95009595,
|
||||
0xf900f9f9, 0x2f002f2f, 0xce00cece, 0xcd00cdcd,
|
||||
0x08000808, 0x7a007a7a, 0x88008888, 0x38003838,
|
||||
0x5c005c5c, 0x83008383, 0x2a002a2a, 0x28002828,
|
||||
0x47004747, 0xdb00dbdb, 0xb800b8b8, 0xc700c7c7,
|
||||
0x93009393, 0xa400a4a4, 0x12001212, 0x53005353,
|
||||
0xff00ffff, 0x87008787, 0x0e000e0e, 0x31003131,
|
||||
0x36003636, 0x21002121, 0x58005858, 0x48004848,
|
||||
0x01000101, 0x8e008e8e, 0x37003737, 0x74007474,
|
||||
0x32003232, 0xca00caca, 0xe900e9e9, 0xb100b1b1,
|
||||
0xb700b7b7, 0xab00abab, 0x0c000c0c, 0xd700d7d7,
|
||||
0xc400c4c4, 0x56005656, 0x42004242, 0x26002626,
|
||||
0x07000707, 0x98009898, 0x60006060, 0xd900d9d9,
|
||||
0xb600b6b6, 0xb900b9b9, 0x11001111, 0x40004040,
|
||||
0xec00ecec, 0x20002020, 0x8c008c8c, 0xbd00bdbd,
|
||||
0xa000a0a0, 0xc900c9c9, 0x84008484, 0x04000404,
|
||||
0x49004949, 0x23002323, 0xf100f1f1, 0x4f004f4f,
|
||||
0x50005050, 0x1f001f1f, 0x13001313, 0xdc00dcdc,
|
||||
0xd800d8d8, 0xc000c0c0, 0x9e009e9e, 0x57005757,
|
||||
0xe300e3e3, 0xc300c3c3, 0x7b007b7b, 0x65006565,
|
||||
0x3b003b3b, 0x02000202, 0x8f008f8f, 0x3e003e3e,
|
||||
0xe800e8e8, 0x25002525, 0x92009292, 0xe500e5e5,
|
||||
0x15001515, 0xdd00dddd, 0xfd00fdfd, 0x17001717,
|
||||
0xa900a9a9, 0xbf00bfbf, 0xd400d4d4, 0x9a009a9a,
|
||||
0x7e007e7e, 0xc500c5c5, 0x39003939, 0x67006767,
|
||||
0xfe00fefe, 0x76007676, 0x9d009d9d, 0x43004343,
|
||||
0xa700a7a7, 0xe100e1e1, 0xd000d0d0, 0xf500f5f5,
|
||||
0x68006868, 0xf200f2f2, 0x1b001b1b, 0x34003434,
|
||||
0x70007070, 0x05000505, 0xa300a3a3, 0x8a008a8a,
|
||||
0xd500d5d5, 0x79007979, 0x86008686, 0xa800a8a8,
|
||||
0x30003030, 0xc600c6c6, 0x51005151, 0x4b004b4b,
|
||||
0x1e001e1e, 0xa600a6a6, 0x27002727, 0xf600f6f6,
|
||||
0x35003535, 0xd200d2d2, 0x6e006e6e, 0x24002424,
|
||||
0x16001616, 0x82008282, 0x5f005f5f, 0xda00dada,
|
||||
0xe600e6e6, 0x75007575, 0xa200a2a2, 0xef00efef,
|
||||
0x2c002c2c, 0xb200b2b2, 0x1c001c1c, 0x9f009f9f,
|
||||
0x5d005d5d, 0x6f006f6f, 0x80008080, 0x0a000a0a,
|
||||
0x72007272, 0x44004444, 0x9b009b9b, 0x6c006c6c,
|
||||
0x90009090, 0x0b000b0b, 0x5b005b5b, 0x33003333,
|
||||
0x7d007d7d, 0x5a005a5a, 0x52005252, 0xf300f3f3,
|
||||
0x61006161, 0xa100a1a1, 0xf700f7f7, 0xb000b0b0,
|
||||
0xd600d6d6, 0x3f003f3f, 0x7c007c7c, 0x6d006d6d,
|
||||
0xed00eded, 0x14001414, 0xe000e0e0, 0xa500a5a5,
|
||||
0x3d003d3d, 0x22002222, 0xb300b3b3, 0xf800f8f8,
|
||||
0x89008989, 0xde00dede, 0x71007171, 0x1a001a1a,
|
||||
0xaf00afaf, 0xba00baba, 0xb500b5b5, 0x81008181
|
||||
};
|
||||
|
||||
static const uint32_t X1[256] = {
|
||||
0x52520052, 0x09090009, 0x6a6a006a, 0xd5d500d5,
|
||||
0x30300030, 0x36360036, 0xa5a500a5, 0x38380038,
|
||||
0xbfbf00bf, 0x40400040, 0xa3a300a3, 0x9e9e009e,
|
||||
0x81810081, 0xf3f300f3, 0xd7d700d7, 0xfbfb00fb,
|
||||
0x7c7c007c, 0xe3e300e3, 0x39390039, 0x82820082,
|
||||
0x9b9b009b, 0x2f2f002f, 0xffff00ff, 0x87870087,
|
||||
0x34340034, 0x8e8e008e, 0x43430043, 0x44440044,
|
||||
0xc4c400c4, 0xdede00de, 0xe9e900e9, 0xcbcb00cb,
|
||||
0x54540054, 0x7b7b007b, 0x94940094, 0x32320032,
|
||||
0xa6a600a6, 0xc2c200c2, 0x23230023, 0x3d3d003d,
|
||||
0xeeee00ee, 0x4c4c004c, 0x95950095, 0x0b0b000b,
|
||||
0x42420042, 0xfafa00fa, 0xc3c300c3, 0x4e4e004e,
|
||||
0x08080008, 0x2e2e002e, 0xa1a100a1, 0x66660066,
|
||||
0x28280028, 0xd9d900d9, 0x24240024, 0xb2b200b2,
|
||||
0x76760076, 0x5b5b005b, 0xa2a200a2, 0x49490049,
|
||||
0x6d6d006d, 0x8b8b008b, 0xd1d100d1, 0x25250025,
|
||||
0x72720072, 0xf8f800f8, 0xf6f600f6, 0x64640064,
|
||||
0x86860086, 0x68680068, 0x98980098, 0x16160016,
|
||||
0xd4d400d4, 0xa4a400a4, 0x5c5c005c, 0xcccc00cc,
|
||||
0x5d5d005d, 0x65650065, 0xb6b600b6, 0x92920092,
|
||||
0x6c6c006c, 0x70700070, 0x48480048, 0x50500050,
|
||||
0xfdfd00fd, 0xeded00ed, 0xb9b900b9, 0xdada00da,
|
||||
0x5e5e005e, 0x15150015, 0x46460046, 0x57570057,
|
||||
0xa7a700a7, 0x8d8d008d, 0x9d9d009d, 0x84840084,
|
||||
0x90900090, 0xd8d800d8, 0xabab00ab, 0x00000000,
|
||||
0x8c8c008c, 0xbcbc00bc, 0xd3d300d3, 0x0a0a000a,
|
||||
0xf7f700f7, 0xe4e400e4, 0x58580058, 0x05050005,
|
||||
0xb8b800b8, 0xb3b300b3, 0x45450045, 0x06060006,
|
||||
0xd0d000d0, 0x2c2c002c, 0x1e1e001e, 0x8f8f008f,
|
||||
0xcaca00ca, 0x3f3f003f, 0x0f0f000f, 0x02020002,
|
||||
0xc1c100c1, 0xafaf00af, 0xbdbd00bd, 0x03030003,
|
||||
0x01010001, 0x13130013, 0x8a8a008a, 0x6b6b006b,
|
||||
0x3a3a003a, 0x91910091, 0x11110011, 0x41410041,
|
||||
0x4f4f004f, 0x67670067, 0xdcdc00dc, 0xeaea00ea,
|
||||
0x97970097, 0xf2f200f2, 0xcfcf00cf, 0xcece00ce,
|
||||
0xf0f000f0, 0xb4b400b4, 0xe6e600e6, 0x73730073,
|
||||
0x96960096, 0xacac00ac, 0x74740074, 0x22220022,
|
||||
0xe7e700e7, 0xadad00ad, 0x35350035, 0x85850085,
|
||||
0xe2e200e2, 0xf9f900f9, 0x37370037, 0xe8e800e8,
|
||||
0x1c1c001c, 0x75750075, 0xdfdf00df, 0x6e6e006e,
|
||||
0x47470047, 0xf1f100f1, 0x1a1a001a, 0x71710071,
|
||||
0x1d1d001d, 0x29290029, 0xc5c500c5, 0x89890089,
|
||||
0x6f6f006f, 0xb7b700b7, 0x62620062, 0x0e0e000e,
|
||||
0xaaaa00aa, 0x18180018, 0xbebe00be, 0x1b1b001b,
|
||||
0xfcfc00fc, 0x56560056, 0x3e3e003e, 0x4b4b004b,
|
||||
0xc6c600c6, 0xd2d200d2, 0x79790079, 0x20200020,
|
||||
0x9a9a009a, 0xdbdb00db, 0xc0c000c0, 0xfefe00fe,
|
||||
0x78780078, 0xcdcd00cd, 0x5a5a005a, 0xf4f400f4,
|
||||
0x1f1f001f, 0xdddd00dd, 0xa8a800a8, 0x33330033,
|
||||
0x88880088, 0x07070007, 0xc7c700c7, 0x31310031,
|
||||
0xb1b100b1, 0x12120012, 0x10100010, 0x59590059,
|
||||
0x27270027, 0x80800080, 0xecec00ec, 0x5f5f005f,
|
||||
0x60600060, 0x51510051, 0x7f7f007f, 0xa9a900a9,
|
||||
0x19190019, 0xb5b500b5, 0x4a4a004a, 0x0d0d000d,
|
||||
0x2d2d002d, 0xe5e500e5, 0x7a7a007a, 0x9f9f009f,
|
||||
0x93930093, 0xc9c900c9, 0x9c9c009c, 0xefef00ef,
|
||||
0xa0a000a0, 0xe0e000e0, 0x3b3b003b, 0x4d4d004d,
|
||||
0xaeae00ae, 0x2a2a002a, 0xf5f500f5, 0xb0b000b0,
|
||||
0xc8c800c8, 0xebeb00eb, 0xbbbb00bb, 0x3c3c003c,
|
||||
0x83830083, 0x53530053, 0x99990099, 0x61610061,
|
||||
0x17170017, 0x2b2b002b, 0x04040004, 0x7e7e007e,
|
||||
0xbaba00ba, 0x77770077, 0xd6d600d6, 0x26260026,
|
||||
0xe1e100e1, 0x69690069, 0x14140014, 0x63630063,
|
||||
0x55550055, 0x21210021, 0x0c0c000c, 0x7d7d007d
|
||||
};
|
||||
|
||||
static const uint32_t X2[256] = {
|
||||
0x30303000, 0x68686800, 0x99999900, 0x1b1b1b00,
|
||||
0x87878700, 0xb9b9b900, 0x21212100, 0x78787800,
|
||||
0x50505000, 0x39393900, 0xdbdbdb00, 0xe1e1e100,
|
||||
0x72727200, 0x09090900, 0x62626200, 0x3c3c3c00,
|
||||
0x3e3e3e00, 0x7e7e7e00, 0x5e5e5e00, 0x8e8e8e00,
|
||||
0xf1f1f100, 0xa0a0a000, 0xcccccc00, 0xa3a3a300,
|
||||
0x2a2a2a00, 0x1d1d1d00, 0xfbfbfb00, 0xb6b6b600,
|
||||
0xd6d6d600, 0x20202000, 0xc4c4c400, 0x8d8d8d00,
|
||||
0x81818100, 0x65656500, 0xf5f5f500, 0x89898900,
|
||||
0xcbcbcb00, 0x9d9d9d00, 0x77777700, 0xc6c6c600,
|
||||
0x57575700, 0x43434300, 0x56565600, 0x17171700,
|
||||
0xd4d4d400, 0x40404000, 0x1a1a1a00, 0x4d4d4d00,
|
||||
0xc0c0c000, 0x63636300, 0x6c6c6c00, 0xe3e3e300,
|
||||
0xb7b7b700, 0xc8c8c800, 0x64646400, 0x6a6a6a00,
|
||||
0x53535300, 0xaaaaaa00, 0x38383800, 0x98989800,
|
||||
0x0c0c0c00, 0xf4f4f400, 0x9b9b9b00, 0xededed00,
|
||||
0x7f7f7f00, 0x22222200, 0x76767600, 0xafafaf00,
|
||||
0xdddddd00, 0x3a3a3a00, 0x0b0b0b00, 0x58585800,
|
||||
0x67676700, 0x88888800, 0x06060600, 0xc3c3c300,
|
||||
0x35353500, 0x0d0d0d00, 0x01010100, 0x8b8b8b00,
|
||||
0x8c8c8c00, 0xc2c2c200, 0xe6e6e600, 0x5f5f5f00,
|
||||
0x02020200, 0x24242400, 0x75757500, 0x93939300,
|
||||
0x66666600, 0x1e1e1e00, 0xe5e5e500, 0xe2e2e200,
|
||||
0x54545400, 0xd8d8d800, 0x10101000, 0xcecece00,
|
||||
0x7a7a7a00, 0xe8e8e800, 0x08080800, 0x2c2c2c00,
|
||||
0x12121200, 0x97979700, 0x32323200, 0xababab00,
|
||||
0xb4b4b400, 0x27272700, 0x0a0a0a00, 0x23232300,
|
||||
0xdfdfdf00, 0xefefef00, 0xcacaca00, 0xd9d9d900,
|
||||
0xb8b8b800, 0xfafafa00, 0xdcdcdc00, 0x31313100,
|
||||
0x6b6b6b00, 0xd1d1d100, 0xadadad00, 0x19191900,
|
||||
0x49494900, 0xbdbdbd00, 0x51515100, 0x96969600,
|
||||
0xeeeeee00, 0xe4e4e400, 0xa8a8a800, 0x41414100,
|
||||
0xdadada00, 0xffffff00, 0xcdcdcd00, 0x55555500,
|
||||
0x86868600, 0x36363600, 0xbebebe00, 0x61616100,
|
||||
0x52525200, 0xf8f8f800, 0xbbbbbb00, 0x0e0e0e00,
|
||||
0x82828200, 0x48484800, 0x69696900, 0x9a9a9a00,
|
||||
0xe0e0e000, 0x47474700, 0x9e9e9e00, 0x5c5c5c00,
|
||||
0x04040400, 0x4b4b4b00, 0x34343400, 0x15151500,
|
||||
0x79797900, 0x26262600, 0xa7a7a700, 0xdedede00,
|
||||
0x29292900, 0xaeaeae00, 0x92929200, 0xd7d7d700,
|
||||
0x84848400, 0xe9e9e900, 0xd2d2d200, 0xbababa00,
|
||||
0x5d5d5d00, 0xf3f3f300, 0xc5c5c500, 0xb0b0b000,
|
||||
0xbfbfbf00, 0xa4a4a400, 0x3b3b3b00, 0x71717100,
|
||||
0x44444400, 0x46464600, 0x2b2b2b00, 0xfcfcfc00,
|
||||
0xebebeb00, 0x6f6f6f00, 0xd5d5d500, 0xf6f6f600,
|
||||
0x14141400, 0xfefefe00, 0x7c7c7c00, 0x70707000,
|
||||
0x5a5a5a00, 0x7d7d7d00, 0xfdfdfd00, 0x2f2f2f00,
|
||||
0x18181800, 0x83838300, 0x16161600, 0xa5a5a500,
|
||||
0x91919100, 0x1f1f1f00, 0x05050500, 0x95959500,
|
||||
0x74747400, 0xa9a9a900, 0xc1c1c100, 0x5b5b5b00,
|
||||
0x4a4a4a00, 0x85858500, 0x6d6d6d00, 0x13131300,
|
||||
0x07070700, 0x4f4f4f00, 0x4e4e4e00, 0x45454500,
|
||||
0xb2b2b200, 0x0f0f0f00, 0xc9c9c900, 0x1c1c1c00,
|
||||
0xa6a6a600, 0xbcbcbc00, 0xececec00, 0x73737300,
|
||||
0x90909000, 0x7b7b7b00, 0xcfcfcf00, 0x59595900,
|
||||
0x8f8f8f00, 0xa1a1a100, 0xf9f9f900, 0x2d2d2d00,
|
||||
0xf2f2f200, 0xb1b1b100, 0x00000000, 0x94949400,
|
||||
0x37373700, 0x9f9f9f00, 0xd0d0d000, 0x2e2e2e00,
|
||||
0x9c9c9c00, 0x6e6e6e00, 0x28282800, 0x3f3f3f00,
|
||||
0x80808000, 0xf0f0f000, 0x3d3d3d00, 0xd3d3d300,
|
||||
0x25252500, 0x8a8a8a00, 0xb5b5b500, 0xe7e7e700,
|
||||
0x42424200, 0xb3b3b300, 0xc7c7c700, 0xeaeaea00,
|
||||
0xf7f7f700, 0x4c4c4c00, 0x11111100, 0x33333300,
|
||||
0x03030300, 0xa2a2a200, 0xacacac00, 0x60606000
|
||||
};
|
||||
|
||||
/* Key XOR Layer */
|
||||
#define ARIA_ADD_ROUND_KEY(RK, T0, T1, T2, T3) \
|
||||
do { \
|
||||
(T0) ^= (RK)->u[0]; \
|
||||
(T1) ^= (RK)->u[1]; \
|
||||
(T2) ^= (RK)->u[2]; \
|
||||
(T3) ^= (RK)->u[3]; \
|
||||
} while(0)
|
||||
|
||||
/* S-Box Layer 1 + M */
|
||||
#define ARIA_SBOX_LAYER1_WITH_PRE_DIFF(T0, T1, T2, T3) \
|
||||
do { \
|
||||
(T0) = \
|
||||
S1[GET_U8_BE(T0, 0)] ^ \
|
||||
S2[GET_U8_BE(T0, 1)] ^ \
|
||||
X1[GET_U8_BE(T0, 2)] ^ \
|
||||
X2[GET_U8_BE(T0, 3)]; \
|
||||
(T1) = \
|
||||
S1[GET_U8_BE(T1, 0)] ^ \
|
||||
S2[GET_U8_BE(T1, 1)] ^ \
|
||||
X1[GET_U8_BE(T1, 2)] ^ \
|
||||
X2[GET_U8_BE(T1, 3)]; \
|
||||
(T2) = \
|
||||
S1[GET_U8_BE(T2, 0)] ^ \
|
||||
S2[GET_U8_BE(T2, 1)] ^ \
|
||||
X1[GET_U8_BE(T2, 2)] ^ \
|
||||
X2[GET_U8_BE(T2, 3)]; \
|
||||
(T3) = \
|
||||
S1[GET_U8_BE(T3, 0)] ^ \
|
||||
S2[GET_U8_BE(T3, 1)] ^ \
|
||||
X1[GET_U8_BE(T3, 2)] ^ \
|
||||
X2[GET_U8_BE(T3, 3)]; \
|
||||
} while(0)
|
||||
|
||||
/* S-Box Layer 2 + M */
|
||||
#define ARIA_SBOX_LAYER2_WITH_PRE_DIFF(T0, T1, T2, T3) \
|
||||
do { \
|
||||
(T0) = \
|
||||
X1[GET_U8_BE(T0, 0)] ^ \
|
||||
X2[GET_U8_BE(T0, 1)] ^ \
|
||||
S1[GET_U8_BE(T0, 2)] ^ \
|
||||
S2[GET_U8_BE(T0, 3)]; \
|
||||
(T1) = \
|
||||
X1[GET_U8_BE(T1, 0)] ^ \
|
||||
X2[GET_U8_BE(T1, 1)] ^ \
|
||||
S1[GET_U8_BE(T1, 2)] ^ \
|
||||
S2[GET_U8_BE(T1, 3)]; \
|
||||
(T2) = \
|
||||
X1[GET_U8_BE(T2, 0)] ^ \
|
||||
X2[GET_U8_BE(T2, 1)] ^ \
|
||||
S1[GET_U8_BE(T2, 2)] ^ \
|
||||
S2[GET_U8_BE(T2, 3)]; \
|
||||
(T3) = \
|
||||
X1[GET_U8_BE(T3, 0)] ^ \
|
||||
X2[GET_U8_BE(T3, 1)] ^ \
|
||||
S1[GET_U8_BE(T3, 2)] ^ \
|
||||
S2[GET_U8_BE(T3, 3)]; \
|
||||
} while(0)
|
||||
|
||||
/* Word-level diffusion */
|
||||
#define ARIA_DIFF_WORD(T0,T1,T2,T3) \
|
||||
do { \
|
||||
(T1) ^= (T2); \
|
||||
(T2) ^= (T3); \
|
||||
(T0) ^= (T1); \
|
||||
\
|
||||
(T3) ^= (T1); \
|
||||
(T2) ^= (T0); \
|
||||
(T1) ^= (T2); \
|
||||
} while(0)
|
||||
|
||||
/* Byte-level diffusion */
|
||||
#define ARIA_DIFF_BYTE(T0, T1, T2, T3) \
|
||||
do { \
|
||||
(T1) = (((T1) << 8) & 0xff00ff00) ^ (((T1) >> 8) & 0x00ff00ff); \
|
||||
(T2) = rotr32(T2, 16); \
|
||||
(T3) = bswap32(T3); \
|
||||
} while(0)
|
||||
|
||||
/* Odd round Substitution & Diffusion */
|
||||
#define ARIA_SUBST_DIFF_ODD(T0, T1, T2, T3) \
|
||||
do { \
|
||||
ARIA_SBOX_LAYER1_WITH_PRE_DIFF(T0, T1, T2, T3); \
|
||||
ARIA_DIFF_WORD(T0, T1, T2, T3); \
|
||||
ARIA_DIFF_BYTE(T0, T1, T2, T3); \
|
||||
ARIA_DIFF_WORD(T0, T1, T2, T3); \
|
||||
} while(0)
|
||||
|
||||
/* Even round Substitution & Diffusion */
|
||||
#define ARIA_SUBST_DIFF_EVEN(T0, T1, T2, T3) \
|
||||
do { \
|
||||
ARIA_SBOX_LAYER2_WITH_PRE_DIFF(T0, T1, T2, T3); \
|
||||
ARIA_DIFF_WORD(T0, T1, T2, T3); \
|
||||
ARIA_DIFF_BYTE(T2, T3, T0, T1); \
|
||||
ARIA_DIFF_WORD(T0, T1, T2, T3); \
|
||||
} while(0)
|
||||
|
||||
/* Q, R Macro expanded ARIA GSRK */
|
||||
#define _ARIA_GSRK(RK, X, Y, Q, R) \
|
||||
do { \
|
||||
(RK)->u[0] = \
|
||||
((X)[0]) ^ \
|
||||
(((Y)[((Q) ) % 4]) >> (R)) ^ \
|
||||
(((Y)[((Q) + 3) % 4]) << (32 - (R))); \
|
||||
(RK)->u[1] = \
|
||||
((X)[1]) ^ \
|
||||
(((Y)[((Q) + 1) % 4]) >> (R)) ^ \
|
||||
(((Y)[((Q) ) % 4]) << (32 - (R))); \
|
||||
(RK)->u[2] = \
|
||||
((X)[2]) ^ \
|
||||
(((Y)[((Q) + 2) % 4]) >> (R)) ^ \
|
||||
(((Y)[((Q) + 1) % 4]) << (32 - (R))); \
|
||||
(RK)->u[3] = \
|
||||
((X)[3]) ^ \
|
||||
(((Y)[((Q) + 3) % 4]) >> (R)) ^ \
|
||||
(((Y)[((Q) + 2) % 4]) << (32 - (R))); \
|
||||
} while(0)
|
||||
|
||||
#define ARIA_GSRK(RK, X, Y, N) _ARIA_GSRK(RK, X, Y, 4 - ((N) / 32), (N) % 32)
|
||||
|
||||
#define ARIA_DEC_DIFF_BYTE(X, Y, TMP, TMP2) \
|
||||
do { \
|
||||
(TMP) = (X); \
|
||||
(TMP2) = rotr32((TMP), 8); \
|
||||
(Y) = (TMP2) ^ rotr32((TMP) ^ (TMP2), 16); \
|
||||
} while(0)
|
||||
|
||||
void aria_encrypt(const unsigned char *in, unsigned char *out,
|
||||
const ARIA_KEY *key)
|
||||
{
|
||||
register uint32_t reg0, reg1, reg2, reg3;
|
||||
int Nr;
|
||||
const ARIA_u128 *rk;
|
||||
|
||||
if (in == NULL || out == NULL || key == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
rk = key->rd_key;
|
||||
Nr = key->rounds;
|
||||
|
||||
if (Nr != 12 && Nr != 14 && Nr != 16) {
|
||||
return;
|
||||
}
|
||||
|
||||
reg0 = GET_U32_BE(in, 0);
|
||||
reg1 = GET_U32_BE(in, 1);
|
||||
reg2 = GET_U32_BE(in, 2);
|
||||
reg3 = GET_U32_BE(in, 3);
|
||||
|
||||
ARIA_ADD_ROUND_KEY(rk, reg0, reg1, reg2, reg3);
|
||||
rk++;
|
||||
|
||||
ARIA_SUBST_DIFF_ODD(reg0, reg1, reg2, reg3);
|
||||
ARIA_ADD_ROUND_KEY(rk, reg0, reg1, reg2, reg3);
|
||||
rk++;
|
||||
|
||||
while(Nr -= 2){
|
||||
ARIA_SUBST_DIFF_EVEN(reg0, reg1, reg2, reg3);
|
||||
ARIA_ADD_ROUND_KEY(rk, reg0, reg1, reg2, reg3);
|
||||
rk++;
|
||||
|
||||
ARIA_SUBST_DIFF_ODD(reg0, reg1, reg2, reg3);
|
||||
ARIA_ADD_ROUND_KEY(rk, reg0, reg1, reg2, reg3);
|
||||
rk++;
|
||||
}
|
||||
|
||||
reg0 = rk->u[0] ^ MAKE_U32(
|
||||
(uint8_t)(X1[GET_U8_BE(reg0, 0)] ),
|
||||
(uint8_t)(X2[GET_U8_BE(reg0, 1)] >> 8),
|
||||
(uint8_t)(S1[GET_U8_BE(reg0, 2)] ),
|
||||
(uint8_t)(S2[GET_U8_BE(reg0, 3)] ));
|
||||
reg1 = rk->u[1] ^ MAKE_U32(
|
||||
(uint8_t)(X1[GET_U8_BE(reg1, 0)] ),
|
||||
(uint8_t)(X2[GET_U8_BE(reg1, 1)] >> 8),
|
||||
(uint8_t)(S1[GET_U8_BE(reg1, 2)] ),
|
||||
(uint8_t)(S2[GET_U8_BE(reg1, 3)] ));
|
||||
reg2 = rk->u[2] ^ MAKE_U32(
|
||||
(uint8_t)(X1[GET_U8_BE(reg2, 0)] ),
|
||||
(uint8_t)(X2[GET_U8_BE(reg2, 1)] >> 8),
|
||||
(uint8_t)(S1[GET_U8_BE(reg2, 2)] ),
|
||||
(uint8_t)(S2[GET_U8_BE(reg2, 3)] ));
|
||||
reg3 = rk->u[3] ^ MAKE_U32(
|
||||
(uint8_t)(X1[GET_U8_BE(reg3, 0)] ),
|
||||
(uint8_t)(X2[GET_U8_BE(reg3, 1)] >> 8),
|
||||
(uint8_t)(S1[GET_U8_BE(reg3, 2)] ),
|
||||
(uint8_t)(S2[GET_U8_BE(reg3, 3)] ));
|
||||
|
||||
PUT_U32_BE(out, 0, reg0);
|
||||
PUT_U32_BE(out, 1, reg1);
|
||||
PUT_U32_BE(out, 2, reg2);
|
||||
PUT_U32_BE(out, 3, reg3);
|
||||
}
|
||||
|
||||
int aria_set_encrypt_key(const unsigned char *userKey, const int bits,
|
||||
ARIA_KEY *key)
|
||||
{
|
||||
register uint32_t reg0, reg1, reg2, reg3;
|
||||
uint32_t w0[4], w1[4], w2[4], w3[4];
|
||||
const uint32_t *ck;
|
||||
|
||||
ARIA_u128 *rk;
|
||||
int Nr = (bits + 256) / 32;
|
||||
|
||||
if (userKey == NULL || key == NULL) {
|
||||
return -1;
|
||||
}
|
||||
if (bits != 128 && bits != 192 && bits != 256) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
rk = key->rd_key;
|
||||
key->rounds = Nr;
|
||||
ck = &Key_RC[(bits - 128) / 64][0];
|
||||
|
||||
w0[0] = GET_U32_BE(userKey, 0);
|
||||
w0[1] = GET_U32_BE(userKey, 1);
|
||||
w0[2] = GET_U32_BE(userKey, 2);
|
||||
w0[3] = GET_U32_BE(userKey, 3);
|
||||
|
||||
reg0 = w0[0] ^ ck[0];
|
||||
reg1 = w0[1] ^ ck[1];
|
||||
reg2 = w0[2] ^ ck[2];
|
||||
reg3 = w0[3] ^ ck[3];
|
||||
|
||||
ARIA_SUBST_DIFF_ODD(reg0, reg1, reg2, reg3);
|
||||
|
||||
if (bits > 128) {
|
||||
w1[0] = GET_U32_BE(userKey, 4);
|
||||
w1[1] = GET_U32_BE(userKey, 5);
|
||||
if (bits > 192) {
|
||||
w1[2] = GET_U32_BE(userKey, 6);
|
||||
w1[3] = GET_U32_BE(userKey, 7);
|
||||
}
|
||||
else {
|
||||
w1[2] = w1[3] = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
w1[0] = w1[1] = w1[2] = w1[3] = 0;
|
||||
}
|
||||
|
||||
w1[0] ^= reg0;
|
||||
w1[1] ^= reg1;
|
||||
w1[2] ^= reg2;
|
||||
w1[3] ^= reg3;
|
||||
|
||||
reg0 = w1[0];
|
||||
reg1 = w1[1];
|
||||
reg2 = w1[2];
|
||||
reg3 = w1[3];
|
||||
|
||||
reg0 ^= ck[4];
|
||||
reg1 ^= ck[5];
|
||||
reg2 ^= ck[6];
|
||||
reg3 ^= ck[7];
|
||||
|
||||
ARIA_SUBST_DIFF_EVEN(reg0, reg1, reg2, reg3);
|
||||
|
||||
reg0 ^= w0[0];
|
||||
reg1 ^= w0[1];
|
||||
reg2 ^= w0[2];
|
||||
reg3 ^= w0[3];
|
||||
|
||||
w2[0] = reg0;
|
||||
w2[1] = reg1;
|
||||
w2[2] = reg2;
|
||||
w2[3] = reg3;
|
||||
|
||||
reg0 ^= ck[8];
|
||||
reg1 ^= ck[9];
|
||||
reg2 ^= ck[10];
|
||||
reg3 ^= ck[11];
|
||||
|
||||
ARIA_SUBST_DIFF_ODD(reg0, reg1, reg2, reg3);
|
||||
|
||||
w3[0] = reg0 ^ w1[0];
|
||||
w3[1] = reg1 ^ w1[1];
|
||||
w3[2] = reg2 ^ w1[2];
|
||||
w3[3] = reg3 ^ w1[3];
|
||||
|
||||
ARIA_GSRK(rk, w0, w1, 19);
|
||||
rk++;
|
||||
ARIA_GSRK(rk, w1, w2, 19);
|
||||
rk++;
|
||||
ARIA_GSRK(rk, w2, w3, 19);
|
||||
rk++;
|
||||
ARIA_GSRK(rk, w3, w0, 19);
|
||||
|
||||
rk++;
|
||||
ARIA_GSRK(rk, w0, w1, 31);
|
||||
rk++;
|
||||
ARIA_GSRK(rk, w1, w2, 31);
|
||||
rk++;
|
||||
ARIA_GSRK(rk, w2, w3, 31);
|
||||
rk++;
|
||||
ARIA_GSRK(rk, w3, w0, 31);
|
||||
|
||||
rk++;
|
||||
ARIA_GSRK(rk, w0, w1, 67);
|
||||
rk++;
|
||||
ARIA_GSRK(rk, w1, w2, 67);
|
||||
rk++;
|
||||
ARIA_GSRK(rk, w2, w3, 67);
|
||||
rk++;
|
||||
ARIA_GSRK(rk, w3, w0, 67);
|
||||
|
||||
rk++;
|
||||
ARIA_GSRK(rk, w0, w1, 97);
|
||||
if (bits > 128) {
|
||||
rk++;
|
||||
ARIA_GSRK(rk, w1, w2, 97);
|
||||
rk++;
|
||||
ARIA_GSRK(rk, w2, w3, 97);
|
||||
}
|
||||
if (bits > 192) {
|
||||
rk++;
|
||||
ARIA_GSRK(rk, w3, w0, 97);
|
||||
|
||||
rk++;
|
||||
ARIA_GSRK(rk, w0, w1, 109);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int aria_set_decrypt_key(const unsigned char *userKey, const int bits,
|
||||
ARIA_KEY *key)
|
||||
{
|
||||
ARIA_u128 *rk_head;
|
||||
ARIA_u128 *rk_tail;
|
||||
register uint32_t w1, w2;
|
||||
register uint32_t reg0, reg1, reg2, reg3;
|
||||
uint32_t s0, s1, s2, s3;
|
||||
|
||||
const int r = aria_set_encrypt_key(userKey, bits, key);
|
||||
|
||||
if (r != 0) {
|
||||
return r;
|
||||
}
|
||||
|
||||
rk_head = key->rd_key;
|
||||
rk_tail = rk_head + key->rounds;
|
||||
|
||||
reg0 = rk_head->u[0];
|
||||
reg1 = rk_head->u[1];
|
||||
reg2 = rk_head->u[2];
|
||||
reg3 = rk_head->u[3];
|
||||
|
||||
memcpy(rk_head, rk_tail, ARIA_BLOCK_SIZE);
|
||||
|
||||
rk_tail->u[0] = reg0;
|
||||
rk_tail->u[1] = reg1;
|
||||
rk_tail->u[2] = reg2;
|
||||
rk_tail->u[3] = reg3;
|
||||
|
||||
rk_head++;
|
||||
rk_tail--;
|
||||
|
||||
for (; rk_head < rk_tail; rk_head++, rk_tail--) {
|
||||
ARIA_DEC_DIFF_BYTE(rk_head->u[0], reg0, w1, w2);
|
||||
ARIA_DEC_DIFF_BYTE(rk_head->u[1], reg1, w1, w2);
|
||||
ARIA_DEC_DIFF_BYTE(rk_head->u[2], reg2, w1, w2);
|
||||
ARIA_DEC_DIFF_BYTE(rk_head->u[3], reg3, w1, w2);
|
||||
|
||||
ARIA_DIFF_WORD(reg0, reg1, reg2, reg3);
|
||||
ARIA_DIFF_BYTE(reg0, reg1, reg2, reg3);
|
||||
ARIA_DIFF_WORD(reg0, reg1, reg2, reg3);
|
||||
|
||||
s0 = reg0;
|
||||
s1 = reg1;
|
||||
s2 = reg2;
|
||||
s3 = reg3;
|
||||
|
||||
ARIA_DEC_DIFF_BYTE(rk_tail->u[0], reg0, w1, w2);
|
||||
ARIA_DEC_DIFF_BYTE(rk_tail->u[1], reg1, w1, w2);
|
||||
ARIA_DEC_DIFF_BYTE(rk_tail->u[2], reg2, w1, w2);
|
||||
ARIA_DEC_DIFF_BYTE(rk_tail->u[3], reg3, w1, w2);
|
||||
|
||||
ARIA_DIFF_WORD(reg0, reg1, reg2, reg3);
|
||||
ARIA_DIFF_BYTE(reg0, reg1, reg2, reg3);
|
||||
ARIA_DIFF_WORD(reg0, reg1, reg2, reg3);
|
||||
|
||||
rk_head->u[0] = reg0;
|
||||
rk_head->u[1] = reg1;
|
||||
rk_head->u[2] = reg2;
|
||||
rk_head->u[3] = reg3;
|
||||
|
||||
rk_tail->u[0] = s0;
|
||||
rk_tail->u[1] = s1;
|
||||
rk_tail->u[2] = s2;
|
||||
rk_tail->u[3] = s3;
|
||||
}
|
||||
ARIA_DEC_DIFF_BYTE(rk_head->u[0], reg0, w1, w2);
|
||||
ARIA_DEC_DIFF_BYTE(rk_head->u[1], reg1, w1, w2);
|
||||
ARIA_DEC_DIFF_BYTE(rk_head->u[2], reg2, w1, w2);
|
||||
ARIA_DEC_DIFF_BYTE(rk_head->u[3], reg3, w1, w2);
|
||||
|
||||
ARIA_DIFF_WORD(reg0, reg1, reg2, reg3);
|
||||
ARIA_DIFF_BYTE(reg0, reg1, reg2, reg3);
|
||||
ARIA_DIFF_WORD(reg0, reg1, reg2, reg3);
|
||||
|
||||
rk_tail->u[0] = reg0;
|
||||
rk_tail->u[1] = reg1;
|
||||
rk_tail->u[2] = reg2;
|
||||
rk_tail->u[3] = reg3;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static const unsigned char sb1[256] = {
|
||||
0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5,
|
||||
0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
|
||||
0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
|
||||
0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
|
||||
0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc,
|
||||
0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
|
||||
0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a,
|
||||
0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
|
||||
0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
|
||||
0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
|
||||
0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b,
|
||||
0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
|
||||
0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85,
|
||||
0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
|
||||
0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
|
||||
0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
|
||||
0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17,
|
||||
0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
|
||||
0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88,
|
||||
0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
|
||||
0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
|
||||
0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
|
||||
0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9,
|
||||
0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
|
||||
0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6,
|
||||
0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
|
||||
0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
|
||||
0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
|
||||
0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94,
|
||||
0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
|
||||
0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68,
|
||||
0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16
|
||||
};
|
||||
|
||||
static const unsigned char sb2[256] = {
|
||||
0xe2, 0x4e, 0x54, 0xfc, 0x94, 0xc2, 0x4a, 0xcc,
|
||||
0x62, 0x0d, 0x6a, 0x46, 0x3c, 0x4d, 0x8b, 0xd1,
|
||||
0x5e, 0xfa, 0x64, 0xcb, 0xb4, 0x97, 0xbe, 0x2b,
|
||||
0xbc, 0x77, 0x2e, 0x03, 0xd3, 0x19, 0x59, 0xc1,
|
||||
0x1d, 0x06, 0x41, 0x6b, 0x55, 0xf0, 0x99, 0x69,
|
||||
0xea, 0x9c, 0x18, 0xae, 0x63, 0xdf, 0xe7, 0xbb,
|
||||
0x00, 0x73, 0x66, 0xfb, 0x96, 0x4c, 0x85, 0xe4,
|
||||
0x3a, 0x09, 0x45, 0xaa, 0x0f, 0xee, 0x10, 0xeb,
|
||||
0x2d, 0x7f, 0xf4, 0x29, 0xac, 0xcf, 0xad, 0x91,
|
||||
0x8d, 0x78, 0xc8, 0x95, 0xf9, 0x2f, 0xce, 0xcd,
|
||||
0x08, 0x7a, 0x88, 0x38, 0x5c, 0x83, 0x2a, 0x28,
|
||||
0x47, 0xdb, 0xb8, 0xc7, 0x93, 0xa4, 0x12, 0x53,
|
||||
0xff, 0x87, 0x0e, 0x31, 0x36, 0x21, 0x58, 0x48,
|
||||
0x01, 0x8e, 0x37, 0x74, 0x32, 0xca, 0xe9, 0xb1,
|
||||
0xb7, 0xab, 0x0c, 0xd7, 0xc4, 0x56, 0x42, 0x26,
|
||||
0x07, 0x98, 0x60, 0xd9, 0xb6, 0xb9, 0x11, 0x40,
|
||||
0xec, 0x20, 0x8c, 0xbd, 0xa0, 0xc9, 0x84, 0x04,
|
||||
0x49, 0x23, 0xf1, 0x4f, 0x50, 0x1f, 0x13, 0xdc,
|
||||
0xd8, 0xc0, 0x9e, 0x57, 0xe3, 0xc3, 0x7b, 0x65,
|
||||
0x3b, 0x02, 0x8f, 0x3e, 0xe8, 0x25, 0x92, 0xe5,
|
||||
0x15, 0xdd, 0xfd, 0x17, 0xa9, 0xbf, 0xd4, 0x9a,
|
||||
0x7e, 0xc5, 0x39, 0x67, 0xfe, 0x76, 0x9d, 0x43,
|
||||
0xa7, 0xe1, 0xd0, 0xf5, 0x68, 0xf2, 0x1b, 0x34,
|
||||
0x70, 0x05, 0xa3, 0x8a, 0xd5, 0x79, 0x86, 0xa8,
|
||||
0x30, 0xc6, 0x51, 0x4b, 0x1e, 0xa6, 0x27, 0xf6,
|
||||
0x35, 0xd2, 0x6e, 0x24, 0x16, 0x82, 0x5f, 0xda,
|
||||
0xe6, 0x75, 0xa2, 0xef, 0x2c, 0xb2, 0x1c, 0x9f,
|
||||
0x5d, 0x6f, 0x80, 0x0a, 0x72, 0x44, 0x9b, 0x6c,
|
||||
0x90, 0x0b, 0x5b, 0x33, 0x7d, 0x5a, 0x52, 0xf3,
|
||||
0x61, 0xa1, 0xf7, 0xb0, 0xd6, 0x3f, 0x7c, 0x6d,
|
||||
0xed, 0x14, 0xe0, 0xa5, 0x3d, 0x22, 0xb3, 0xf8,
|
||||
0x89, 0xde, 0x71, 0x1a, 0xaf, 0xba, 0xb5, 0x81
|
||||
};
|
||||
|
||||
static const unsigned char sb3[256] = {
|
||||
0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38,
|
||||
0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb,
|
||||
0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
|
||||
0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb,
|
||||
0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d,
|
||||
0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
|
||||
0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2,
|
||||
0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25,
|
||||
0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
|
||||
0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92,
|
||||
0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda,
|
||||
0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
|
||||
0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a,
|
||||
0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06,
|
||||
0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
|
||||
0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b,
|
||||
0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea,
|
||||
0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
|
||||
0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85,
|
||||
0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e,
|
||||
0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
|
||||
0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b,
|
||||
0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20,
|
||||
0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
|
||||
0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31,
|
||||
0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f,
|
||||
0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
|
||||
0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef,
|
||||
0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0,
|
||||
0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
|
||||
0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26,
|
||||
0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d
|
||||
};
|
||||
|
||||
static const unsigned char sb4[256] = {
|
||||
0x30, 0x68, 0x99, 0x1b, 0x87, 0xb9, 0x21, 0x78,
|
||||
0x50, 0x39, 0xdb, 0xe1, 0x72, 0x09, 0x62, 0x3c,
|
||||
0x3e, 0x7e, 0x5e, 0x8e, 0xf1, 0xa0, 0xcc, 0xa3,
|
||||
0x2a, 0x1d, 0xfb, 0xb6, 0xd6, 0x20, 0xc4, 0x8d,
|
||||
0x81, 0x65, 0xf5, 0x89, 0xcb, 0x9d, 0x77, 0xc6,
|
||||
0x57, 0x43, 0x56, 0x17, 0xd4, 0x40, 0x1a, 0x4d,
|
||||
0xc0, 0x63, 0x6c, 0xe3, 0xb7, 0xc8, 0x64, 0x6a,
|
||||
0x53, 0xaa, 0x38, 0x98, 0x0c, 0xf4, 0x9b, 0xed,
|
||||
0x7f, 0x22, 0x76, 0xaf, 0xdd, 0x3a, 0x0b, 0x58,
|
||||
0x67, 0x88, 0x06, 0xc3, 0x35, 0x0d, 0x01, 0x8b,
|
||||
0x8c, 0xc2, 0xe6, 0x5f, 0x02, 0x24, 0x75, 0x93,
|
||||
0x66, 0x1e, 0xe5, 0xe2, 0x54, 0xd8, 0x10, 0xce,
|
||||
0x7a, 0xe8, 0x08, 0x2c, 0x12, 0x97, 0x32, 0xab,
|
||||
0xb4, 0x27, 0x0a, 0x23, 0xdf, 0xef, 0xca, 0xd9,
|
||||
0xb8, 0xfa, 0xdc, 0x31, 0x6b, 0xd1, 0xad, 0x19,
|
||||
0x49, 0xbd, 0x51, 0x96, 0xee, 0xe4, 0xa8, 0x41,
|
||||
0xda, 0xff, 0xcd, 0x55, 0x86, 0x36, 0xbe, 0x61,
|
||||
0x52, 0xf8, 0xbb, 0x0e, 0x82, 0x48, 0x69, 0x9a,
|
||||
0xe0, 0x47, 0x9e, 0x5c, 0x04, 0x4b, 0x34, 0x15,
|
||||
0x79, 0x26, 0xa7, 0xde, 0x29, 0xae, 0x92, 0xd7,
|
||||
0x84, 0xe9, 0xd2, 0xba, 0x5d, 0xf3, 0xc5, 0xb0,
|
||||
0xbf, 0xa4, 0x3b, 0x71, 0x44, 0x46, 0x2b, 0xfc,
|
||||
0xeb, 0x6f, 0xd5, 0xf6, 0x14, 0xfe, 0x7c, 0x70,
|
||||
0x5a, 0x7d, 0xfd, 0x2f, 0x18, 0x83, 0x16, 0xa5,
|
||||
0x91, 0x1f, 0x05, 0x95, 0x74, 0xa9, 0xc1, 0x5b,
|
||||
0x4a, 0x85, 0x6d, 0x13, 0x07, 0x4f, 0x4e, 0x45,
|
||||
0xb2, 0x0f, 0xc9, 0x1c, 0xa6, 0xbc, 0xec, 0x73,
|
||||
0x90, 0x7b, 0xcf, 0x59, 0x8f, 0xa1, 0xf9, 0x2d,
|
||||
0xf2, 0xb1, 0x00, 0x94, 0x37, 0x9f, 0xd0, 0x2e,
|
||||
0x9c, 0x6e, 0x28, 0x3f, 0x80, 0xf0, 0x3d, 0xd3,
|
||||
0x25, 0x8a, 0xb5, 0xe7, 0x42, 0xb3, 0xc7, 0xea,
|
||||
0xf7, 0x4c, 0x11, 0x33, 0x03, 0xa2, 0xac, 0x60
|
||||
};
|
||||
|
||||
static const ARIA_u128 c1 = {{
|
||||
0x51, 0x7c, 0xc1, 0xb7, 0x27, 0x22, 0x0a, 0x94,
|
||||
0xfe, 0x13, 0xab, 0xe8, 0xfa, 0x9a, 0x6e, 0xe0
|
||||
}};
|
||||
|
||||
static const ARIA_u128 c2 = {{
|
||||
0x6d, 0xb1, 0x4a, 0xcc, 0x9e, 0x21, 0xc8, 0x20,
|
||||
0xff, 0x28, 0xb1, 0xd5, 0xef, 0x5d, 0xe2, 0xb0
|
||||
}};
|
||||
|
||||
static const ARIA_u128 c3 = {{
|
||||
0xdb, 0x92, 0x37, 0x1d, 0x21, 0x26, 0xe9, 0x70,
|
||||
0x03, 0x24, 0x97, 0x75, 0x04, 0xe8, 0xc9, 0x0e
|
||||
}};
|
||||
|
||||
/*
|
||||
* Exclusive or two 128 bit values into the result.
|
||||
* It is safe for the result to be the same as the either input.
|
||||
*/
|
||||
static void xor128(ARIA_c128 o, const ARIA_c128 x, const ARIA_u128 *y)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARIA_BLOCK_SIZE; i++)
|
||||
o[i] = x[i] ^ y->c[i];
|
||||
}
|
||||
|
||||
/*
|
||||
* Generalised circular rotate right and exclusive or function.
|
||||
* It is safe for the output to overlap either input.
|
||||
*/
|
||||
static ossl_inline void rotnr(unsigned int n, ARIA_u128 *o,
|
||||
const ARIA_u128 *xor, const ARIA_u128 *z)
|
||||
{
|
||||
const unsigned int bytes = n / 8, bits = n % 8;
|
||||
unsigned int i;
|
||||
ARIA_u128 t;
|
||||
|
||||
for (i = 0; i < ARIA_BLOCK_SIZE; i++)
|
||||
t.c[(i + bytes) % ARIA_BLOCK_SIZE] = z->c[i];
|
||||
for (i = 0; i < ARIA_BLOCK_SIZE; i++)
|
||||
o->c[i] = ((t.c[i] >> bits) |
|
||||
(t.c[i ? i - 1 : ARIA_BLOCK_SIZE - 1] << (8 - bits))) ^
|
||||
xor->c[i];
|
||||
}
|
||||
|
||||
/*
|
||||
* Circular rotate 19 bits right and xor.
|
||||
* It is safe for the output to overlap either input.
|
||||
*/
|
||||
static void rot19r(ARIA_u128 *o, const ARIA_u128 *xor, const ARIA_u128 *z)
|
||||
{
|
||||
rotnr(19, o, xor, z);
|
||||
}
|
||||
|
||||
/*
|
||||
* Circular rotate 31 bits right and xor.
|
||||
* It is safe for the output to overlap either input.
|
||||
*/
|
||||
static void rot31r(ARIA_u128 *o, const ARIA_u128 *xor, const ARIA_u128 *z)
|
||||
{
|
||||
rotnr(31, o, xor, z);
|
||||
}
|
||||
|
||||
/*
|
||||
* Circular rotate 61 bits left and xor.
|
||||
* It is safe for the output to overlap either input.
|
||||
*/
|
||||
static void rot61l(ARIA_u128 *o, const ARIA_u128 *xor, const ARIA_u128 *z)
|
||||
{
|
||||
rotnr(8 * ARIA_BLOCK_SIZE - 61, o, xor, z);
|
||||
}
|
||||
|
||||
/*
|
||||
* Circular rotate 31 bits left and xor.
|
||||
* It is safe for the output to overlap either input.
|
||||
*/
|
||||
static void rot31l(ARIA_u128 *o, const ARIA_u128 *xor, const ARIA_u128 *z)
|
||||
{
|
||||
rotnr(8 * ARIA_BLOCK_SIZE - 31, o, xor, z);
|
||||
}
|
||||
|
||||
/*
|
||||
* Circular rotate 19 bits left and xor.
|
||||
* It is safe for the output to overlap either input.
|
||||
*/
|
||||
static void rot19l(ARIA_u128 *o, const ARIA_u128 *xor, const ARIA_u128 *z)
|
||||
{
|
||||
rotnr(8 * ARIA_BLOCK_SIZE - 19, o, xor, z);
|
||||
}
|
||||
|
||||
/*
|
||||
* First substitution and xor layer, used for odd steps.
|
||||
* It is safe for the input and output to be the same.
|
||||
*/
|
||||
static void sl1(ARIA_u128 *o, const ARIA_u128 *x, const ARIA_u128 *y)
|
||||
{
|
||||
unsigned int i;
|
||||
for (i = 0; i < ARIA_BLOCK_SIZE; i += 4) {
|
||||
o->c[i ] = sb1[x->c[i ] ^ y->c[i ]];
|
||||
o->c[i + 1] = sb2[x->c[i + 1] ^ y->c[i + 1]];
|
||||
o->c[i + 2] = sb3[x->c[i + 2] ^ y->c[i + 2]];
|
||||
o->c[i + 3] = sb4[x->c[i + 3] ^ y->c[i + 3]];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Second substitution and xor layer, used for even steps.
|
||||
* It is safe for the input and output to be the same.
|
||||
*/
|
||||
static void sl2(ARIA_c128 o, const ARIA_u128 *x, const ARIA_u128 *y)
|
||||
{
|
||||
unsigned int i;
|
||||
for (i = 0; i < ARIA_BLOCK_SIZE; i += 4) {
|
||||
o[i ] = sb3[x->c[i ] ^ y->c[i ]];
|
||||
o[i + 1] = sb4[x->c[i + 1] ^ y->c[i + 1]];
|
||||
o[i + 2] = sb1[x->c[i + 2] ^ y->c[i + 2]];
|
||||
o[i + 3] = sb2[x->c[i + 3] ^ y->c[i + 3]];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Diffusion layer step
|
||||
* It is NOT safe for the input and output to overlap.
|
||||
*/
|
||||
static void a(ARIA_u128 *y, const ARIA_u128 *x)
|
||||
{
|
||||
y->c[ 0] = x->c[ 3] ^ x->c[ 4] ^ x->c[ 6] ^ x->c[ 8] ^
|
||||
x->c[ 9] ^ x->c[13] ^ x->c[14];
|
||||
y->c[ 1] = x->c[ 2] ^ x->c[ 5] ^ x->c[ 7] ^ x->c[ 8] ^
|
||||
x->c[ 9] ^ x->c[12] ^ x->c[15];
|
||||
y->c[ 2] = x->c[ 1] ^ x->c[ 4] ^ x->c[ 6] ^ x->c[10] ^
|
||||
x->c[11] ^ x->c[12] ^ x->c[15];
|
||||
y->c[ 3] = x->c[ 0] ^ x->c[ 5] ^ x->c[ 7] ^ x->c[10] ^
|
||||
x->c[11] ^ x->c[13] ^ x->c[14];
|
||||
y->c[ 4] = x->c[ 0] ^ x->c[ 2] ^ x->c[ 5] ^ x->c[ 8] ^
|
||||
x->c[11] ^ x->c[14] ^ x->c[15];
|
||||
y->c[ 5] = x->c[ 1] ^ x->c[ 3] ^ x->c[ 4] ^ x->c[ 9] ^
|
||||
x->c[10] ^ x->c[14] ^ x->c[15];
|
||||
y->c[ 6] = x->c[ 0] ^ x->c[ 2] ^ x->c[ 7] ^ x->c[ 9] ^
|
||||
x->c[10] ^ x->c[12] ^ x->c[13];
|
||||
y->c[ 7] = x->c[ 1] ^ x->c[ 3] ^ x->c[ 6] ^ x->c[ 8] ^
|
||||
x->c[11] ^ x->c[12] ^ x->c[13];
|
||||
y->c[ 8] = x->c[ 0] ^ x->c[ 1] ^ x->c[ 4] ^ x->c[ 7] ^
|
||||
x->c[10] ^ x->c[13] ^ x->c[15];
|
||||
y->c[ 9] = x->c[ 0] ^ x->c[ 1] ^ x->c[ 5] ^ x->c[ 6] ^
|
||||
x->c[11] ^ x->c[12] ^ x->c[14];
|
||||
y->c[10] = x->c[ 2] ^ x->c[ 3] ^ x->c[ 5] ^ x->c[ 6] ^
|
||||
x->c[ 8] ^ x->c[13] ^ x->c[15];
|
||||
y->c[11] = x->c[ 2] ^ x->c[ 3] ^ x->c[ 4] ^ x->c[ 7] ^
|
||||
x->c[ 9] ^ x->c[12] ^ x->c[14];
|
||||
y->c[12] = x->c[ 1] ^ x->c[ 2] ^ x->c[ 6] ^ x->c[ 7] ^
|
||||
x->c[ 9] ^ x->c[11] ^ x->c[12];
|
||||
y->c[13] = x->c[ 0] ^ x->c[ 3] ^ x->c[ 6] ^ x->c[ 7] ^
|
||||
x->c[ 8] ^ x->c[10] ^ x->c[13];
|
||||
y->c[14] = x->c[ 0] ^ x->c[ 3] ^ x->c[ 4] ^ x->c[ 5] ^
|
||||
x->c[ 9] ^ x->c[11] ^ x->c[14];
|
||||
y->c[15] = x->c[ 1] ^ x->c[ 2] ^ x->c[ 4] ^ x->c[ 5] ^
|
||||
x->c[ 8] ^ x->c[10] ^ x->c[15];
|
||||
}
|
||||
|
||||
/*
|
||||
* Odd round function
|
||||
* Apply the first substitution layer and then a diffusion step.
|
||||
* It is safe for the input and output to overlap.
|
||||
*/
|
||||
static ossl_inline void FO(ARIA_u128 *o, const ARIA_u128 *d,
|
||||
const ARIA_u128 *rk)
|
||||
{
|
||||
ARIA_u128 y;
|
||||
|
||||
sl1(&y, d, rk);
|
||||
a(o, &y);
|
||||
}
|
||||
|
||||
/*
|
||||
* Even round function
|
||||
* Apply the second substitution layer and then a diffusion step.
|
||||
* It is safe for the input and output to overlap.
|
||||
*/
|
||||
static ossl_inline void FE(ARIA_u128 *o, const ARIA_u128 *d,
|
||||
const ARIA_u128 *rk)
|
||||
{
|
||||
ARIA_u128 y;
|
||||
|
||||
sl2(y.c, d, rk);
|
||||
a(o, &y);
|
||||
}
|
||||
|
||||
/*
|
||||
* Encrypt or decrypt a single block
|
||||
* in and out can overlap
|
||||
*/
|
||||
static void do_encrypt(unsigned char *o, const unsigned char *pin,
|
||||
unsigned int rounds, const ARIA_u128 *keys)
|
||||
{
|
||||
ARIA_u128 p;
|
||||
unsigned int i;
|
||||
|
||||
memcpy(&p, pin, sizeof(p));
|
||||
for (i = 0; i < rounds - 2; i += 2) {
|
||||
FO(&p, &p, &keys[i]);
|
||||
FE(&p, &p, &keys[i + 1]);
|
||||
}
|
||||
FO(&p, &p, &keys[rounds - 2]);
|
||||
sl2(o, &p, &keys[rounds - 1]);
|
||||
xor128(o, o, &keys[rounds]);
|
||||
}
|
||||
|
||||
/*
|
||||
* Encrypt a single block
|
||||
* in and out can overlap
|
||||
*/
|
||||
void aria_encrypt(const unsigned char *in, unsigned char *out,
|
||||
const ARIA_KEY *key)
|
||||
{
|
||||
assert(in != NULL && out != NULL && key != NULL);
|
||||
do_encrypt(out, in, key->rounds, key->rd_key);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Expand the cipher key into the encryption key schedule.
|
||||
* We short circuit execution of the last two
|
||||
* or four rotations based on the key size.
|
||||
*/
|
||||
int aria_set_encrypt_key(const unsigned char *userKey, const int bits,
|
||||
ARIA_KEY *key)
|
||||
{
|
||||
const ARIA_u128 *ck1, *ck2, *ck3;
|
||||
ARIA_u128 kr, w0, w1, w2, w3;
|
||||
|
||||
if (!userKey || !key)
|
||||
return -1;
|
||||
memcpy(w0.c, userKey, sizeof(w0));
|
||||
switch (bits) {
|
||||
default:
|
||||
return -2;
|
||||
case 128:
|
||||
key->rounds = 12;
|
||||
ck1 = &c1;
|
||||
ck2 = &c2;
|
||||
ck3 = &c3;
|
||||
memset(kr.c, 0, sizeof(kr));
|
||||
break;
|
||||
|
||||
case 192:
|
||||
key->rounds = 14;
|
||||
ck1 = &c2;
|
||||
ck2 = &c3;
|
||||
ck3 = &c1;
|
||||
memcpy(kr.c, userKey + ARIA_BLOCK_SIZE, sizeof(kr) / 2);
|
||||
memset(kr.c + ARIA_BLOCK_SIZE / 2, 0, sizeof(kr) / 2);
|
||||
break;
|
||||
|
||||
case 256:
|
||||
key->rounds = 16;
|
||||
ck1 = &c3;
|
||||
ck2 = &c1;
|
||||
ck3 = &c2;
|
||||
memcpy(kr.c, userKey + ARIA_BLOCK_SIZE, sizeof(kr));
|
||||
break;
|
||||
}
|
||||
|
||||
FO(&w3, &w0, ck1); xor128(w1.c, w3.c, &kr);
|
||||
FE(&w3, &w1, ck2); xor128(w2.c, w3.c, &w0);
|
||||
FO(&kr, &w2, ck3); xor128(w3.c, kr.c, &w1);
|
||||
|
||||
rot19r(&key->rd_key[ 0], &w0, &w1);
|
||||
rot19r(&key->rd_key[ 1], &w1, &w2);
|
||||
rot19r(&key->rd_key[ 2], &w2, &w3);
|
||||
rot19r(&key->rd_key[ 3], &w3, &w0);
|
||||
|
||||
rot31r(&key->rd_key[ 4], &w0, &w1);
|
||||
rot31r(&key->rd_key[ 5], &w1, &w2);
|
||||
rot31r(&key->rd_key[ 6], &w2, &w3);
|
||||
rot31r(&key->rd_key[ 7], &w3, &w0);
|
||||
|
||||
rot61l(&key->rd_key[ 8], &w0, &w1);
|
||||
rot61l(&key->rd_key[ 9], &w1, &w2);
|
||||
rot61l(&key->rd_key[10], &w2, &w3);
|
||||
rot61l(&key->rd_key[11], &w3, &w0);
|
||||
|
||||
rot31l(&key->rd_key[12], &w0, &w1);
|
||||
if (key->rounds > 12) {
|
||||
rot31l(&key->rd_key[13], &w1, &w2);
|
||||
rot31l(&key->rd_key[14], &w2, &w3);
|
||||
|
||||
if (key->rounds > 14) {
|
||||
rot31l(&key->rd_key[15], &w3, &w0);
|
||||
rot19l(&key->rd_key[16], &w0, &w1);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Expand the cipher key into the decryption key schedule.
|
||||
*/
|
||||
int aria_set_decrypt_key(const unsigned char *userKey, const int bits,
|
||||
ARIA_KEY *key)
|
||||
{
|
||||
ARIA_KEY ek;
|
||||
const int r = aria_set_encrypt_key(userKey, bits, &ek);
|
||||
unsigned int i, rounds = ek.rounds;
|
||||
|
||||
if (r == 0) {
|
||||
key->rounds = rounds;
|
||||
memcpy(&key->rd_key[0], &ek.rd_key[rounds], sizeof(key->rd_key[0]));
|
||||
for (i = 1; i < rounds; i++)
|
||||
a(&key->rd_key[i], &ek.rd_key[rounds - i]);
|
||||
memcpy(&key->rd_key[rounds], &ek.rd_key[0], sizeof(key->rd_key[rounds]));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,4 @@
|
||||
LIBS=../../libcrypto
|
||||
SOURCE[../../libcrypto]=\
|
||||
aria.c
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#! /usr/bin/env perl
|
||||
# Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
# Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the OpenSSL license (the "License"). You may not use
|
||||
# this file except in compliance with the License. You can obtain a copy
|
||||
@@ -63,6 +63,7 @@ _armv8_sha256_probe:
|
||||
sha256su0 v0.4s, v0.4s
|
||||
ret
|
||||
.size _armv8_sha256_probe,.-_armv8_sha256_probe
|
||||
|
||||
.globl _armv8_pmull_probe
|
||||
.type _armv8_pmull_probe,%function
|
||||
_armv8_pmull_probe:
|
||||
@@ -70,6 +71,13 @@ _armv8_pmull_probe:
|
||||
ret
|
||||
.size _armv8_pmull_probe,.-_armv8_pmull_probe
|
||||
|
||||
.globl _armv8_sha512_probe
|
||||
.type _armv8_sha512_probe,%function
|
||||
_armv8_sha512_probe:
|
||||
.long 0xcec08000 // sha512su0 v0.2d,v0.2d
|
||||
ret
|
||||
.size _armv8_sha512_probe,.-_armv8_sha512_probe
|
||||
|
||||
.globl OPENSSL_cleanse
|
||||
.type OPENSSL_cleanse,%function
|
||||
.align 5
|
||||
|
||||
+3
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2011-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -28,7 +28,7 @@
|
||||
# endif
|
||||
/*
|
||||
* Why doesn't gcc define __ARM_ARCH__? Instead it defines
|
||||
* bunch of below macros. See all_architectires[] table in
|
||||
* bunch of below macros. See all_architectures[] table in
|
||||
* gcc/config/arm/arm.c. On a side note it defines
|
||||
* __ARMEL__/__ARMEB__ for little-/big-endian.
|
||||
*/
|
||||
@@ -79,5 +79,6 @@ extern unsigned int OPENSSL_armcap_P;
|
||||
# define ARMV8_SHA1 (1<<3)
|
||||
# define ARMV8_SHA256 (1<<4)
|
||||
# define ARMV8_PMULL (1<<5)
|
||||
# define ARMV8_SHA512 (1<<6)
|
||||
|
||||
#endif
|
||||
+21
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2017 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2011-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <setjmp.h>
|
||||
#include <signal.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include "internal/cryptlib.h"
|
||||
|
||||
#include "arm_arch.h"
|
||||
|
||||
@@ -23,7 +24,7 @@ void OPENSSL_cpuid_setup(void)
|
||||
{
|
||||
}
|
||||
|
||||
unsigned long OPENSSL_rdtsc(void)
|
||||
uint32_t OPENSSL_rdtsc(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -45,9 +46,12 @@ void _armv8_aes_probe(void);
|
||||
void _armv8_sha1_probe(void);
|
||||
void _armv8_sha256_probe(void);
|
||||
void _armv8_pmull_probe(void);
|
||||
unsigned long _armv7_tick(void);
|
||||
# ifdef __aarch64__
|
||||
void _armv8_sha512_probe(void);
|
||||
# endif
|
||||
uint32_t _armv7_tick(void);
|
||||
|
||||
unsigned long OPENSSL_rdtsc(void)
|
||||
uint32_t OPENSSL_rdtsc(void)
|
||||
{
|
||||
if (OPENSSL_armcap_P & ARMV7_TICK)
|
||||
return _armv7_tick();
|
||||
@@ -93,11 +97,12 @@ static unsigned long (*getauxval) (unsigned long) = NULL;
|
||||
# define HWCAP_CE_PMULL (1 << 4)
|
||||
# define HWCAP_CE_SHA1 (1 << 5)
|
||||
# define HWCAP_CE_SHA256 (1 << 6)
|
||||
# define HWCAP_CE_SHA512 (1 << 21)
|
||||
# endif
|
||||
|
||||
void OPENSSL_cpuid_setup(void)
|
||||
{
|
||||
char *e;
|
||||
const char *e;
|
||||
struct sigaction ill_oact, ill_act;
|
||||
sigset_t oset;
|
||||
static int trigger = 0;
|
||||
@@ -162,6 +167,11 @@ void OPENSSL_cpuid_setup(void)
|
||||
|
||||
if (hwcap & HWCAP_CE_SHA256)
|
||||
OPENSSL_armcap_P |= ARMV8_SHA256;
|
||||
|
||||
# ifdef __aarch64__
|
||||
if (hwcap & HWCAP_CE_SHA512)
|
||||
OPENSSL_armcap_P |= ARMV8_SHA512;
|
||||
# endif
|
||||
}
|
||||
} else if (sigsetjmp(ill_jmp, 1) == 0) {
|
||||
_armv7_neon_probe();
|
||||
@@ -181,6 +191,12 @@ void OPENSSL_cpuid_setup(void)
|
||||
_armv8_sha256_probe();
|
||||
OPENSSL_armcap_P |= ARMV8_SHA256;
|
||||
}
|
||||
# ifdef __aarch64__
|
||||
if (sigsetjmp(ill_jmp, 1) == 0) {
|
||||
_armv8_sha512_probe();
|
||||
OPENSSL_armcap_P |= ARMV8_SHA512;
|
||||
}
|
||||
# endif
|
||||
}
|
||||
if (sigsetjmp(ill_jmp, 1) == 0) {
|
||||
_armv7_tick();
|
||||
|
||||
+10
-10
@@ -24,7 +24,7 @@ int i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp)
|
||||
unsigned char *p, *d;
|
||||
|
||||
if (a == NULL)
|
||||
return (0);
|
||||
return 0;
|
||||
|
||||
len = a->length;
|
||||
|
||||
@@ -61,7 +61,7 @@ int i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp)
|
||||
|
||||
ret = 1 + len;
|
||||
if (pp == NULL)
|
||||
return (ret);
|
||||
return ret;
|
||||
|
||||
p = *pp;
|
||||
|
||||
@@ -73,7 +73,7 @@ int i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp)
|
||||
p[-1] &= (0xff << bits);
|
||||
}
|
||||
*pp = p;
|
||||
return (ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
|
||||
@@ -96,7 +96,7 @@ ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
|
||||
|
||||
if ((a == NULL) || ((*a) == NULL)) {
|
||||
if ((ret = ASN1_BIT_STRING_new()) == NULL)
|
||||
return (NULL);
|
||||
return NULL;
|
||||
} else
|
||||
ret = (*a);
|
||||
|
||||
@@ -132,16 +132,16 @@ ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
|
||||
if (a != NULL)
|
||||
(*a) = ret;
|
||||
*pp = p;
|
||||
return (ret);
|
||||
return ret;
|
||||
err:
|
||||
ASN1err(ASN1_F_C2I_ASN1_BIT_STRING, i);
|
||||
if ((a == NULL) || (*a != ret))
|
||||
ASN1_BIT_STRING_free(ret);
|
||||
return (NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* These next 2 functions from Goetz Babin-Ebell <babinebell@trustcenter.de>
|
||||
* These next 2 functions from Goetz Babin-Ebell.
|
||||
*/
|
||||
int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value)
|
||||
{
|
||||
@@ -161,7 +161,7 @@ int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value)
|
||||
|
||||
if ((a->length < (w + 1)) || (a->data == NULL)) {
|
||||
if (!value)
|
||||
return (1); /* Don't need to set */
|
||||
return 1; /* Don't need to set */
|
||||
c = OPENSSL_clear_realloc(a->data, a->length, w + 1);
|
||||
if (c == NULL) {
|
||||
ASN1err(ASN1_F_ASN1_BIT_STRING_SET_BIT, ERR_R_MALLOC_FAILURE);
|
||||
@@ -175,7 +175,7 @@ int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value)
|
||||
a->data[w] = ((a->data[w]) & iv) | v;
|
||||
while ((a->length > 0) && (a->data[a->length - 1] == 0))
|
||||
a->length--;
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ASN1_BIT_STRING_get_bit(const ASN1_BIT_STRING *a, int n)
|
||||
@@ -185,7 +185,7 @@ int ASN1_BIT_STRING_get_bit(const ASN1_BIT_STRING *a, int n)
|
||||
w = n / 8;
|
||||
v = 1 << (7 - (n & 0x07));
|
||||
if ((a == NULL) || (a->length < (w + 1)) || (a->data == NULL))
|
||||
return (0);
|
||||
return 0;
|
||||
return ((a->data[w] & v) != 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,8 +13,7 @@
|
||||
#include "internal/numbers.h"
|
||||
#include <openssl/buffer.h>
|
||||
#include <openssl/asn1.h>
|
||||
|
||||
static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb);
|
||||
#include "internal/asn1_int.h"
|
||||
|
||||
#ifndef NO_OLD_ASN1
|
||||
# ifndef OPENSSL_NO_STDIO
|
||||
@@ -26,12 +25,12 @@ void *ASN1_d2i_fp(void *(*xnew) (void), d2i_of_void *d2i, FILE *in, void **x)
|
||||
|
||||
if ((b = BIO_new(BIO_s_file())) == NULL) {
|
||||
ASN1err(ASN1_F_ASN1_D2I_FP, ERR_R_BUF_LIB);
|
||||
return (NULL);
|
||||
return NULL;
|
||||
}
|
||||
BIO_set_fp(b, in, BIO_NOCLOSE);
|
||||
ret = ASN1_d2i_bio(xnew, d2i, b, x);
|
||||
BIO_free(b);
|
||||
return (ret);
|
||||
return ret;
|
||||
}
|
||||
# endif
|
||||
|
||||
@@ -50,7 +49,7 @@ void *ASN1_d2i_bio(void *(*xnew) (void), d2i_of_void *d2i, BIO *in, void **x)
|
||||
ret = d2i(x, &p, len);
|
||||
err:
|
||||
BUF_MEM_free(b);
|
||||
return (ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -70,7 +69,7 @@ void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x)
|
||||
ret = ASN1_item_d2i(x, &p, len, it);
|
||||
err:
|
||||
BUF_MEM_free(b);
|
||||
return (ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_STDIO
|
||||
@@ -81,18 +80,18 @@ void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x)
|
||||
|
||||
if ((b = BIO_new(BIO_s_file())) == NULL) {
|
||||
ASN1err(ASN1_F_ASN1_ITEM_D2I_FP, ERR_R_BUF_LIB);
|
||||
return (NULL);
|
||||
return NULL;
|
||||
}
|
||||
BIO_set_fp(b, in, BIO_NOCLOSE);
|
||||
ret = ASN1_item_d2i_bio(it, b, x);
|
||||
BIO_free(b);
|
||||
return (ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#define HEADER_SIZE 8
|
||||
#define ASN1_CHUNK_INITIAL_SIZE (16 * 1024)
|
||||
static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
|
||||
int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
|
||||
{
|
||||
BUF_MEM *b;
|
||||
unsigned char *p;
|
||||
|
||||
@@ -29,7 +29,7 @@ int ASN1_digest(i2d_of_void *i2d, const EVP_MD *type, char *data,
|
||||
i = i2d(data, NULL);
|
||||
if ((str = OPENSSL_malloc(i)) == NULL) {
|
||||
ASN1err(ASN1_F_ASN1_DIGEST, ERR_R_MALLOC_FAILURE);
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
p = str;
|
||||
i2d(data, &p);
|
||||
@@ -39,7 +39,7 @@ int ASN1_digest(i2d_of_void *i2d, const EVP_MD *type, char *data,
|
||||
return 0;
|
||||
}
|
||||
OPENSSL_free(str);
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -52,12 +52,12 @@ int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *asn,
|
||||
|
||||
i = ASN1_item_i2d(asn, &str, it);
|
||||
if (!str)
|
||||
return (0);
|
||||
return 0;
|
||||
|
||||
if (!EVP_Digest(str, i, md, len, type, NULL)) {
|
||||
OPENSSL_free(str);
|
||||
return 0;
|
||||
}
|
||||
OPENSSL_free(str);
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
+6
-6
@@ -21,20 +21,20 @@ void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x)
|
||||
char *ret;
|
||||
|
||||
if (x == NULL)
|
||||
return (NULL);
|
||||
return NULL;
|
||||
|
||||
i = i2d(x, NULL);
|
||||
b = OPENSSL_malloc(i + 10);
|
||||
if (b == NULL) {
|
||||
ASN1err(ASN1_F_ASN1_DUP, ERR_R_MALLOC_FAILURE);
|
||||
return (NULL);
|
||||
return NULL;
|
||||
}
|
||||
p = b;
|
||||
i = i2d(x, &p);
|
||||
p2 = b;
|
||||
ret = d2i(NULL, &p2, i);
|
||||
OPENSSL_free(b);
|
||||
return (ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -54,15 +54,15 @@ void *ASN1_item_dup(const ASN1_ITEM *it, void *x)
|
||||
void *ret;
|
||||
|
||||
if (x == NULL)
|
||||
return (NULL);
|
||||
return NULL;
|
||||
|
||||
i = ASN1_item_i2d(x, &b, it);
|
||||
if (b == NULL) {
|
||||
ASN1err(ASN1_F_ASN1_ITEM_DUP, ERR_R_MALLOC_FAILURE);
|
||||
return (NULL);
|
||||
return NULL;
|
||||
}
|
||||
p = b;
|
||||
ret = ASN1_item_d2i(NULL, &p, i, it);
|
||||
OPENSSL_free(b);
|
||||
return (ret);
|
||||
return ret;
|
||||
}
|
||||
+20
-211
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -17,121 +17,13 @@
|
||||
#include <openssl/asn1.h>
|
||||
#include "asn1_locl.h"
|
||||
|
||||
/* This is the primary function used to parse ASN1_GENERALIZEDTIME */
|
||||
int asn1_generalizedtime_to_tm(struct tm *tm, const ASN1_GENERALIZEDTIME *d)
|
||||
{
|
||||
static const int min[9] = { 0, 0, 1, 1, 0, 0, 0, 0, 0 };
|
||||
static const int max[9] = { 99, 99, 12, 31, 23, 59, 59, 12, 59 };
|
||||
char *a;
|
||||
int n, i, l, o;
|
||||
|
||||
/* wrapper around asn1_time_to_tm */
|
||||
if (d->type != V_ASN1_GENERALIZEDTIME)
|
||||
return (0);
|
||||
l = d->length;
|
||||
a = (char *)d->data;
|
||||
o = 0;
|
||||
/*
|
||||
* GENERALIZEDTIME is similar to UTCTIME except the year is represented
|
||||
* as YYYY. This stuff treats everything as a two digit field so make
|
||||
* first two fields 00 to 99
|
||||
*/
|
||||
if (l < 13)
|
||||
goto err;
|
||||
for (i = 0; i < 7; i++) {
|
||||
if ((i == 6) && ((a[o] == 'Z') || (a[o] == '+') || (a[o] == '-'))) {
|
||||
i++;
|
||||
if (tm)
|
||||
tm->tm_sec = 0;
|
||||
break;
|
||||
}
|
||||
if ((a[o] < '0') || (a[o] > '9'))
|
||||
goto err;
|
||||
n = a[o] - '0';
|
||||
if (++o > l)
|
||||
goto err;
|
||||
|
||||
if ((a[o] < '0') || (a[o] > '9'))
|
||||
goto err;
|
||||
n = (n * 10) + a[o] - '0';
|
||||
if (++o > l)
|
||||
goto err;
|
||||
|
||||
if ((n < min[i]) || (n > max[i]))
|
||||
goto err;
|
||||
if (tm) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
tm->tm_year = n * 100 - 1900;
|
||||
break;
|
||||
case 1:
|
||||
tm->tm_year += n;
|
||||
break;
|
||||
case 2:
|
||||
tm->tm_mon = n - 1;
|
||||
break;
|
||||
case 3:
|
||||
tm->tm_mday = n;
|
||||
break;
|
||||
case 4:
|
||||
tm->tm_hour = n;
|
||||
break;
|
||||
case 5:
|
||||
tm->tm_min = n;
|
||||
break;
|
||||
case 6:
|
||||
tm->tm_sec = n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Optional fractional seconds: decimal point followed by one or more
|
||||
* digits.
|
||||
*/
|
||||
if (a[o] == '.') {
|
||||
if (++o > l)
|
||||
goto err;
|
||||
i = o;
|
||||
while ((a[o] >= '0') && (a[o] <= '9') && (o <= l))
|
||||
o++;
|
||||
/* Must have at least one digit after decimal point */
|
||||
if (i == o)
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (a[o] == 'Z')
|
||||
o++;
|
||||
else if ((a[o] == '+') || (a[o] == '-')) {
|
||||
int offsign = a[o] == '-' ? 1 : -1, offset = 0;
|
||||
o++;
|
||||
if (o + 4 > l)
|
||||
goto err;
|
||||
for (i = 7; i < 9; i++) {
|
||||
if ((a[o] < '0') || (a[o] > '9'))
|
||||
goto err;
|
||||
n = a[o] - '0';
|
||||
o++;
|
||||
if ((a[o] < '0') || (a[o] > '9'))
|
||||
goto err;
|
||||
n = (n * 10) + a[o] - '0';
|
||||
if ((n < min[i]) || (n > max[i]))
|
||||
goto err;
|
||||
if (tm) {
|
||||
if (i == 7)
|
||||
offset = n * 3600;
|
||||
else if (i == 8)
|
||||
offset += n * 60;
|
||||
}
|
||||
o++;
|
||||
}
|
||||
if (offset && !OPENSSL_gmtime_adj(tm, 0, offset * offsign))
|
||||
return 0;
|
||||
} else if (a[o]) {
|
||||
/* Missing time zone information. */
|
||||
goto err;
|
||||
}
|
||||
return (o == l);
|
||||
err:
|
||||
return (0);
|
||||
return 0;
|
||||
return asn1_time_to_tm(tm, d);
|
||||
}
|
||||
|
||||
int ASN1_GENERALIZEDTIME_check(const ASN1_GENERALIZEDTIME *d)
|
||||
@@ -146,15 +38,15 @@ int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str)
|
||||
t.type = V_ASN1_GENERALIZEDTIME;
|
||||
t.length = strlen(str);
|
||||
t.data = (unsigned char *)str;
|
||||
if (ASN1_GENERALIZEDTIME_check(&t)) {
|
||||
if (s != NULL) {
|
||||
if (!ASN1_STRING_set((ASN1_STRING *)s, str, t.length))
|
||||
return 0;
|
||||
s->type = V_ASN1_GENERALIZEDTIME;
|
||||
}
|
||||
return (1);
|
||||
} else
|
||||
return (0);
|
||||
t.flags = 0;
|
||||
|
||||
if (!ASN1_GENERALIZEDTIME_check(&t))
|
||||
return 0;
|
||||
|
||||
if (s != NULL && !ASN1_STRING_copy(s, &t))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,
|
||||
@@ -167,107 +59,24 @@ ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s,
|
||||
time_t t, int offset_day,
|
||||
long offset_sec)
|
||||
{
|
||||
char *p;
|
||||
struct tm *ts;
|
||||
struct tm data;
|
||||
size_t len = 20;
|
||||
ASN1_GENERALIZEDTIME *tmps = NULL;
|
||||
|
||||
if (s == NULL)
|
||||
tmps = ASN1_GENERALIZEDTIME_new();
|
||||
else
|
||||
tmps = s;
|
||||
if (tmps == NULL)
|
||||
return NULL;
|
||||
|
||||
ts = OPENSSL_gmtime(&t, &data);
|
||||
if (ts == NULL)
|
||||
goto err;
|
||||
return NULL;
|
||||
|
||||
if (offset_day || offset_sec) {
|
||||
if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec))
|
||||
goto err;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
p = (char *)tmps->data;
|
||||
if ((p == NULL) || ((size_t)tmps->length < len)) {
|
||||
p = OPENSSL_malloc(len);
|
||||
if (p == NULL) {
|
||||
ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_ADJ, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
OPENSSL_free(tmps->data);
|
||||
tmps->data = (unsigned char *)p;
|
||||
}
|
||||
|
||||
BIO_snprintf(p, len, "%04d%02d%02d%02d%02d%02dZ", ts->tm_year + 1900,
|
||||
ts->tm_mon + 1, ts->tm_mday, ts->tm_hour, ts->tm_min,
|
||||
ts->tm_sec);
|
||||
tmps->length = strlen(p);
|
||||
tmps->type = V_ASN1_GENERALIZEDTIME;
|
||||
#ifdef CHARSET_EBCDIC_not
|
||||
ebcdic2ascii(tmps->data, tmps->data, tmps->length);
|
||||
#endif
|
||||
return tmps;
|
||||
err:
|
||||
if (s == NULL)
|
||||
ASN1_GENERALIZEDTIME_free(tmps);
|
||||
return NULL;
|
||||
return asn1_time_from_tm(s, ts, V_ASN1_GENERALIZEDTIME);
|
||||
}
|
||||
|
||||
const char *_asn1_mon[12] = {
|
||||
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
||||
};
|
||||
|
||||
int ASN1_GENERALIZEDTIME_print(BIO *bp, const ASN1_GENERALIZEDTIME *tm)
|
||||
{
|
||||
char *v;
|
||||
int gmt = 0;
|
||||
int i;
|
||||
int y = 0, M = 0, d = 0, h = 0, m = 0, s = 0;
|
||||
char *f = NULL;
|
||||
int f_len = 0;
|
||||
|
||||
i = tm->length;
|
||||
v = (char *)tm->data;
|
||||
|
||||
if (i < 12)
|
||||
goto err;
|
||||
if (v[i - 1] == 'Z')
|
||||
gmt = 1;
|
||||
for (i = 0; i < 12; i++)
|
||||
if ((v[i] > '9') || (v[i] < '0'))
|
||||
goto err;
|
||||
y = (v[0] - '0') * 1000 + (v[1] - '0') * 100
|
||||
+ (v[2] - '0') * 10 + (v[3] - '0');
|
||||
M = (v[4] - '0') * 10 + (v[5] - '0');
|
||||
if ((M > 12) || (M < 1))
|
||||
goto err;
|
||||
d = (v[6] - '0') * 10 + (v[7] - '0');
|
||||
h = (v[8] - '0') * 10 + (v[9] - '0');
|
||||
m = (v[10] - '0') * 10 + (v[11] - '0');
|
||||
if (tm->length >= 14 &&
|
||||
(v[12] >= '0') && (v[12] <= '9') &&
|
||||
(v[13] >= '0') && (v[13] <= '9')) {
|
||||
s = (v[12] - '0') * 10 + (v[13] - '0');
|
||||
/* Check for fractions of seconds. */
|
||||
if (tm->length >= 15 && v[14] == '.') {
|
||||
int l = tm->length;
|
||||
f = &v[14]; /* The decimal point. */
|
||||
f_len = 1;
|
||||
while (14 + f_len < l && f[f_len] >= '0' && f[f_len] <= '9')
|
||||
++f_len;
|
||||
}
|
||||
}
|
||||
|
||||
if (BIO_printf(bp, "%s %2d %02d:%02d:%02d%.*s %d%s",
|
||||
_asn1_mon[M - 1], d, h, m, s, f_len, f, y,
|
||||
(gmt) ? " GMT" : "") <= 0)
|
||||
return (0);
|
||||
else
|
||||
return (1);
|
||||
err:
|
||||
BIO_write(bp, "Bad time value", 14);
|
||||
return (0);
|
||||
if (tm->type != V_ASN1_GENERALIZEDTIME)
|
||||
return 0;
|
||||
return ASN1_TIME_print(bp, tm);
|
||||
}
|
||||
@@ -22,12 +22,12 @@ int ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, void *x)
|
||||
|
||||
if ((b = BIO_new(BIO_s_file())) == NULL) {
|
||||
ASN1err(ASN1_F_ASN1_I2D_FP, ERR_R_BUF_LIB);
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
BIO_set_fp(b, out, BIO_NOCLOSE);
|
||||
ret = ASN1_i2d_bio(i2d, b, x);
|
||||
BIO_free(b);
|
||||
return (ret);
|
||||
return ret;
|
||||
}
|
||||
# endif
|
||||
|
||||
@@ -44,7 +44,7 @@ int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x)
|
||||
b = OPENSSL_malloc(n);
|
||||
if (b == NULL) {
|
||||
ASN1err(ASN1_F_ASN1_I2D_BIO, ERR_R_MALLOC_FAILURE);
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
p = (unsigned char *)b;
|
||||
@@ -62,7 +62,7 @@ int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x)
|
||||
n -= i;
|
||||
}
|
||||
OPENSSL_free(b);
|
||||
return (ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -75,12 +75,12 @@ int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x)
|
||||
|
||||
if ((b = BIO_new(BIO_s_file())) == NULL) {
|
||||
ASN1err(ASN1_F_ASN1_ITEM_I2D_FP, ERR_R_BUF_LIB);
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
BIO_set_fp(b, out, BIO_NOCLOSE);
|
||||
ret = ASN1_item_i2d_bio(it, b, x);
|
||||
BIO_free(b);
|
||||
return (ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -92,7 +92,7 @@ int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x)
|
||||
n = ASN1_item_i2d(x, &b, it);
|
||||
if (b == NULL) {
|
||||
ASN1err(ASN1_F_ASN1_ITEM_I2D_BIO, ERR_R_MALLOC_FAILURE);
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
@@ -107,5 +107,5 @@ int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x)
|
||||
n -= i;
|
||||
}
|
||||
OPENSSL_free(b);
|
||||
return (ret);
|
||||
return ret;
|
||||
}
|
||||
+4
-4
@@ -396,7 +396,7 @@ ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp,
|
||||
|
||||
if ((a == NULL) || ((*a) == NULL)) {
|
||||
if ((ret = ASN1_INTEGER_new()) == NULL)
|
||||
return (NULL);
|
||||
return NULL;
|
||||
ret->type = V_ASN1_INTEGER;
|
||||
} else
|
||||
ret = (*a);
|
||||
@@ -438,12 +438,12 @@ ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp,
|
||||
if (a != NULL)
|
||||
(*a) = ret;
|
||||
*pp = p;
|
||||
return (ret);
|
||||
return ret;
|
||||
err:
|
||||
ASN1err(ASN1_F_D2I_ASN1_UINTEGER, i);
|
||||
if ((a == NULL) || (*a != ret))
|
||||
ASN1_INTEGER_free(ret);
|
||||
return (NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static ASN1_STRING *bn_to_asn1_string(const BIGNUM *bn, ASN1_STRING *ai,
|
||||
@@ -487,7 +487,7 @@ static ASN1_STRING *bn_to_asn1_string(const BIGNUM *bn, ASN1_STRING *ai,
|
||||
err:
|
||||
if (ret != ai)
|
||||
ASN1_INTEGER_free(ret);
|
||||
return (NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static BIGNUM *asn1_string_to_bn(const ASN1_INTEGER *ai, BIGNUM *bn,
|
||||
|
||||
+9
-61
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1999-2017 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include "internal/ctype.h"
|
||||
#include "internal/cryptlib.h"
|
||||
#include <openssl/asn1.h>
|
||||
|
||||
@@ -22,8 +22,6 @@ static int cpy_asc(unsigned long value, void *arg);
|
||||
static int cpy_bmp(unsigned long value, void *arg);
|
||||
static int cpy_univ(unsigned long value, void *arg);
|
||||
static int cpy_utf8(unsigned long value, void *arg);
|
||||
static int is_numeric(unsigned long value);
|
||||
static int is_printable(unsigned long value);
|
||||
|
||||
/*
|
||||
* These functions take a string in UTF8, ASCII or multibyte form and a mask
|
||||
@@ -271,13 +269,15 @@ static int out_utf8(unsigned long value, void *arg)
|
||||
|
||||
static int type_str(unsigned long value, void *arg)
|
||||
{
|
||||
unsigned long types;
|
||||
types = *((unsigned long *)arg);
|
||||
if ((types & B_ASN1_NUMERICSTRING) && !is_numeric(value))
|
||||
unsigned long types = *((unsigned long *)arg);
|
||||
const int native = value > INT_MAX ? INT_MAX : ossl_fromascii(value);
|
||||
|
||||
if ((types & B_ASN1_NUMERICSTRING) && !(ossl_isdigit(native)
|
||||
|| native == ' '))
|
||||
types &= ~B_ASN1_NUMERICSTRING;
|
||||
if ((types & B_ASN1_PRINTABLESTRING) && !is_printable(value))
|
||||
if ((types & B_ASN1_PRINTABLESTRING) && !ossl_isasn1print(native))
|
||||
types &= ~B_ASN1_PRINTABLESTRING;
|
||||
if ((types & B_ASN1_IA5STRING) && (value > 127))
|
||||
if ((types & B_ASN1_IA5STRING) && !ossl_isascii(native))
|
||||
types &= ~B_ASN1_IA5STRING;
|
||||
if ((types & B_ASN1_T61STRING) && (value > 0xff))
|
||||
types &= ~B_ASN1_T61STRING;
|
||||
@@ -341,55 +341,3 @@ static int cpy_utf8(unsigned long value, void *arg)
|
||||
*p += ret;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Return 1 if the character is permitted in a PrintableString */
|
||||
static int is_printable(unsigned long value)
|
||||
{
|
||||
int ch;
|
||||
if (value > 0x7f)
|
||||
return 0;
|
||||
ch = (int)value;
|
||||
/*
|
||||
* Note: we can't use 'isalnum' because certain accented characters may
|
||||
* count as alphanumeric in some environments.
|
||||
*/
|
||||
#ifndef CHARSET_EBCDIC
|
||||
if ((ch >= 'a') && (ch <= 'z'))
|
||||
return 1;
|
||||
if ((ch >= 'A') && (ch <= 'Z'))
|
||||
return 1;
|
||||
if ((ch >= '0') && (ch <= '9'))
|
||||
return 1;
|
||||
if ((ch == ' ') || strchr("'()+,-./:=?", ch))
|
||||
return 1;
|
||||
#else /* CHARSET_EBCDIC */
|
||||
if ((ch >= os_toascii['a']) && (ch <= os_toascii['z']))
|
||||
return 1;
|
||||
if ((ch >= os_toascii['A']) && (ch <= os_toascii['Z']))
|
||||
return 1;
|
||||
if ((ch >= os_toascii['0']) && (ch <= os_toascii['9']))
|
||||
return 1;
|
||||
if ((ch == os_toascii[' ']) || strchr("'()+,-./:=?", os_toebcdic[ch]))
|
||||
return 1;
|
||||
#endif /* CHARSET_EBCDIC */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Return 1 if the character is a digit or space */
|
||||
static int is_numeric(unsigned long value)
|
||||
{
|
||||
int ch;
|
||||
if (value > 0x7f)
|
||||
return 0;
|
||||
ch = (int)value;
|
||||
#ifndef CHARSET_EBCDIC
|
||||
if (!isdigit(ch) && ch != ' ')
|
||||
return 0;
|
||||
#else
|
||||
if (ch > os_toascii['9'])
|
||||
return 0;
|
||||
if (ch < os_toascii['0'] && ch != os_toascii[' '])
|
||||
return 0;
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
+17
-16
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include "internal/ctype.h"
|
||||
#include "internal/cryptlib.h"
|
||||
#include <openssl/buffer.h>
|
||||
#include <openssl/asn1.h>
|
||||
@@ -23,7 +24,7 @@ int i2d_ASN1_OBJECT(const ASN1_OBJECT *a, unsigned char **pp)
|
||||
int objsize;
|
||||
|
||||
if ((a == NULL) || (a->data == NULL))
|
||||
return (0);
|
||||
return 0;
|
||||
|
||||
objsize = ASN1_object_size(0, a->length, V_ASN1_OBJECT);
|
||||
if (pp == NULL || objsize == -1)
|
||||
@@ -35,7 +36,7 @@ int i2d_ASN1_OBJECT(const ASN1_OBJECT *a, unsigned char **pp)
|
||||
p += a->length;
|
||||
|
||||
*pp = p;
|
||||
return (objsize);
|
||||
return objsize;
|
||||
}
|
||||
|
||||
int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
|
||||
@@ -48,7 +49,7 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
|
||||
BIGNUM *bl = NULL;
|
||||
|
||||
if (num == 0)
|
||||
return (0);
|
||||
return 0;
|
||||
else if (num == -1)
|
||||
num = strlen(buf);
|
||||
|
||||
@@ -84,7 +85,7 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
|
||||
c = *(p++);
|
||||
if ((c == ' ') || (c == '.'))
|
||||
break;
|
||||
if ((c < '0') || (c > '9')) {
|
||||
if (!ossl_isdigit(c)) {
|
||||
ASN1err(ASN1_F_A2D_ASN1_OBJECT, ASN1_R_INVALID_DIGIT);
|
||||
goto err;
|
||||
}
|
||||
@@ -157,12 +158,12 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
|
||||
if (tmp != ftmp)
|
||||
OPENSSL_free(tmp);
|
||||
BN_free(bl);
|
||||
return (len);
|
||||
return len;
|
||||
err:
|
||||
if (tmp != ftmp)
|
||||
OPENSSL_free(tmp);
|
||||
BN_free(bl);
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int i2t_ASN1_OBJECT(char *buf, int buf_len, const ASN1_OBJECT *a)
|
||||
@@ -176,7 +177,7 @@ int i2a_ASN1_OBJECT(BIO *bp, const ASN1_OBJECT *a)
|
||||
int i;
|
||||
|
||||
if ((a == NULL) || (a->data == NULL))
|
||||
return (BIO_write(bp, "NULL", 4));
|
||||
return BIO_write(bp, "NULL", 4);
|
||||
i = i2t_ASN1_OBJECT(buf, sizeof(buf), a);
|
||||
if (i > (int)(sizeof(buf) - 1)) {
|
||||
p = OPENSSL_malloc(i + 1);
|
||||
@@ -192,7 +193,7 @@ int i2a_ASN1_OBJECT(BIO *bp, const ASN1_OBJECT *a)
|
||||
BIO_write(bp, p, i);
|
||||
if (p != buf)
|
||||
OPENSSL_free(p);
|
||||
return (i);
|
||||
return i;
|
||||
}
|
||||
|
||||
ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
|
||||
@@ -220,7 +221,7 @@ ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
|
||||
return ret;
|
||||
err:
|
||||
ASN1err(ASN1_F_D2I_ASN1_OBJECT, i);
|
||||
return (NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
|
||||
@@ -280,7 +281,7 @@ ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
|
||||
if ((a == NULL) || ((*a) == NULL) ||
|
||||
!((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC)) {
|
||||
if ((ret = ASN1_OBJECT_new()) == NULL)
|
||||
return (NULL);
|
||||
return NULL;
|
||||
} else
|
||||
ret = (*a);
|
||||
|
||||
@@ -311,12 +312,12 @@ ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
|
||||
if (a != NULL)
|
||||
(*a) = ret;
|
||||
*pp = p;
|
||||
return (ret);
|
||||
return ret;
|
||||
err:
|
||||
ASN1err(ASN1_F_C2I_ASN1_OBJECT, i);
|
||||
if ((a == NULL) || (*a != ret))
|
||||
ASN1_OBJECT_free(ret);
|
||||
return (NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ASN1_OBJECT *ASN1_OBJECT_new(void)
|
||||
@@ -326,10 +327,10 @@ ASN1_OBJECT *ASN1_OBJECT_new(void)
|
||||
ret = OPENSSL_zalloc(sizeof(*ret));
|
||||
if (ret == NULL) {
|
||||
ASN1err(ASN1_F_ASN1_OBJECT_NEW, ERR_R_MALLOC_FAILURE);
|
||||
return (NULL);
|
||||
return NULL;
|
||||
}
|
||||
ret->flags = ASN1_OBJECT_FLAG_DYNAMIC;
|
||||
return (ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ASN1_OBJECT_free(ASN1_OBJECT *a)
|
||||
@@ -366,5 +367,5 @@ ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len,
|
||||
o.length = len;
|
||||
o.flags = ASN1_OBJECT_FLAG_DYNAMIC | ASN1_OBJECT_FLAG_DYNAMIC_STRINGS |
|
||||
ASN1_OBJECT_FLAG_DYNAMIC_DATA;
|
||||
return (OBJ_dup(&o));
|
||||
return OBJ_dup(&o);
|
||||
}
|
||||
+16
-30
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include "internal/ctype.h"
|
||||
#include "internal/cryptlib.h"
|
||||
#include <openssl/asn1.h>
|
||||
|
||||
@@ -21,34 +21,20 @@ int ASN1_PRINTABLE_type(const unsigned char *s, int len)
|
||||
if (len <= 0)
|
||||
len = -1;
|
||||
if (s == NULL)
|
||||
return (V_ASN1_PRINTABLESTRING);
|
||||
return V_ASN1_PRINTABLESTRING;
|
||||
|
||||
while ((*s) && (len-- != 0)) {
|
||||
c = *(s++);
|
||||
#ifndef CHARSET_EBCDIC
|
||||
if (!(((c >= 'a') && (c <= 'z')) ||
|
||||
((c >= 'A') && (c <= 'Z')) ||
|
||||
((c >= '0') && (c <= '9')) ||
|
||||
(c == ' ') || (c == '\'') ||
|
||||
(c == '(') || (c == ')') ||
|
||||
(c == '+') || (c == ',') ||
|
||||
(c == '-') || (c == '.') ||
|
||||
(c == '/') || (c == ':') || (c == '=') || (c == '?')))
|
||||
if (!ossl_isasn1print(c))
|
||||
ia5 = 1;
|
||||
if (c & 0x80)
|
||||
if (!ossl_isascii(c))
|
||||
t61 = 1;
|
||||
#else
|
||||
if (!isalnum(c) && (c != ' ') && strchr("'()+,-./:=?", c) == NULL)
|
||||
ia5 = 1;
|
||||
if (os_toascii[c] & 0x80)
|
||||
t61 = 1;
|
||||
#endif
|
||||
}
|
||||
if (t61)
|
||||
return (V_ASN1_T61STRING);
|
||||
return V_ASN1_T61STRING;
|
||||
if (ia5)
|
||||
return (V_ASN1_IA5STRING);
|
||||
return (V_ASN1_PRINTABLESTRING);
|
||||
return V_ASN1_IA5STRING;
|
||||
return V_ASN1_PRINTABLESTRING;
|
||||
}
|
||||
|
||||
int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s)
|
||||
@@ -57,9 +43,9 @@ int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s)
|
||||
unsigned char *p;
|
||||
|
||||
if (s->type != V_ASN1_UNIVERSALSTRING)
|
||||
return (0);
|
||||
return 0;
|
||||
if ((s->length % 4) != 0)
|
||||
return (0);
|
||||
return 0;
|
||||
p = s->data;
|
||||
for (i = 0; i < s->length; i += 4) {
|
||||
if ((p[0] != '\0') || (p[1] != '\0') || (p[2] != '\0'))
|
||||
@@ -68,7 +54,7 @@ int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s)
|
||||
p += 4;
|
||||
}
|
||||
if (i < s->length)
|
||||
return (0);
|
||||
return 0;
|
||||
p = s->data;
|
||||
for (i = 3; i < s->length; i += 4) {
|
||||
*(p++) = s->data[i];
|
||||
@@ -76,7 +62,7 @@ int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s)
|
||||
*(p) = '\0';
|
||||
s->length /= 4;
|
||||
s->type = ASN1_PRINTABLE_type(s->data, s->length);
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v)
|
||||
@@ -86,7 +72,7 @@ int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v)
|
||||
const char *p;
|
||||
|
||||
if (v == NULL)
|
||||
return (0);
|
||||
return 0;
|
||||
n = 0;
|
||||
p = (const char *)v->data;
|
||||
for (i = 0; i < v->length; i++) {
|
||||
@@ -98,12 +84,12 @@ int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v)
|
||||
n++;
|
||||
if (n >= 80) {
|
||||
if (BIO_write(bp, buf, n) <= 0)
|
||||
return (0);
|
||||
return 0;
|
||||
n = 0;
|
||||
}
|
||||
}
|
||||
if (n > 0)
|
||||
if (BIO_write(bp, buf, n) <= 0)
|
||||
return (0);
|
||||
return (1);
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
+10
-6
@@ -103,7 +103,7 @@ int ASN1_sign(i2d_of_void *i2d, X509_ALGOR *algor1, X509_ALGOR *algor2,
|
||||
EVP_MD_CTX_free(ctx);
|
||||
OPENSSL_clear_free((char *)buf_in, (unsigned int)inl);
|
||||
OPENSSL_clear_free((char *)buf_out, outll);
|
||||
return (outl);
|
||||
return outl;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -144,7 +144,7 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it,
|
||||
type = EVP_MD_CTX_md(ctx);
|
||||
pkey = EVP_PKEY_CTX_get0_pkey(EVP_MD_CTX_pkey_ctx(ctx));
|
||||
|
||||
if (type == NULL || pkey == NULL) {
|
||||
if (pkey == NULL) {
|
||||
ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ASN1_R_CONTEXT_NOT_INITIALISED);
|
||||
goto err;
|
||||
}
|
||||
@@ -169,10 +169,15 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it,
|
||||
ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ERR_R_EVP_LIB);
|
||||
if (rv <= 1)
|
||||
goto err;
|
||||
} else
|
||||
} else {
|
||||
rv = 2;
|
||||
}
|
||||
|
||||
if (rv == 2) {
|
||||
if (type == NULL) {
|
||||
ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ASN1_R_CONTEXT_NOT_INITIALISED);
|
||||
goto err;
|
||||
}
|
||||
if (!OBJ_find_sigid_by_algs(&signid,
|
||||
EVP_MD_nid(type),
|
||||
pkey->ameth->pkey_id)) {
|
||||
@@ -202,8 +207,7 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it,
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!EVP_DigestSignUpdate(ctx, buf_in, inl)
|
||||
|| !EVP_DigestSignFinal(ctx, buf_out, &outl)) {
|
||||
if (!EVP_DigestSign(ctx, buf_out, &outl, buf_in, inl)) {
|
||||
outl = 0;
|
||||
ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ERR_R_EVP_LIB);
|
||||
goto err;
|
||||
@@ -221,5 +225,5 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it,
|
||||
err:
|
||||
OPENSSL_clear_free((char *)buf_in, (unsigned int)inl);
|
||||
OPENSSL_clear_free((char *)buf_out, outll);
|
||||
return (outl);
|
||||
return outl;
|
||||
}
|
||||
+17
-88
@@ -8,7 +8,6 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/objects.h>
|
||||
@@ -50,6 +49,7 @@ int ASN1_STRING_set_default_mask_asc(const char *p)
|
||||
{
|
||||
unsigned long mask;
|
||||
char *end;
|
||||
|
||||
if (strncmp(p, "MASK:", 5) == 0) {
|
||||
if (!p[5])
|
||||
return 0;
|
||||
@@ -84,19 +84,20 @@ ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out,
|
||||
ASN1_STRING *str = NULL;
|
||||
unsigned long mask;
|
||||
int ret;
|
||||
if (!out)
|
||||
|
||||
if (out == NULL)
|
||||
out = &str;
|
||||
tbl = ASN1_STRING_TABLE_get(nid);
|
||||
if (tbl) {
|
||||
if (tbl != NULL) {
|
||||
mask = tbl->mask;
|
||||
if (!(tbl->flags & STABLE_NO_MASK))
|
||||
mask &= global_mask;
|
||||
ret = ASN1_mbstring_ncopy(out, in, inlen, inform, mask,
|
||||
tbl->minsize, tbl->maxsize);
|
||||
} else
|
||||
ret =
|
||||
ASN1_mbstring_copy(out, in, inlen, inform,
|
||||
DIRSTRING_TYPE & global_mask);
|
||||
} else {
|
||||
ret = ASN1_mbstring_copy(out, in, inlen, inform,
|
||||
DIRSTRING_TYPE & global_mask);
|
||||
}
|
||||
if (ret <= 0)
|
||||
return NULL;
|
||||
return *out;
|
||||
@@ -106,54 +107,7 @@ ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out,
|
||||
* Now the tables and helper functions for the string table:
|
||||
*/
|
||||
|
||||
/* size limits: this stuff is taken straight from RFC3280 */
|
||||
|
||||
#define ub_name 32768
|
||||
#define ub_common_name 64
|
||||
#define ub_locality_name 128
|
||||
#define ub_state_name 128
|
||||
#define ub_organization_name 64
|
||||
#define ub_organization_unit_name 64
|
||||
#define ub_title 64
|
||||
#define ub_email_address 128
|
||||
#define ub_serial_number 64
|
||||
|
||||
/* From RFC4524 */
|
||||
|
||||
#define ub_rfc822_mailbox 256
|
||||
|
||||
/* This table must be kept in NID order */
|
||||
|
||||
static const ASN1_STRING_TABLE tbl_standard[] = {
|
||||
{NID_commonName, 1, ub_common_name, DIRSTRING_TYPE, 0},
|
||||
{NID_countryName, 2, 2, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK},
|
||||
{NID_localityName, 1, ub_locality_name, DIRSTRING_TYPE, 0},
|
||||
{NID_stateOrProvinceName, 1, ub_state_name, DIRSTRING_TYPE, 0},
|
||||
{NID_organizationName, 1, ub_organization_name, DIRSTRING_TYPE, 0},
|
||||
{NID_organizationalUnitName, 1, ub_organization_unit_name, DIRSTRING_TYPE,
|
||||
0},
|
||||
{NID_pkcs9_emailAddress, 1, ub_email_address, B_ASN1_IA5STRING,
|
||||
STABLE_NO_MASK},
|
||||
{NID_pkcs9_unstructuredName, 1, -1, PKCS9STRING_TYPE, 0},
|
||||
{NID_pkcs9_challengePassword, 1, -1, PKCS9STRING_TYPE, 0},
|
||||
{NID_pkcs9_unstructuredAddress, 1, -1, DIRSTRING_TYPE, 0},
|
||||
{NID_givenName, 1, ub_name, DIRSTRING_TYPE, 0},
|
||||
{NID_surname, 1, ub_name, DIRSTRING_TYPE, 0},
|
||||
{NID_initials, 1, ub_name, DIRSTRING_TYPE, 0},
|
||||
{NID_serialNumber, 1, ub_serial_number, B_ASN1_PRINTABLESTRING,
|
||||
STABLE_NO_MASK},
|
||||
{NID_friendlyName, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK},
|
||||
{NID_name, 1, ub_name, DIRSTRING_TYPE, 0},
|
||||
{NID_dnQualifier, -1, -1, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK},
|
||||
{NID_domainComponent, 1, -1, B_ASN1_IA5STRING, STABLE_NO_MASK},
|
||||
{NID_ms_csp_name, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK},
|
||||
{NID_rfc822Mailbox, 1, ub_rfc822_mailbox, B_ASN1_IA5STRING,
|
||||
STABLE_NO_MASK},
|
||||
{NID_jurisdictionCountryName, 2, 2, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK},
|
||||
{NID_INN, 1, 12, B_ASN1_NUMERICSTRING, STABLE_NO_MASK},
|
||||
{NID_OGRN, 1, 13, B_ASN1_NUMERICSTRING, STABLE_NO_MASK},
|
||||
{NID_SNILS, 1, 11, B_ASN1_NUMERICSTRING, STABLE_NO_MASK}
|
||||
};
|
||||
#include "tbl_standard.h"
|
||||
|
||||
static int sk_table_cmp(const ASN1_STRING_TABLE *const *a,
|
||||
const ASN1_STRING_TABLE *const *b)
|
||||
@@ -174,6 +128,7 @@ ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid)
|
||||
{
|
||||
int idx;
|
||||
ASN1_STRING_TABLE fnd;
|
||||
|
||||
fnd.nid = nid;
|
||||
if (stable) {
|
||||
idx = sk_ASN1_STRING_TABLE_find(stable, &fnd);
|
||||
@@ -191,6 +146,7 @@ ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid)
|
||||
static ASN1_STRING_TABLE *stable_get(int nid)
|
||||
{
|
||||
ASN1_STRING_TABLE *tmp, *rv;
|
||||
|
||||
/* Always need a string table so allocate one if NULL */
|
||||
if (stable == NULL) {
|
||||
stable = sk_ASN1_STRING_TABLE_new(sk_table_cmp);
|
||||
@@ -198,7 +154,7 @@ static ASN1_STRING_TABLE *stable_get(int nid)
|
||||
return NULL;
|
||||
}
|
||||
tmp = ASN1_STRING_TABLE_get(nid);
|
||||
if (tmp && tmp->flags & STABLE_FLAGS_MALLOC)
|
||||
if (tmp != NULL && tmp->flags & STABLE_FLAGS_MALLOC)
|
||||
return tmp;
|
||||
rv = OPENSSL_zalloc(sizeof(*rv));
|
||||
if (rv == NULL)
|
||||
@@ -207,7 +163,7 @@ static ASN1_STRING_TABLE *stable_get(int nid)
|
||||
OPENSSL_free(rv);
|
||||
return NULL;
|
||||
}
|
||||
if (tmp) {
|
||||
if (tmp != NULL) {
|
||||
rv->nid = tmp->nid;
|
||||
rv->minsize = tmp->minsize;
|
||||
rv->maxsize = tmp->maxsize;
|
||||
@@ -227,8 +183,9 @@ int ASN1_STRING_TABLE_add(int nid,
|
||||
unsigned long flags)
|
||||
{
|
||||
ASN1_STRING_TABLE *tmp;
|
||||
|
||||
tmp = stable_get(nid);
|
||||
if (!tmp) {
|
||||
if (tmp == NULL) {
|
||||
ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD, ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
@@ -246,8 +203,9 @@ int ASN1_STRING_TABLE_add(int nid,
|
||||
void ASN1_STRING_TABLE_cleanup(void)
|
||||
{
|
||||
STACK_OF(ASN1_STRING_TABLE) *tmp;
|
||||
|
||||
tmp = stable;
|
||||
if (!tmp)
|
||||
if (tmp == NULL)
|
||||
return;
|
||||
stable = NULL;
|
||||
sk_ASN1_STRING_TABLE_pop_free(tmp, st_free);
|
||||
@@ -258,32 +216,3 @@ static void st_free(ASN1_STRING_TABLE *tbl)
|
||||
if (tbl->flags & STABLE_FLAGS_MALLOC)
|
||||
OPENSSL_free(tbl);
|
||||
}
|
||||
|
||||
|
||||
#ifdef STRING_TABLE_TEST
|
||||
|
||||
main()
|
||||
{
|
||||
ASN1_STRING_TABLE *tmp;
|
||||
int i, last_nid = -1;
|
||||
|
||||
for (tmp = tbl_standard, i = 0; i < OSSL_NELEM(tbl_standard); i++, tmp++) {
|
||||
if (tmp->nid < last_nid) {
|
||||
last_nid = 0;
|
||||
break;
|
||||
}
|
||||
last_nid = tmp->nid;
|
||||
}
|
||||
|
||||
if (last_nid != 0) {
|
||||
printf("Table order OK\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
for (tmp = tbl_standard, i = 0; i < OSSL_NELEM(tbl_standard); i++, tmp++)
|
||||
printf("Index %d, NID %d, Name=%s\n", i, tmp->nid,
|
||||
OBJ_nid2ln(tmp->nid));
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
+444
-61
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1999-2017 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include "internal/ctype.h"
|
||||
#include "internal/cryptlib.h"
|
||||
#include <openssl/asn1t.h>
|
||||
#include "asn1_locl.h"
|
||||
@@ -24,6 +25,291 @@ IMPLEMENT_ASN1_MSTRING(ASN1_TIME, B_ASN1_TIME)
|
||||
|
||||
IMPLEMENT_ASN1_FUNCTIONS(ASN1_TIME)
|
||||
|
||||
static int is_utc(const int year)
|
||||
{
|
||||
if (50 <= year && year <= 149)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int leap_year(const int year)
|
||||
{
|
||||
if (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Compute the day of the week and the day of the year from the year, month
|
||||
* and day. The day of the year is straightforward, the day of the week uses
|
||||
* a form of Zeller's congruence. For this months start with March and are
|
||||
* numbered 4 through 15.
|
||||
*/
|
||||
static void determine_days(struct tm *tm)
|
||||
{
|
||||
static const int ydays[12] = {
|
||||
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
|
||||
};
|
||||
int y = tm->tm_year + 1900;
|
||||
int m = tm->tm_mon;
|
||||
int d = tm->tm_mday;
|
||||
int c;
|
||||
|
||||
tm->tm_yday = ydays[m] + d - 1;
|
||||
if (m >= 2) {
|
||||
/* March and onwards can be one day further into the year */
|
||||
tm->tm_yday += leap_year(y);
|
||||
m += 2;
|
||||
} else {
|
||||
/* Treat January and February as part of the previous year */
|
||||
m += 14;
|
||||
y--;
|
||||
}
|
||||
c = y / 100;
|
||||
y %= 100;
|
||||
/* Zeller's congruance */
|
||||
tm->tm_wday = (d + (13 * m) / 5 + y + y / 4 + c / 4 + 5 * c + 6) % 7;
|
||||
}
|
||||
|
||||
int asn1_time_to_tm(struct tm *tm, const ASN1_TIME *d)
|
||||
{
|
||||
static const int min[9] = { 0, 0, 1, 1, 0, 0, 0, 0, 0 };
|
||||
static const int max[9] = { 99, 99, 12, 31, 23, 59, 59, 12, 59 };
|
||||
static const int mdays[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||
char *a;
|
||||
int n, i, i2, l, o, min_l = 11, strict = 0, end = 6, btz = 5, md;
|
||||
struct tm tmp;
|
||||
|
||||
/*
|
||||
* ASN1_STRING_FLAG_X509_TIME is used to enforce RFC 5280
|
||||
* time string format, in which:
|
||||
*
|
||||
* 1. "seconds" is a 'MUST'
|
||||
* 2. "Zulu" timezone is a 'MUST'
|
||||
* 3. "+|-" is not allowed to indicate a time zone
|
||||
*/
|
||||
if (d->type == V_ASN1_UTCTIME) {
|
||||
if (d->flags & ASN1_STRING_FLAG_X509_TIME) {
|
||||
min_l = 13;
|
||||
strict = 1;
|
||||
}
|
||||
} else if (d->type == V_ASN1_GENERALIZEDTIME) {
|
||||
end = 7;
|
||||
btz = 6;
|
||||
if (d->flags & ASN1_STRING_FLAG_X509_TIME) {
|
||||
min_l = 15;
|
||||
strict = 1;
|
||||
} else {
|
||||
min_l = 13;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
l = d->length;
|
||||
a = (char *)d->data;
|
||||
o = 0;
|
||||
memset(&tmp, 0, sizeof(tmp));
|
||||
|
||||
/*
|
||||
* GENERALIZEDTIME is similar to UTCTIME except the year is represented
|
||||
* as YYYY. This stuff treats everything as a two digit field so make
|
||||
* first two fields 00 to 99
|
||||
*/
|
||||
|
||||
if (l < min_l)
|
||||
goto err;
|
||||
for (i = 0; i < end; i++) {
|
||||
if (!strict && (i == btz) && ((a[o] == 'Z') || (a[o] == '+') || (a[o] == '-'))) {
|
||||
i++;
|
||||
break;
|
||||
}
|
||||
if (!ossl_isdigit(a[o]))
|
||||
goto err;
|
||||
n = a[o] - '0';
|
||||
/* incomplete 2-digital number */
|
||||
if (++o == l)
|
||||
goto err;
|
||||
|
||||
if (!ossl_isdigit(a[o]))
|
||||
goto err;
|
||||
n = (n * 10) + a[o] - '0';
|
||||
/* no more bytes to read, but we haven't seen time-zone yet */
|
||||
if (++o == l)
|
||||
goto err;
|
||||
|
||||
i2 = (d->type == V_ASN1_UTCTIME) ? i + 1 : i;
|
||||
|
||||
if ((n < min[i2]) || (n > max[i2]))
|
||||
goto err;
|
||||
switch (i2) {
|
||||
case 0:
|
||||
/* UTC will never be here */
|
||||
tmp.tm_year = n * 100 - 1900;
|
||||
break;
|
||||
case 1:
|
||||
if (d->type == V_ASN1_UTCTIME)
|
||||
tmp.tm_year = n < 50 ? n + 100 : n;
|
||||
else
|
||||
tmp.tm_year += n;
|
||||
break;
|
||||
case 2:
|
||||
tmp.tm_mon = n - 1;
|
||||
break;
|
||||
case 3:
|
||||
/* check if tm_mday is valid in tm_mon */
|
||||
if (tmp.tm_mon == 1) {
|
||||
/* it's February */
|
||||
md = mdays[1] + leap_year(tmp.tm_year + 1900);
|
||||
} else {
|
||||
md = mdays[tmp.tm_mon];
|
||||
}
|
||||
if (n > md)
|
||||
goto err;
|
||||
tmp.tm_mday = n;
|
||||
determine_days(&tmp);
|
||||
break;
|
||||
case 4:
|
||||
tmp.tm_hour = n;
|
||||
break;
|
||||
case 5:
|
||||
tmp.tm_min = n;
|
||||
break;
|
||||
case 6:
|
||||
tmp.tm_sec = n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Optional fractional seconds: decimal point followed by one or more
|
||||
* digits.
|
||||
*/
|
||||
if (d->type == V_ASN1_GENERALIZEDTIME && a[o] == '.') {
|
||||
if (strict)
|
||||
/* RFC 5280 forbids fractional seconds */
|
||||
goto err;
|
||||
if (++o == l)
|
||||
goto err;
|
||||
i = o;
|
||||
while ((o < l) && ossl_isdigit(a[o]))
|
||||
o++;
|
||||
/* Must have at least one digit after decimal point */
|
||||
if (i == o)
|
||||
goto err;
|
||||
/* no more bytes to read, but we haven't seen time-zone yet */
|
||||
if (o == l)
|
||||
goto err;
|
||||
}
|
||||
|
||||
/*
|
||||
* 'o' will never point to '\0' at this point, the only chance
|
||||
* 'o' can point to '\0' is either the subsequent if or the first
|
||||
* else if is true.
|
||||
*/
|
||||
if (a[o] == 'Z') {
|
||||
o++;
|
||||
} else if (!strict && ((a[o] == '+') || (a[o] == '-'))) {
|
||||
int offsign = a[o] == '-' ? 1 : -1;
|
||||
int offset = 0;
|
||||
|
||||
o++;
|
||||
/*
|
||||
* if not equal, no need to do subsequent checks
|
||||
* since the following for-loop will add 'o' by 4
|
||||
* and the final return statement will check if 'l'
|
||||
* and 'o' are equal.
|
||||
*/
|
||||
if (o + 4 != l)
|
||||
goto err;
|
||||
for (i = end; i < end + 2; i++) {
|
||||
if (!ossl_isdigit(a[o]))
|
||||
goto err;
|
||||
n = a[o] - '0';
|
||||
o++;
|
||||
if (!ossl_isdigit(a[o]))
|
||||
goto err;
|
||||
n = (n * 10) + a[o] - '0';
|
||||
i2 = (d->type == V_ASN1_UTCTIME) ? i + 1 : i;
|
||||
if ((n < min[i2]) || (n > max[i2]))
|
||||
goto err;
|
||||
/* if tm is NULL, no need to adjust */
|
||||
if (tm != NULL) {
|
||||
if (i == end)
|
||||
offset = n * 3600;
|
||||
else if (i == end + 1)
|
||||
offset += n * 60;
|
||||
}
|
||||
o++;
|
||||
}
|
||||
if (offset && !OPENSSL_gmtime_adj(&tmp, 0, offset * offsign))
|
||||
goto err;
|
||||
} else {
|
||||
/* not Z, or not +/- in non-strict mode */
|
||||
goto err;
|
||||
}
|
||||
if (o == l) {
|
||||
/* success, check if tm should be filled */
|
||||
if (tm != NULL)
|
||||
*tm = tmp;
|
||||
return 1;
|
||||
}
|
||||
err:
|
||||
return 0;
|
||||
}
|
||||
|
||||
ASN1_TIME *asn1_time_from_tm(ASN1_TIME *s, struct tm *ts, int type)
|
||||
{
|
||||
char* p;
|
||||
ASN1_TIME *tmps = NULL;
|
||||
const size_t len = 20;
|
||||
|
||||
if (type == V_ASN1_UNDEF) {
|
||||
if (is_utc(ts->tm_year))
|
||||
type = V_ASN1_UTCTIME;
|
||||
else
|
||||
type = V_ASN1_GENERALIZEDTIME;
|
||||
} else if (type == V_ASN1_UTCTIME) {
|
||||
if (!is_utc(ts->tm_year))
|
||||
goto err;
|
||||
} else if (type != V_ASN1_GENERALIZEDTIME) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (s == NULL)
|
||||
tmps = ASN1_STRING_new();
|
||||
else
|
||||
tmps = s;
|
||||
if (tmps == NULL)
|
||||
return NULL;
|
||||
|
||||
if (!ASN1_STRING_set(tmps, NULL, len))
|
||||
goto err;
|
||||
|
||||
tmps->type = type;
|
||||
p = (char*)tmps->data;
|
||||
|
||||
if (type == V_ASN1_GENERALIZEDTIME)
|
||||
tmps->length = BIO_snprintf(p, len, "%04d%02d%02d%02d%02d%02dZ",
|
||||
ts->tm_year + 1900, ts->tm_mon + 1,
|
||||
ts->tm_mday, ts->tm_hour, ts->tm_min,
|
||||
ts->tm_sec);
|
||||
else
|
||||
tmps->length = BIO_snprintf(p, len, "%02d%02d%02d%02d%02d%02dZ",
|
||||
ts->tm_year % 100, ts->tm_mon + 1,
|
||||
ts->tm_mday, ts->tm_hour, ts->tm_min,
|
||||
ts->tm_sec);
|
||||
|
||||
#ifdef CHARSET_EBCDIC_not
|
||||
ebcdic2ascii(tmps->data, tmps->data, tmps->length);
|
||||
#endif
|
||||
return tmps;
|
||||
err:
|
||||
if (tmps != s)
|
||||
ASN1_STRING_free(tmps);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t)
|
||||
{
|
||||
return ASN1_TIME_adj(s, t, 0, 0);
|
||||
@@ -44,9 +330,7 @@ ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t,
|
||||
if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec))
|
||||
return NULL;
|
||||
}
|
||||
if ((ts->tm_year >= 50) && (ts->tm_year < 150))
|
||||
return ASN1_UTCTIME_adj(s, t, offset_day, offset_sec);
|
||||
return ASN1_GENERALIZEDTIME_adj(s, t, offset_day, offset_sec);
|
||||
return asn1_time_from_tm(s, ts, V_ASN1_UNDEF);
|
||||
}
|
||||
|
||||
int ASN1_TIME_check(const ASN1_TIME *t)
|
||||
@@ -63,108 +347,207 @@ ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(const ASN1_TIME *t,
|
||||
ASN1_GENERALIZEDTIME **out)
|
||||
{
|
||||
ASN1_GENERALIZEDTIME *ret = NULL;
|
||||
char *str;
|
||||
int newlen;
|
||||
struct tm tm;
|
||||
|
||||
if (!ASN1_TIME_check(t))
|
||||
if (!ASN1_TIME_to_tm(t, &tm))
|
||||
return NULL;
|
||||
|
||||
if (out == NULL || *out == NULL) {
|
||||
if ((ret = ASN1_GENERALIZEDTIME_new()) == NULL)
|
||||
goto err;
|
||||
} else
|
||||
if (out != NULL)
|
||||
ret = *out;
|
||||
|
||||
/* If already GeneralizedTime just copy across */
|
||||
if (t->type == V_ASN1_GENERALIZEDTIME) {
|
||||
if (!ASN1_STRING_set(ret, t->data, t->length))
|
||||
goto err;
|
||||
goto done;
|
||||
}
|
||||
ret = asn1_time_from_tm(ret, &tm, V_ASN1_GENERALIZEDTIME);
|
||||
|
||||
/* grow the string */
|
||||
if (!ASN1_STRING_set(ret, NULL, t->length + 2))
|
||||
goto err;
|
||||
/* ASN1_STRING_set() allocated 'len + 1' bytes. */
|
||||
newlen = t->length + 2 + 1;
|
||||
str = (char *)ret->data;
|
||||
/* Work out the century and prepend */
|
||||
if (t->data[0] >= '5')
|
||||
OPENSSL_strlcpy(str, "19", newlen);
|
||||
else
|
||||
OPENSSL_strlcpy(str, "20", newlen);
|
||||
if (out != NULL && ret != NULL)
|
||||
*out = ret;
|
||||
|
||||
OPENSSL_strlcat(str, (const char *)t->data, newlen);
|
||||
|
||||
done:
|
||||
if (out != NULL && *out == NULL)
|
||||
*out = ret;
|
||||
return ret;
|
||||
|
||||
err:
|
||||
if (out == NULL || *out != ret)
|
||||
ASN1_GENERALIZEDTIME_free(ret);
|
||||
return NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int ASN1_TIME_set_string(ASN1_TIME *s, const char *str)
|
||||
{
|
||||
/* Try UTC, if that fails, try GENERALIZED */
|
||||
if (ASN1_UTCTIME_set_string(s, str))
|
||||
return 1;
|
||||
return ASN1_GENERALIZEDTIME_set_string(s, str);
|
||||
}
|
||||
|
||||
int ASN1_TIME_set_string_X509(ASN1_TIME *s, const char *str)
|
||||
{
|
||||
ASN1_TIME t;
|
||||
struct tm tm;
|
||||
int rv = 0;
|
||||
|
||||
t.length = strlen(str);
|
||||
t.data = (unsigned char *)str;
|
||||
t.flags = 0;
|
||||
t.flags = ASN1_STRING_FLAG_X509_TIME;
|
||||
|
||||
t.type = V_ASN1_UTCTIME;
|
||||
|
||||
if (!ASN1_TIME_check(&t)) {
|
||||
t.type = V_ASN1_GENERALIZEDTIME;
|
||||
if (!ASN1_TIME_check(&t))
|
||||
return 0;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (s && !ASN1_STRING_copy((ASN1_STRING *)s, (ASN1_STRING *)&t))
|
||||
return 0;
|
||||
/*
|
||||
* Per RFC 5280 (section 4.1.2.5.), the valid input time
|
||||
* strings should be encoded with the following rules:
|
||||
*
|
||||
* 1. UTC: YYMMDDHHMMSSZ, if YY < 50 (20YY) --> UTC: YYMMDDHHMMSSZ
|
||||
* 2. UTC: YYMMDDHHMMSSZ, if YY >= 50 (19YY) --> UTC: YYMMDDHHMMSSZ
|
||||
* 3. G'd: YYYYMMDDHHMMSSZ, if YYYY >= 2050 --> G'd: YYYYMMDDHHMMSSZ
|
||||
* 4. G'd: YYYYMMDDHHMMSSZ, if YYYY < 2050 --> UTC: YYMMDDHHMMSSZ
|
||||
*
|
||||
* Only strings of the 4th rule should be reformatted, but since a
|
||||
* UTC can only present [1950, 2050), so if the given time string
|
||||
* is less than 1950 (e.g. 19230419000000Z), we do nothing...
|
||||
*/
|
||||
|
||||
return 1;
|
||||
if (s != NULL && t.type == V_ASN1_GENERALIZEDTIME) {
|
||||
if (!asn1_time_to_tm(&tm, &t))
|
||||
goto out;
|
||||
if (is_utc(tm.tm_year)) {
|
||||
t.length -= 2;
|
||||
/*
|
||||
* it's OK to let original t.data go since that's assigned
|
||||
* to a piece of memory allocated outside of this function.
|
||||
* new t.data would be freed after ASN1_STRING_copy is done.
|
||||
*/
|
||||
t.data = OPENSSL_zalloc(t.length + 1);
|
||||
if (t.data == NULL)
|
||||
goto out;
|
||||
memcpy(t.data, str + 2, t.length);
|
||||
t.type = V_ASN1_UTCTIME;
|
||||
}
|
||||
}
|
||||
|
||||
if (s == NULL || ASN1_STRING_copy((ASN1_STRING *)s, (ASN1_STRING *)&t))
|
||||
rv = 1;
|
||||
|
||||
if (t.data != (unsigned char *)str)
|
||||
OPENSSL_free(t.data);
|
||||
out:
|
||||
return rv;
|
||||
}
|
||||
|
||||
static int asn1_time_to_tm(struct tm *tm, const ASN1_TIME *t)
|
||||
int ASN1_TIME_to_tm(const ASN1_TIME *s, struct tm *tm)
|
||||
{
|
||||
if (t == NULL) {
|
||||
if (s == NULL) {
|
||||
time_t now_t;
|
||||
|
||||
time(&now_t);
|
||||
if (OPENSSL_gmtime(&now_t, tm))
|
||||
memset(tm, 0, sizeof(*tm));
|
||||
if (OPENSSL_gmtime(&now_t, tm) != NULL)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (t->type == V_ASN1_UTCTIME)
|
||||
return asn1_utctime_to_tm(tm, t);
|
||||
else if (t->type == V_ASN1_GENERALIZEDTIME)
|
||||
return asn1_generalizedtime_to_tm(tm, t);
|
||||
|
||||
return 0;
|
||||
return asn1_time_to_tm(tm, s);
|
||||
}
|
||||
|
||||
int ASN1_TIME_diff(int *pday, int *psec,
|
||||
const ASN1_TIME *from, const ASN1_TIME *to)
|
||||
{
|
||||
struct tm tm_from, tm_to;
|
||||
if (!asn1_time_to_tm(&tm_from, from))
|
||||
|
||||
if (!ASN1_TIME_to_tm(from, &tm_from))
|
||||
return 0;
|
||||
if (!asn1_time_to_tm(&tm_to, to))
|
||||
if (!ASN1_TIME_to_tm(to, &tm_to))
|
||||
return 0;
|
||||
return OPENSSL_gmtime_diff(pday, psec, &tm_from, &tm_to);
|
||||
}
|
||||
|
||||
static const char _asn1_mon[12][4] = {
|
||||
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
||||
};
|
||||
|
||||
int ASN1_TIME_print(BIO *bp, const ASN1_TIME *tm)
|
||||
{
|
||||
if (tm->type == V_ASN1_UTCTIME)
|
||||
return ASN1_UTCTIME_print(bp, tm);
|
||||
if (tm->type == V_ASN1_GENERALIZEDTIME)
|
||||
return ASN1_GENERALIZEDTIME_print(bp, tm);
|
||||
char *v;
|
||||
int gmt = 0, l;
|
||||
struct tm stm;
|
||||
|
||||
if (!asn1_time_to_tm(&stm, tm)) {
|
||||
/* asn1_time_to_tm will check the time type */
|
||||
goto err;
|
||||
}
|
||||
|
||||
l = tm->length;
|
||||
v = (char *)tm->data;
|
||||
if (v[l - 1] == 'Z')
|
||||
gmt = 1;
|
||||
|
||||
if (tm->type == V_ASN1_GENERALIZEDTIME) {
|
||||
char *f = NULL;
|
||||
int f_len = 0;
|
||||
|
||||
/*
|
||||
* Try to parse fractional seconds. '14' is the place of
|
||||
* 'fraction point' in a GeneralizedTime string.
|
||||
*/
|
||||
if (tm->length > 15 && v[14] == '.') {
|
||||
f = &v[14];
|
||||
f_len = 1;
|
||||
while (14 + f_len < l && ossl_isdigit(f[f_len]))
|
||||
++f_len;
|
||||
}
|
||||
|
||||
return BIO_printf(bp, "%s %2d %02d:%02d:%02d%.*s %d%s",
|
||||
_asn1_mon[stm.tm_mon], stm.tm_mday, stm.tm_hour,
|
||||
stm.tm_min, stm.tm_sec, f_len, f, stm.tm_year + 1900,
|
||||
(gmt ? " GMT" : "")) > 0;
|
||||
} else {
|
||||
return BIO_printf(bp, "%s %2d %02d:%02d:%02d %d%s",
|
||||
_asn1_mon[stm.tm_mon], stm.tm_mday, stm.tm_hour,
|
||||
stm.tm_min, stm.tm_sec, stm.tm_year + 1900,
|
||||
(gmt ? " GMT" : "")) > 0;
|
||||
}
|
||||
err:
|
||||
BIO_write(bp, "Bad time value", 14);
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ASN1_TIME_cmp_time_t(const ASN1_TIME *s, time_t t)
|
||||
{
|
||||
struct tm stm, ttm;
|
||||
int day, sec;
|
||||
|
||||
if (!ASN1_TIME_to_tm(s, &stm))
|
||||
return -2;
|
||||
|
||||
if (!OPENSSL_gmtime(&t, &ttm))
|
||||
return -2;
|
||||
|
||||
if (!OPENSSL_gmtime_diff(&day, &sec, &ttm, &stm))
|
||||
return -2;
|
||||
|
||||
if (day > 0 || sec > 0)
|
||||
return 1;
|
||||
if (day < 0 || sec < 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ASN1_TIME_normalize(ASN1_TIME *t)
|
||||
{
|
||||
struct tm tm;
|
||||
|
||||
if (!ASN1_TIME_to_tm(t, &tm))
|
||||
return 0;
|
||||
|
||||
return asn1_time_from_tm(t, &tm, V_ASN1_UNDEF) != NULL;
|
||||
}
|
||||
|
||||
int ASN1_TIME_compare(const ASN1_TIME *a, const ASN1_TIME *b)
|
||||
{
|
||||
int day, sec;
|
||||
|
||||
if (!ASN1_TIME_diff(&day, &sec, b, a))
|
||||
return -2;
|
||||
if (day > 0 || sec > 0)
|
||||
return 1;
|
||||
if (day < 0 || sec < 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
@@ -16,9 +16,9 @@
|
||||
int ASN1_TYPE_get(const ASN1_TYPE *a)
|
||||
{
|
||||
if ((a->value.ptr != NULL) || (a->type == V_ASN1_NULL))
|
||||
return (a->type);
|
||||
return a->type;
|
||||
else
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value)
|
||||
|
||||
+24
-180
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -13,96 +13,13 @@
|
||||
#include <openssl/asn1.h>
|
||||
#include "asn1_locl.h"
|
||||
|
||||
/* This is the primary function used to parse ASN1_UTCTIME */
|
||||
int asn1_utctime_to_tm(struct tm *tm, const ASN1_UTCTIME *d)
|
||||
{
|
||||
static const int min[8] = { 0, 1, 1, 0, 0, 0, 0, 0 };
|
||||
static const int max[8] = { 99, 12, 31, 23, 59, 59, 12, 59 };
|
||||
char *a;
|
||||
int n, i, l, o;
|
||||
|
||||
/* wrapper around ans1_time_to_tm */
|
||||
if (d->type != V_ASN1_UTCTIME)
|
||||
return (0);
|
||||
l = d->length;
|
||||
a = (char *)d->data;
|
||||
o = 0;
|
||||
|
||||
if (l < 11)
|
||||
goto err;
|
||||
for (i = 0; i < 6; i++) {
|
||||
if ((i == 5) && ((a[o] == 'Z') || (a[o] == '+') || (a[o] == '-'))) {
|
||||
i++;
|
||||
if (tm)
|
||||
tm->tm_sec = 0;
|
||||
break;
|
||||
}
|
||||
if ((a[o] < '0') || (a[o] > '9'))
|
||||
goto err;
|
||||
n = a[o] - '0';
|
||||
if (++o > l)
|
||||
goto err;
|
||||
|
||||
if ((a[o] < '0') || (a[o] > '9'))
|
||||
goto err;
|
||||
n = (n * 10) + a[o] - '0';
|
||||
if (++o > l)
|
||||
goto err;
|
||||
|
||||
if ((n < min[i]) || (n > max[i]))
|
||||
goto err;
|
||||
if (tm) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
tm->tm_year = n < 50 ? n + 100 : n;
|
||||
break;
|
||||
case 1:
|
||||
tm->tm_mon = n - 1;
|
||||
break;
|
||||
case 2:
|
||||
tm->tm_mday = n;
|
||||
break;
|
||||
case 3:
|
||||
tm->tm_hour = n;
|
||||
break;
|
||||
case 4:
|
||||
tm->tm_min = n;
|
||||
break;
|
||||
case 5:
|
||||
tm->tm_sec = n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (a[o] == 'Z')
|
||||
o++;
|
||||
else if ((a[o] == '+') || (a[o] == '-')) {
|
||||
int offsign = a[o] == '-' ? 1 : -1, offset = 0;
|
||||
o++;
|
||||
if (o + 4 > l)
|
||||
goto err;
|
||||
for (i = 6; i < 8; i++) {
|
||||
if ((a[o] < '0') || (a[o] > '9'))
|
||||
goto err;
|
||||
n = a[o] - '0';
|
||||
o++;
|
||||
if ((a[o] < '0') || (a[o] > '9'))
|
||||
goto err;
|
||||
n = (n * 10) + a[o] - '0';
|
||||
if ((n < min[i]) || (n > max[i]))
|
||||
goto err;
|
||||
if (tm) {
|
||||
if (i == 6)
|
||||
offset = n * 3600;
|
||||
else if (i == 7)
|
||||
offset += n * 60;
|
||||
}
|
||||
o++;
|
||||
}
|
||||
if (offset && !OPENSSL_gmtime_adj(tm, 0, offset * offsign))
|
||||
return 0;
|
||||
}
|
||||
return o == l;
|
||||
err:
|
||||
return 0;
|
||||
return 0;
|
||||
return asn1_time_to_tm(tm, d);
|
||||
}
|
||||
|
||||
int ASN1_UTCTIME_check(const ASN1_UTCTIME *d)
|
||||
@@ -110,6 +27,7 @@ int ASN1_UTCTIME_check(const ASN1_UTCTIME *d)
|
||||
return asn1_utctime_to_tm(NULL, d);
|
||||
}
|
||||
|
||||
/* Sets the string via simple copy without cleaning it up */
|
||||
int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str)
|
||||
{
|
||||
ASN1_UTCTIME t;
|
||||
@@ -117,15 +35,15 @@ int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str)
|
||||
t.type = V_ASN1_UTCTIME;
|
||||
t.length = strlen(str);
|
||||
t.data = (unsigned char *)str;
|
||||
if (ASN1_UTCTIME_check(&t)) {
|
||||
if (s != NULL) {
|
||||
if (!ASN1_STRING_set((ASN1_STRING *)s, str, t.length))
|
||||
return 0;
|
||||
s->type = V_ASN1_UTCTIME;
|
||||
}
|
||||
return (1);
|
||||
} else
|
||||
return (0);
|
||||
t.flags = 0;
|
||||
|
||||
if (!ASN1_UTCTIME_check(&t))
|
||||
return 0;
|
||||
|
||||
if (s != NULL && !ASN1_STRING_copy(s, &t))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t)
|
||||
@@ -136,55 +54,19 @@ ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t)
|
||||
ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t,
|
||||
int offset_day, long offset_sec)
|
||||
{
|
||||
char *p;
|
||||
struct tm *ts;
|
||||
struct tm data;
|
||||
size_t len = 20;
|
||||
int free_s = 0;
|
||||
|
||||
if (s == NULL) {
|
||||
s = ASN1_UTCTIME_new();
|
||||
if (s == NULL)
|
||||
goto err;
|
||||
free_s = 1;
|
||||
}
|
||||
|
||||
ts = OPENSSL_gmtime(&t, &data);
|
||||
if (ts == NULL)
|
||||
goto err;
|
||||
return NULL;
|
||||
|
||||
if (offset_day || offset_sec) {
|
||||
if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec))
|
||||
goto err;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((ts->tm_year < 50) || (ts->tm_year >= 150))
|
||||
goto err;
|
||||
|
||||
p = (char *)s->data;
|
||||
if ((p == NULL) || ((size_t)s->length < len)) {
|
||||
p = OPENSSL_malloc(len);
|
||||
if (p == NULL) {
|
||||
ASN1err(ASN1_F_ASN1_UTCTIME_ADJ, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
OPENSSL_free(s->data);
|
||||
s->data = (unsigned char *)p;
|
||||
}
|
||||
|
||||
BIO_snprintf(p, len, "%02d%02d%02d%02d%02d%02dZ", ts->tm_year % 100,
|
||||
ts->tm_mon + 1, ts->tm_mday, ts->tm_hour, ts->tm_min,
|
||||
ts->tm_sec);
|
||||
s->length = strlen(p);
|
||||
s->type = V_ASN1_UTCTIME;
|
||||
#ifdef CHARSET_EBCDIC_not
|
||||
ebcdic2ascii(s->data, s->data, s->length);
|
||||
#endif
|
||||
return (s);
|
||||
err:
|
||||
if (free_s)
|
||||
ASN1_UTCTIME_free(s);
|
||||
return NULL;
|
||||
return asn1_time_from_tm(s, ts, V_ASN1_UTCTIME);
|
||||
}
|
||||
|
||||
int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t)
|
||||
@@ -195,60 +77,22 @@ int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t)
|
||||
if (!asn1_utctime_to_tm(&stm, s))
|
||||
return -2;
|
||||
|
||||
if (!OPENSSL_gmtime(&t, &ttm))
|
||||
if (OPENSSL_gmtime(&t, &ttm) == NULL)
|
||||
return -2;
|
||||
|
||||
if (!OPENSSL_gmtime_diff(&day, &sec, &ttm, &stm))
|
||||
return -2;
|
||||
|
||||
if (day > 0)
|
||||
if (day > 0 || sec > 0)
|
||||
return 1;
|
||||
if (day < 0)
|
||||
return -1;
|
||||
if (sec > 0)
|
||||
return 1;
|
||||
if (sec < 0)
|
||||
if (day < 0 || sec < 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ASN1_UTCTIME_print(BIO *bp, const ASN1_UTCTIME *tm)
|
||||
{
|
||||
const char *v;
|
||||
int gmt = 0;
|
||||
int i;
|
||||
int y = 0, M = 0, d = 0, h = 0, m = 0, s = 0;
|
||||
|
||||
i = tm->length;
|
||||
v = (const char *)tm->data;
|
||||
|
||||
if (i < 10)
|
||||
goto err;
|
||||
if (v[i - 1] == 'Z')
|
||||
gmt = 1;
|
||||
for (i = 0; i < 10; i++)
|
||||
if ((v[i] > '9') || (v[i] < '0'))
|
||||
goto err;
|
||||
y = (v[0] - '0') * 10 + (v[1] - '0');
|
||||
if (y < 50)
|
||||
y += 100;
|
||||
M = (v[2] - '0') * 10 + (v[3] - '0');
|
||||
if ((M > 12) || (M < 1))
|
||||
goto err;
|
||||
d = (v[4] - '0') * 10 + (v[5] - '0');
|
||||
h = (v[6] - '0') * 10 + (v[7] - '0');
|
||||
m = (v[8] - '0') * 10 + (v[9] - '0');
|
||||
if (tm->length >= 12 &&
|
||||
(v[10] >= '0') && (v[10] <= '9') && (v[11] >= '0') && (v[11] <= '9'))
|
||||
s = (v[10] - '0') * 10 + (v[11] - '0');
|
||||
|
||||
if (BIO_printf(bp, "%s %2d %02d:%02d:%02d %d%s",
|
||||
_asn1_mon[M - 1], d, h, m, s, y + 1900,
|
||||
(gmt) ? " GMT" : "") <= 0)
|
||||
return (0);
|
||||
else
|
||||
return (1);
|
||||
err:
|
||||
BIO_write(bp, "Bad time value", 14);
|
||||
return (0);
|
||||
if (tm->type != V_ASN1_UTCTIME)
|
||||
return 0;
|
||||
return ASN1_TIME_print(bp, tm);
|
||||
}
|
||||
+7
-16
@@ -76,7 +76,7 @@ int ASN1_verify(i2d_of_void *i2d, X509_ALGOR *a, ASN1_BIT_STRING *signature,
|
||||
ret = 1;
|
||||
err:
|
||||
EVP_MD_CTX_free(ctx);
|
||||
return (ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -86,7 +86,7 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a,
|
||||
{
|
||||
EVP_MD_CTX *ctx = NULL;
|
||||
unsigned char *buf_in = NULL;
|
||||
int ret = -1, inl;
|
||||
int ret = -1, inl = 0;
|
||||
|
||||
int mdnid, pknid;
|
||||
|
||||
@@ -156,24 +156,15 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a,
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = EVP_DigestVerifyUpdate(ctx, buf_in, inl);
|
||||
|
||||
OPENSSL_clear_free(buf_in, (unsigned int)inl);
|
||||
|
||||
if (!ret) {
|
||||
ret = EVP_DigestVerify(ctx, signature->data, (size_t)signature->length,
|
||||
buf_in, inl);
|
||||
if (ret <= 0) {
|
||||
ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ERR_R_EVP_LIB);
|
||||
goto err;
|
||||
}
|
||||
ret = -1;
|
||||
|
||||
if (EVP_DigestVerifyFinal(ctx, signature->data,
|
||||
(size_t)signature->length) <= 0) {
|
||||
ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ERR_R_EVP_LIB);
|
||||
ret = 0;
|
||||
goto err;
|
||||
}
|
||||
ret = 1;
|
||||
err:
|
||||
OPENSSL_clear_free(buf_in, (unsigned int)inl);
|
||||
EVP_MD_CTX_free(ctx);
|
||||
return (ret);
|
||||
return ret;
|
||||
}
|
||||
+33
-42
@@ -7,59 +7,20 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "e_os.h" /* for strncasecmp */
|
||||
#include "internal/cryptlib.h"
|
||||
#include <stdio.h>
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/engine.h>
|
||||
#include "internal/asn1_int.h"
|
||||
#include "internal/evp_int.h"
|
||||
|
||||
/* Keep this sorted in type order !! */
|
||||
static const EVP_PKEY_ASN1_METHOD *standard_methods[] = {
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
&rsa_asn1_meths[0],
|
||||
&rsa_asn1_meths[1],
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DH
|
||||
&dh_asn1_meth,
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
&dsa_asn1_meths[0],
|
||||
&dsa_asn1_meths[1],
|
||||
&dsa_asn1_meths[2],
|
||||
&dsa_asn1_meths[3],
|
||||
&dsa_asn1_meths[4],
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_EC
|
||||
&eckey_asn1_meth,
|
||||
#endif
|
||||
&hmac_asn1_meth,
|
||||
#ifndef OPENSSL_NO_CMAC
|
||||
&cmac_asn1_meth,
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DH
|
||||
&dhx_asn1_meth,
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_EC
|
||||
&ecx25519_asn1_meth
|
||||
#endif
|
||||
};
|
||||
#include "standard_methods.h"
|
||||
|
||||
typedef int sk_cmp_fn_type(const char *const *a, const char *const *b);
|
||||
static STACK_OF(EVP_PKEY_ASN1_METHOD) *app_methods = NULL;
|
||||
|
||||
#ifdef TEST
|
||||
void main()
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < OSSL_NELEM(standard_methods); i++)
|
||||
fprintf(stderr, "Number %d id=%d (%s)\n", i,
|
||||
standard_methods[i]->pkey_id,
|
||||
OBJ_nid2sn(standard_methods[i]->pkey_id));
|
||||
}
|
||||
#endif
|
||||
|
||||
DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_ASN1_METHOD *,
|
||||
const EVP_PKEY_ASN1_METHOD *, ameth);
|
||||
|
||||
@@ -301,6 +262,10 @@ void EVP_PKEY_asn1_copy(EVP_PKEY_ASN1_METHOD *dst,
|
||||
dst->item_sign = src->item_sign;
|
||||
dst->item_verify = src->item_verify;
|
||||
|
||||
dst->siginf_set = src->siginf_set;
|
||||
|
||||
dst->pkey_check = src->pkey_check;
|
||||
|
||||
}
|
||||
|
||||
void EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD *ameth)
|
||||
@@ -409,3 +374,29 @@ void EVP_PKEY_asn1_set_item(EVP_PKEY_ASN1_METHOD *ameth,
|
||||
ameth->item_sign = item_sign;
|
||||
ameth->item_verify = item_verify;
|
||||
}
|
||||
|
||||
void EVP_PKEY_asn1_set_siginf(EVP_PKEY_ASN1_METHOD *ameth,
|
||||
int (*siginf_set) (X509_SIG_INFO *siginf,
|
||||
const X509_ALGOR *alg,
|
||||
const ASN1_STRING *sig))
|
||||
{
|
||||
ameth->siginf_set = siginf_set;
|
||||
}
|
||||
|
||||
void EVP_PKEY_asn1_set_check(EVP_PKEY_ASN1_METHOD *ameth,
|
||||
int (*pkey_check) (const EVP_PKEY *pk))
|
||||
{
|
||||
ameth->pkey_check = pkey_check;
|
||||
}
|
||||
|
||||
void EVP_PKEY_asn1_set_public_check(EVP_PKEY_ASN1_METHOD *ameth,
|
||||
int (*pkey_pub_check) (const EVP_PKEY *pk))
|
||||
{
|
||||
ameth->pkey_public_check = pkey_pub_check;
|
||||
}
|
||||
|
||||
void EVP_PKEY_asn1_set_param_check(EVP_PKEY_ASN1_METHOD *ameth,
|
||||
int (*pkey_param_check) (const EVP_PKEY *pk))
|
||||
{
|
||||
ameth->pkey_param_check = pkey_param_check;
|
||||
}
|
||||
+301
-241
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Generated by util/mkerr.pl DO NOT EDIT
|
||||
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -8,251 +8,312 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/asn1err.h>
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
|
||||
# define ERR_FUNC(func) ERR_PACK(ERR_LIB_ASN1,func,0)
|
||||
# define ERR_REASON(reason) ERR_PACK(ERR_LIB_ASN1,0,reason)
|
||||
|
||||
static ERR_STRING_DATA ASN1_str_functs[] = {
|
||||
{ERR_FUNC(ASN1_F_A2D_ASN1_OBJECT), "a2d_ASN1_OBJECT"},
|
||||
{ERR_FUNC(ASN1_F_A2I_ASN1_INTEGER), "a2i_ASN1_INTEGER"},
|
||||
{ERR_FUNC(ASN1_F_A2I_ASN1_STRING), "a2i_ASN1_STRING"},
|
||||
{ERR_FUNC(ASN1_F_APPEND_EXP), "append_exp"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_BIT_STRING_SET_BIT), "ASN1_BIT_STRING_set_bit"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_CB), "asn1_cb"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_CHECK_TLEN), "asn1_check_tlen"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_COLLECT), "asn1_collect"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_D2I_EX_PRIMITIVE), "asn1_d2i_ex_primitive"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_D2I_FP), "ASN1_d2i_fp"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_D2I_READ_BIO), "asn1_d2i_read_bio"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_DIGEST), "ASN1_digest"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_DO_ADB), "asn1_do_adb"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_DO_LOCK), "asn1_do_lock"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_DUP), "ASN1_dup"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_EX_C2I), "asn1_ex_c2i"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_FIND_END), "asn1_find_end"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_GENERALIZEDTIME_ADJ), "ASN1_GENERALIZEDTIME_adj"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_GENERATE_V3), "ASN1_generate_v3"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_GET_INT64), "asn1_get_int64"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_GET_OBJECT), "ASN1_get_object"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_GET_UINT64), "asn1_get_uint64"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_I2D_BIO), "ASN1_i2d_bio"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_I2D_FP), "ASN1_i2d_fp"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_ITEM_D2I_FP), "ASN1_item_d2i_fp"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_ITEM_DUP), "ASN1_item_dup"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_ITEM_EMBED_D2I), "asn1_item_embed_d2i"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_ITEM_EMBED_NEW), "asn1_item_embed_new"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_ITEM_I2D_BIO), "ASN1_item_i2d_bio"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_ITEM_I2D_FP), "ASN1_item_i2d_fp"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_ITEM_PACK), "ASN1_item_pack"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_ITEM_SIGN), "ASN1_item_sign"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_ITEM_SIGN_CTX), "ASN1_item_sign_ctx"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_ITEM_UNPACK), "ASN1_item_unpack"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_ITEM_VERIFY), "ASN1_item_verify"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_MBSTRING_NCOPY), "ASN1_mbstring_ncopy"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_OBJECT_NEW), "ASN1_OBJECT_new"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_OUTPUT_DATA), "asn1_output_data"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_PCTX_NEW), "ASN1_PCTX_new"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_SCTX_NEW), "ASN1_SCTX_new"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_SIGN), "ASN1_sign"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_STR2TYPE), "asn1_str2type"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_STRING_GET_INT64), "asn1_string_get_int64"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_STRING_GET_UINT64), "asn1_string_get_uint64"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_STRING_SET), "ASN1_STRING_set"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_STRING_TABLE_ADD), "ASN1_STRING_TABLE_add"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_STRING_TO_BN), "asn1_string_to_bn"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_STRING_TYPE_NEW), "ASN1_STRING_type_new"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_TEMPLATE_EX_D2I), "asn1_template_ex_d2i"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_TEMPLATE_NEW), "asn1_template_new"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I), "asn1_template_noexp_d2i"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_TIME_ADJ), "ASN1_TIME_adj"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING),
|
||||
static const ERR_STRING_DATA ASN1_str_functs[] = {
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_A2D_ASN1_OBJECT, 0), "a2d_ASN1_OBJECT"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_A2I_ASN1_INTEGER, 0), "a2i_ASN1_INTEGER"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_A2I_ASN1_STRING, 0), "a2i_ASN1_STRING"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_APPEND_EXP, 0), "append_exp"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_BIT_STRING_SET_BIT, 0),
|
||||
"ASN1_BIT_STRING_set_bit"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_CB, 0), "asn1_cb"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_CHECK_TLEN, 0), "asn1_check_tlen"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_COLLECT, 0), "asn1_collect"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_D2I_EX_PRIMITIVE, 0),
|
||||
"asn1_d2i_ex_primitive"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_D2I_FP, 0), "ASN1_d2i_fp"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_D2I_READ_BIO, 0), "asn1_d2i_read_bio"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_DIGEST, 0), "ASN1_digest"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_DO_ADB, 0), "asn1_do_adb"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_DO_LOCK, 0), "asn1_do_lock"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_DUP, 0), "ASN1_dup"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_EX_C2I, 0), "asn1_ex_c2i"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_FIND_END, 0), "asn1_find_end"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_GENERALIZEDTIME_ADJ, 0),
|
||||
"ASN1_GENERALIZEDTIME_adj"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_GENERATE_V3, 0), "ASN1_generate_v3"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_GET_INT64, 0), "asn1_get_int64"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_GET_OBJECT, 0), "ASN1_get_object"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_GET_UINT64, 0), "asn1_get_uint64"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_I2D_BIO, 0), "ASN1_i2d_bio"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_I2D_FP, 0), "ASN1_i2d_fp"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_ITEM_D2I_FP, 0), "ASN1_item_d2i_fp"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_ITEM_DUP, 0), "ASN1_item_dup"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_ITEM_EMBED_D2I, 0),
|
||||
"asn1_item_embed_d2i"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_ITEM_EMBED_NEW, 0),
|
||||
"asn1_item_embed_new"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_ITEM_I2D_BIO, 0), "ASN1_item_i2d_bio"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_ITEM_I2D_FP, 0), "ASN1_item_i2d_fp"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_ITEM_PACK, 0), "ASN1_item_pack"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_ITEM_SIGN, 0), "ASN1_item_sign"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_ITEM_SIGN_CTX, 0),
|
||||
"ASN1_item_sign_ctx"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_ITEM_UNPACK, 0), "ASN1_item_unpack"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_ITEM_VERIFY, 0), "ASN1_item_verify"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_MBSTRING_NCOPY, 0),
|
||||
"ASN1_mbstring_ncopy"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_OBJECT_NEW, 0), "ASN1_OBJECT_new"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_OUTPUT_DATA, 0), "asn1_output_data"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_PCTX_NEW, 0), "ASN1_PCTX_new"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_SCTX_NEW, 0), "ASN1_SCTX_new"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_SIGN, 0), "ASN1_sign"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_STR2TYPE, 0), "asn1_str2type"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_STRING_GET_INT64, 0),
|
||||
"asn1_string_get_int64"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_STRING_GET_UINT64, 0),
|
||||
"asn1_string_get_uint64"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_STRING_SET, 0), "ASN1_STRING_set"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_STRING_TABLE_ADD, 0),
|
||||
"ASN1_STRING_TABLE_add"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_STRING_TO_BN, 0), "asn1_string_to_bn"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_STRING_TYPE_NEW, 0),
|
||||
"ASN1_STRING_type_new"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_TEMPLATE_EX_D2I, 0),
|
||||
"asn1_template_ex_d2i"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_TEMPLATE_NEW, 0), "asn1_template_new"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, 0),
|
||||
"asn1_template_noexp_d2i"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_TIME_ADJ, 0), "ASN1_TIME_adj"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING, 0),
|
||||
"ASN1_TYPE_get_int_octetstring"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_TYPE_GET_OCTETSTRING), "ASN1_TYPE_get_octetstring"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_UTCTIME_ADJ), "ASN1_UTCTIME_adj"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_VERIFY), "ASN1_verify"},
|
||||
{ERR_FUNC(ASN1_F_B64_READ_ASN1), "b64_read_asn1"},
|
||||
{ERR_FUNC(ASN1_F_B64_WRITE_ASN1), "B64_write_ASN1"},
|
||||
{ERR_FUNC(ASN1_F_BIO_NEW_NDEF), "BIO_new_NDEF"},
|
||||
{ERR_FUNC(ASN1_F_BITSTR_CB), "bitstr_cb"},
|
||||
{ERR_FUNC(ASN1_F_BN_TO_ASN1_STRING), "bn_to_asn1_string"},
|
||||
{ERR_FUNC(ASN1_F_C2I_ASN1_BIT_STRING), "c2i_ASN1_BIT_STRING"},
|
||||
{ERR_FUNC(ASN1_F_C2I_ASN1_INTEGER), "c2i_ASN1_INTEGER"},
|
||||
{ERR_FUNC(ASN1_F_C2I_ASN1_OBJECT), "c2i_ASN1_OBJECT"},
|
||||
{ERR_FUNC(ASN1_F_C2I_IBUF), "c2i_ibuf"},
|
||||
{ERR_FUNC(ASN1_F_C2I_UINT64_INT), "c2i_uint64_int"},
|
||||
{ERR_FUNC(ASN1_F_COLLECT_DATA), "collect_data"},
|
||||
{ERR_FUNC(ASN1_F_D2I_ASN1_OBJECT), "d2i_ASN1_OBJECT"},
|
||||
{ERR_FUNC(ASN1_F_D2I_ASN1_UINTEGER), "d2i_ASN1_UINTEGER"},
|
||||
{ERR_FUNC(ASN1_F_D2I_AUTOPRIVATEKEY), "d2i_AutoPrivateKey"},
|
||||
{ERR_FUNC(ASN1_F_D2I_PRIVATEKEY), "d2i_PrivateKey"},
|
||||
{ERR_FUNC(ASN1_F_D2I_PUBLICKEY), "d2i_PublicKey"},
|
||||
{ERR_FUNC(ASN1_F_DO_TCREATE), "do_tcreate"},
|
||||
{ERR_FUNC(ASN1_F_I2D_ASN1_BIO_STREAM), "i2d_ASN1_bio_stream"},
|
||||
{ERR_FUNC(ASN1_F_I2D_DSA_PUBKEY), "i2d_DSA_PUBKEY"},
|
||||
{ERR_FUNC(ASN1_F_I2D_EC_PUBKEY), "i2d_EC_PUBKEY"},
|
||||
{ERR_FUNC(ASN1_F_I2D_PRIVATEKEY), "i2d_PrivateKey"},
|
||||
{ERR_FUNC(ASN1_F_I2D_PUBLICKEY), "i2d_PublicKey"},
|
||||
{ERR_FUNC(ASN1_F_I2D_RSA_PUBKEY), "i2d_RSA_PUBKEY"},
|
||||
{ERR_FUNC(ASN1_F_LONG_C2I), "long_c2i"},
|
||||
{ERR_FUNC(ASN1_F_OID_MODULE_INIT), "oid_module_init"},
|
||||
{ERR_FUNC(ASN1_F_PARSE_TAGGING), "parse_tagging"},
|
||||
{ERR_FUNC(ASN1_F_PKCS5_PBE2_SET_IV), "PKCS5_pbe2_set_iv"},
|
||||
{ERR_FUNC(ASN1_F_PKCS5_PBE2_SET_SCRYPT), "PKCS5_pbe2_set_scrypt"},
|
||||
{ERR_FUNC(ASN1_F_PKCS5_PBE_SET), "PKCS5_pbe_set"},
|
||||
{ERR_FUNC(ASN1_F_PKCS5_PBE_SET0_ALGOR), "PKCS5_pbe_set0_algor"},
|
||||
{ERR_FUNC(ASN1_F_PKCS5_PBKDF2_SET), "PKCS5_pbkdf2_set"},
|
||||
{ERR_FUNC(ASN1_F_PKCS5_SCRYPT_SET), "pkcs5_scrypt_set"},
|
||||
{ERR_FUNC(ASN1_F_SMIME_READ_ASN1), "SMIME_read_ASN1"},
|
||||
{ERR_FUNC(ASN1_F_SMIME_TEXT), "SMIME_text"},
|
||||
{ERR_FUNC(ASN1_F_STBL_MODULE_INIT), "stbl_module_init"},
|
||||
{ERR_FUNC(ASN1_F_UINT32_C2I), "uint32_c2i"},
|
||||
{ERR_FUNC(ASN1_F_UINT64_C2I), "uint64_c2i"},
|
||||
{ERR_FUNC(ASN1_F_X509_CRL_ADD0_REVOKED), "X509_CRL_add0_revoked"},
|
||||
{ERR_FUNC(ASN1_F_X509_INFO_NEW), "X509_INFO_new"},
|
||||
{ERR_FUNC(ASN1_F_X509_NAME_ENCODE), "x509_name_encode"},
|
||||
{ERR_FUNC(ASN1_F_X509_NAME_EX_D2I), "x509_name_ex_d2i"},
|
||||
{ERR_FUNC(ASN1_F_X509_NAME_EX_NEW), "x509_name_ex_new"},
|
||||
{ERR_FUNC(ASN1_F_X509_PKEY_NEW), "X509_PKEY_new"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_TYPE_GET_OCTETSTRING, 0),
|
||||
"ASN1_TYPE_get_octetstring"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_UTCTIME_ADJ, 0), "ASN1_UTCTIME_adj"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_VERIFY, 0), "ASN1_verify"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_B64_READ_ASN1, 0), "b64_read_asn1"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_B64_WRITE_ASN1, 0), "B64_write_ASN1"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_BIO_NEW_NDEF, 0), "BIO_new_NDEF"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_BITSTR_CB, 0), "bitstr_cb"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_BN_TO_ASN1_STRING, 0), "bn_to_asn1_string"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_C2I_ASN1_BIT_STRING, 0),
|
||||
"c2i_ASN1_BIT_STRING"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_C2I_ASN1_INTEGER, 0), "c2i_ASN1_INTEGER"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_C2I_ASN1_OBJECT, 0), "c2i_ASN1_OBJECT"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_C2I_IBUF, 0), "c2i_ibuf"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_C2I_UINT64_INT, 0), "c2i_uint64_int"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_COLLECT_DATA, 0), "collect_data"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_D2I_ASN1_OBJECT, 0), "d2i_ASN1_OBJECT"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_D2I_ASN1_UINTEGER, 0), "d2i_ASN1_UINTEGER"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_D2I_AUTOPRIVATEKEY, 0),
|
||||
"d2i_AutoPrivateKey"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_D2I_PRIVATEKEY, 0), "d2i_PrivateKey"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_D2I_PUBLICKEY, 0), "d2i_PublicKey"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_DO_TCREATE, 0), "do_tcreate"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_I2D_ASN1_BIO_STREAM, 0),
|
||||
"i2d_ASN1_bio_stream"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_I2D_DSA_PUBKEY, 0), "i2d_DSA_PUBKEY"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_I2D_EC_PUBKEY, 0), "i2d_EC_PUBKEY"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_I2D_PRIVATEKEY, 0), "i2d_PrivateKey"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_I2D_PUBLICKEY, 0), "i2d_PublicKey"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_I2D_RSA_PUBKEY, 0), "i2d_RSA_PUBKEY"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_LONG_C2I, 0), "long_c2i"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_OID_MODULE_INIT, 0), "oid_module_init"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_PARSE_TAGGING, 0), "parse_tagging"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_PKCS5_PBE2_SET_IV, 0), "PKCS5_pbe2_set_iv"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_PKCS5_PBE2_SET_SCRYPT, 0),
|
||||
"PKCS5_pbe2_set_scrypt"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_PKCS5_PBE_SET, 0), "PKCS5_pbe_set"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_PKCS5_PBE_SET0_ALGOR, 0),
|
||||
"PKCS5_pbe_set0_algor"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_PKCS5_PBKDF2_SET, 0), "PKCS5_pbkdf2_set"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_PKCS5_SCRYPT_SET, 0), "pkcs5_scrypt_set"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_SMIME_READ_ASN1, 0), "SMIME_read_ASN1"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_SMIME_TEXT, 0), "SMIME_text"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_STBL_MODULE_INIT, 0), "stbl_module_init"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_UINT32_C2I, 0), "uint32_c2i"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_UINT64_C2I, 0), "uint64_c2i"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_X509_CRL_ADD0_REVOKED, 0),
|
||||
"X509_CRL_add0_revoked"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_X509_INFO_NEW, 0), "X509_INFO_new"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_X509_NAME_ENCODE, 0), "x509_name_encode"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_X509_NAME_EX_D2I, 0), "x509_name_ex_d2i"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_X509_NAME_EX_NEW, 0), "x509_name_ex_new"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_X509_PKEY_NEW, 0), "X509_PKEY_new"},
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
static ERR_STRING_DATA ASN1_str_reasons[] = {
|
||||
{ERR_REASON(ASN1_R_ADDING_OBJECT), "adding object"},
|
||||
{ERR_REASON(ASN1_R_ASN1_PARSE_ERROR), "asn1 parse error"},
|
||||
{ERR_REASON(ASN1_R_ASN1_SIG_PARSE_ERROR), "asn1 sig parse error"},
|
||||
{ERR_REASON(ASN1_R_AUX_ERROR), "aux error"},
|
||||
{ERR_REASON(ASN1_R_BAD_OBJECT_HEADER), "bad object header"},
|
||||
{ERR_REASON(ASN1_R_BMPSTRING_IS_WRONG_LENGTH),
|
||||
"bmpstring is wrong length"},
|
||||
{ERR_REASON(ASN1_R_BN_LIB), "bn lib"},
|
||||
{ERR_REASON(ASN1_R_BOOLEAN_IS_WRONG_LENGTH), "boolean is wrong length"},
|
||||
{ERR_REASON(ASN1_R_BUFFER_TOO_SMALL), "buffer too small"},
|
||||
{ERR_REASON(ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER),
|
||||
"cipher has no object identifier"},
|
||||
{ERR_REASON(ASN1_R_CONTEXT_NOT_INITIALISED), "context not initialised"},
|
||||
{ERR_REASON(ASN1_R_DATA_IS_WRONG), "data is wrong"},
|
||||
{ERR_REASON(ASN1_R_DECODE_ERROR), "decode error"},
|
||||
{ERR_REASON(ASN1_R_DEPTH_EXCEEDED), "depth exceeded"},
|
||||
{ERR_REASON(ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED),
|
||||
"digest and key type not supported"},
|
||||
{ERR_REASON(ASN1_R_ENCODE_ERROR), "encode error"},
|
||||
{ERR_REASON(ASN1_R_ERROR_GETTING_TIME), "error getting time"},
|
||||
{ERR_REASON(ASN1_R_ERROR_LOADING_SECTION), "error loading section"},
|
||||
{ERR_REASON(ASN1_R_ERROR_SETTING_CIPHER_PARAMS),
|
||||
"error setting cipher params"},
|
||||
{ERR_REASON(ASN1_R_EXPECTING_AN_INTEGER), "expecting an integer"},
|
||||
{ERR_REASON(ASN1_R_EXPECTING_AN_OBJECT), "expecting an object"},
|
||||
{ERR_REASON(ASN1_R_EXPLICIT_LENGTH_MISMATCH), "explicit length mismatch"},
|
||||
{ERR_REASON(ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED),
|
||||
"explicit tag not constructed"},
|
||||
{ERR_REASON(ASN1_R_FIELD_MISSING), "field missing"},
|
||||
{ERR_REASON(ASN1_R_FIRST_NUM_TOO_LARGE), "first num too large"},
|
||||
{ERR_REASON(ASN1_R_HEADER_TOO_LONG), "header too long"},
|
||||
{ERR_REASON(ASN1_R_ILLEGAL_BITSTRING_FORMAT), "illegal bitstring format"},
|
||||
{ERR_REASON(ASN1_R_ILLEGAL_BOOLEAN), "illegal boolean"},
|
||||
{ERR_REASON(ASN1_R_ILLEGAL_CHARACTERS), "illegal characters"},
|
||||
{ERR_REASON(ASN1_R_ILLEGAL_FORMAT), "illegal format"},
|
||||
{ERR_REASON(ASN1_R_ILLEGAL_HEX), "illegal hex"},
|
||||
{ERR_REASON(ASN1_R_ILLEGAL_IMPLICIT_TAG), "illegal implicit tag"},
|
||||
{ERR_REASON(ASN1_R_ILLEGAL_INTEGER), "illegal integer"},
|
||||
{ERR_REASON(ASN1_R_ILLEGAL_NEGATIVE_VALUE), "illegal negative value"},
|
||||
{ERR_REASON(ASN1_R_ILLEGAL_NESTED_TAGGING), "illegal nested tagging"},
|
||||
{ERR_REASON(ASN1_R_ILLEGAL_NULL), "illegal null"},
|
||||
{ERR_REASON(ASN1_R_ILLEGAL_NULL_VALUE), "illegal null value"},
|
||||
{ERR_REASON(ASN1_R_ILLEGAL_OBJECT), "illegal object"},
|
||||
{ERR_REASON(ASN1_R_ILLEGAL_OPTIONAL_ANY), "illegal optional any"},
|
||||
{ERR_REASON(ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE),
|
||||
"illegal options on item template"},
|
||||
{ERR_REASON(ASN1_R_ILLEGAL_PADDING), "illegal padding"},
|
||||
{ERR_REASON(ASN1_R_ILLEGAL_TAGGED_ANY), "illegal tagged any"},
|
||||
{ERR_REASON(ASN1_R_ILLEGAL_TIME_VALUE), "illegal time value"},
|
||||
{ERR_REASON(ASN1_R_ILLEGAL_ZERO_CONTENT), "illegal zero content"},
|
||||
{ERR_REASON(ASN1_R_INTEGER_NOT_ASCII_FORMAT), "integer not ascii format"},
|
||||
{ERR_REASON(ASN1_R_INTEGER_TOO_LARGE_FOR_LONG),
|
||||
"integer too large for long"},
|
||||
{ERR_REASON(ASN1_R_INVALID_BIT_STRING_BITS_LEFT),
|
||||
"invalid bit string bits left"},
|
||||
{ERR_REASON(ASN1_R_INVALID_BMPSTRING_LENGTH), "invalid bmpstring length"},
|
||||
{ERR_REASON(ASN1_R_INVALID_DIGIT), "invalid digit"},
|
||||
{ERR_REASON(ASN1_R_INVALID_MIME_TYPE), "invalid mime type"},
|
||||
{ERR_REASON(ASN1_R_INVALID_MODIFIER), "invalid modifier"},
|
||||
{ERR_REASON(ASN1_R_INVALID_NUMBER), "invalid number"},
|
||||
{ERR_REASON(ASN1_R_INVALID_OBJECT_ENCODING), "invalid object encoding"},
|
||||
{ERR_REASON(ASN1_R_INVALID_SCRYPT_PARAMETERS),
|
||||
"invalid scrypt parameters"},
|
||||
{ERR_REASON(ASN1_R_INVALID_SEPARATOR), "invalid separator"},
|
||||
{ERR_REASON(ASN1_R_INVALID_STRING_TABLE_VALUE),
|
||||
"invalid string table value"},
|
||||
{ERR_REASON(ASN1_R_INVALID_UNIVERSALSTRING_LENGTH),
|
||||
"invalid universalstring length"},
|
||||
{ERR_REASON(ASN1_R_INVALID_UTF8STRING), "invalid utf8string"},
|
||||
{ERR_REASON(ASN1_R_INVALID_VALUE), "invalid value"},
|
||||
{ERR_REASON(ASN1_R_LIST_ERROR), "list error"},
|
||||
{ERR_REASON(ASN1_R_MIME_NO_CONTENT_TYPE), "mime no content type"},
|
||||
{ERR_REASON(ASN1_R_MIME_PARSE_ERROR), "mime parse error"},
|
||||
{ERR_REASON(ASN1_R_MIME_SIG_PARSE_ERROR), "mime sig parse error"},
|
||||
{ERR_REASON(ASN1_R_MISSING_EOC), "missing eoc"},
|
||||
{ERR_REASON(ASN1_R_MISSING_SECOND_NUMBER), "missing second number"},
|
||||
{ERR_REASON(ASN1_R_MISSING_VALUE), "missing value"},
|
||||
{ERR_REASON(ASN1_R_MSTRING_NOT_UNIVERSAL), "mstring not universal"},
|
||||
{ERR_REASON(ASN1_R_MSTRING_WRONG_TAG), "mstring wrong tag"},
|
||||
{ERR_REASON(ASN1_R_NESTED_ASN1_STRING), "nested asn1 string"},
|
||||
{ERR_REASON(ASN1_R_NESTED_TOO_DEEP), "nested too deep"},
|
||||
{ERR_REASON(ASN1_R_NON_HEX_CHARACTERS), "non hex characters"},
|
||||
{ERR_REASON(ASN1_R_NOT_ASCII_FORMAT), "not ascii format"},
|
||||
{ERR_REASON(ASN1_R_NOT_ENOUGH_DATA), "not enough data"},
|
||||
{ERR_REASON(ASN1_R_NO_CONTENT_TYPE), "no content type"},
|
||||
{ERR_REASON(ASN1_R_NO_MATCHING_CHOICE_TYPE), "no matching choice type"},
|
||||
{ERR_REASON(ASN1_R_NO_MULTIPART_BODY_FAILURE),
|
||||
"no multipart body failure"},
|
||||
{ERR_REASON(ASN1_R_NO_MULTIPART_BOUNDARY), "no multipart boundary"},
|
||||
{ERR_REASON(ASN1_R_NO_SIG_CONTENT_TYPE), "no sig content type"},
|
||||
{ERR_REASON(ASN1_R_NULL_IS_WRONG_LENGTH), "null is wrong length"},
|
||||
{ERR_REASON(ASN1_R_OBJECT_NOT_ASCII_FORMAT), "object not ascii format"},
|
||||
{ERR_REASON(ASN1_R_ODD_NUMBER_OF_CHARS), "odd number of chars"},
|
||||
{ERR_REASON(ASN1_R_SECOND_NUMBER_TOO_LARGE), "second number too large"},
|
||||
{ERR_REASON(ASN1_R_SEQUENCE_LENGTH_MISMATCH), "sequence length mismatch"},
|
||||
{ERR_REASON(ASN1_R_SEQUENCE_NOT_CONSTRUCTED), "sequence not constructed"},
|
||||
{ERR_REASON(ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG),
|
||||
"sequence or set needs config"},
|
||||
{ERR_REASON(ASN1_R_SHORT_LINE), "short line"},
|
||||
{ERR_REASON(ASN1_R_SIG_INVALID_MIME_TYPE), "sig invalid mime type"},
|
||||
{ERR_REASON(ASN1_R_STREAMING_NOT_SUPPORTED), "streaming not supported"},
|
||||
{ERR_REASON(ASN1_R_STRING_TOO_LONG), "string too long"},
|
||||
{ERR_REASON(ASN1_R_STRING_TOO_SHORT), "string too short"},
|
||||
{ERR_REASON(ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD),
|
||||
"the asn1 object identifier is not known for this md"},
|
||||
{ERR_REASON(ASN1_R_TIME_NOT_ASCII_FORMAT), "time not ascii format"},
|
||||
{ERR_REASON(ASN1_R_TOO_LARGE), "too large"},
|
||||
{ERR_REASON(ASN1_R_TOO_LONG), "too long"},
|
||||
{ERR_REASON(ASN1_R_TOO_SMALL), "too small"},
|
||||
{ERR_REASON(ASN1_R_TYPE_NOT_CONSTRUCTED), "type not constructed"},
|
||||
{ERR_REASON(ASN1_R_TYPE_NOT_PRIMITIVE), "type not primitive"},
|
||||
{ERR_REASON(ASN1_R_UNEXPECTED_EOC), "unexpected eoc"},
|
||||
{ERR_REASON(ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH),
|
||||
"universalstring is wrong length"},
|
||||
{ERR_REASON(ASN1_R_UNKNOWN_FORMAT), "unknown format"},
|
||||
{ERR_REASON(ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM),
|
||||
"unknown message digest algorithm"},
|
||||
{ERR_REASON(ASN1_R_UNKNOWN_OBJECT_TYPE), "unknown object type"},
|
||||
{ERR_REASON(ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE), "unknown public key type"},
|
||||
{ERR_REASON(ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM),
|
||||
"unknown signature algorithm"},
|
||||
{ERR_REASON(ASN1_R_UNKNOWN_TAG), "unknown tag"},
|
||||
{ERR_REASON(ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE),
|
||||
"unsupported any defined by type"},
|
||||
{ERR_REASON(ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE),
|
||||
"unsupported public key type"},
|
||||
{ERR_REASON(ASN1_R_UNSUPPORTED_TYPE), "unsupported type"},
|
||||
{ERR_REASON(ASN1_R_WRONG_INTEGER_TYPE), "wrong integer type"},
|
||||
{ERR_REASON(ASN1_R_WRONG_PUBLIC_KEY_TYPE), "wrong public key type"},
|
||||
{ERR_REASON(ASN1_R_WRONG_TAG), "wrong tag"},
|
||||
static const ERR_STRING_DATA ASN1_str_reasons[] = {
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_ADDING_OBJECT), "adding object"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_ASN1_PARSE_ERROR), "asn1 parse error"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_ASN1_SIG_PARSE_ERROR),
|
||||
"asn1 sig parse error"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_AUX_ERROR), "aux error"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_BAD_OBJECT_HEADER), "bad object header"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_BMPSTRING_IS_WRONG_LENGTH),
|
||||
"bmpstring is wrong length"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_BN_LIB), "bn lib"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_BOOLEAN_IS_WRONG_LENGTH),
|
||||
"boolean is wrong length"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_BUFFER_TOO_SMALL), "buffer too small"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER),
|
||||
"cipher has no object identifier"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_CONTEXT_NOT_INITIALISED),
|
||||
"context not initialised"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_DATA_IS_WRONG), "data is wrong"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_DECODE_ERROR), "decode error"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_DEPTH_EXCEEDED), "depth exceeded"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED),
|
||||
"digest and key type not supported"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_ENCODE_ERROR), "encode error"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_ERROR_GETTING_TIME),
|
||||
"error getting time"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_ERROR_LOADING_SECTION),
|
||||
"error loading section"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_ERROR_SETTING_CIPHER_PARAMS),
|
||||
"error setting cipher params"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_EXPECTING_AN_INTEGER),
|
||||
"expecting an integer"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_EXPECTING_AN_OBJECT),
|
||||
"expecting an object"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_EXPLICIT_LENGTH_MISMATCH),
|
||||
"explicit length mismatch"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED),
|
||||
"explicit tag not constructed"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_FIELD_MISSING), "field missing"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_FIRST_NUM_TOO_LARGE),
|
||||
"first num too large"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_HEADER_TOO_LONG), "header too long"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_ILLEGAL_BITSTRING_FORMAT),
|
||||
"illegal bitstring format"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_ILLEGAL_BOOLEAN), "illegal boolean"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_ILLEGAL_CHARACTERS),
|
||||
"illegal characters"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_ILLEGAL_FORMAT), "illegal format"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_ILLEGAL_HEX), "illegal hex"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_ILLEGAL_IMPLICIT_TAG),
|
||||
"illegal implicit tag"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_ILLEGAL_INTEGER), "illegal integer"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_ILLEGAL_NEGATIVE_VALUE),
|
||||
"illegal negative value"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_ILLEGAL_NESTED_TAGGING),
|
||||
"illegal nested tagging"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_ILLEGAL_NULL), "illegal null"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_ILLEGAL_NULL_VALUE),
|
||||
"illegal null value"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_ILLEGAL_OBJECT), "illegal object"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_ILLEGAL_OPTIONAL_ANY),
|
||||
"illegal optional any"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE),
|
||||
"illegal options on item template"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_ILLEGAL_PADDING), "illegal padding"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_ILLEGAL_TAGGED_ANY),
|
||||
"illegal tagged any"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_ILLEGAL_TIME_VALUE),
|
||||
"illegal time value"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_ILLEGAL_ZERO_CONTENT),
|
||||
"illegal zero content"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_INTEGER_NOT_ASCII_FORMAT),
|
||||
"integer not ascii format"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG),
|
||||
"integer too large for long"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_INVALID_BIT_STRING_BITS_LEFT),
|
||||
"invalid bit string bits left"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_INVALID_BMPSTRING_LENGTH),
|
||||
"invalid bmpstring length"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_INVALID_DIGIT), "invalid digit"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_INVALID_MIME_TYPE), "invalid mime type"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_INVALID_MODIFIER), "invalid modifier"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_INVALID_NUMBER), "invalid number"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_INVALID_OBJECT_ENCODING),
|
||||
"invalid object encoding"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_INVALID_SCRYPT_PARAMETERS),
|
||||
"invalid scrypt parameters"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_INVALID_SEPARATOR), "invalid separator"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_INVALID_STRING_TABLE_VALUE),
|
||||
"invalid string table value"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_INVALID_UNIVERSALSTRING_LENGTH),
|
||||
"invalid universalstring length"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_INVALID_UTF8STRING),
|
||||
"invalid utf8string"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_INVALID_VALUE), "invalid value"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_LIST_ERROR), "list error"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_MIME_NO_CONTENT_TYPE),
|
||||
"mime no content type"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_MIME_PARSE_ERROR), "mime parse error"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_MIME_SIG_PARSE_ERROR),
|
||||
"mime sig parse error"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_MISSING_EOC), "missing eoc"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_MISSING_SECOND_NUMBER),
|
||||
"missing second number"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_MISSING_VALUE), "missing value"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_MSTRING_NOT_UNIVERSAL),
|
||||
"mstring not universal"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_MSTRING_WRONG_TAG), "mstring wrong tag"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_NESTED_ASN1_STRING),
|
||||
"nested asn1 string"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_NON_HEX_CHARACTERS),
|
||||
"non hex characters"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_NOT_ASCII_FORMAT), "not ascii format"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_NOT_ENOUGH_DATA), "not enough data"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_NO_CONTENT_TYPE), "no content type"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_NO_MATCHING_CHOICE_TYPE),
|
||||
"no matching choice type"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_NO_MULTIPART_BODY_FAILURE),
|
||||
"no multipart body failure"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_NO_MULTIPART_BOUNDARY),
|
||||
"no multipart boundary"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_NO_SIG_CONTENT_TYPE),
|
||||
"no sig content type"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_NULL_IS_WRONG_LENGTH),
|
||||
"null is wrong length"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_OBJECT_NOT_ASCII_FORMAT),
|
||||
"object not ascii format"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_ODD_NUMBER_OF_CHARS),
|
||||
"odd number of chars"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_SECOND_NUMBER_TOO_LARGE),
|
||||
"second number too large"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_SEQUENCE_LENGTH_MISMATCH),
|
||||
"sequence length mismatch"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_SEQUENCE_NOT_CONSTRUCTED),
|
||||
"sequence not constructed"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG),
|
||||
"sequence or set needs config"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_SHORT_LINE), "short line"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_SIG_INVALID_MIME_TYPE),
|
||||
"sig invalid mime type"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_STREAMING_NOT_SUPPORTED),
|
||||
"streaming not supported"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_STRING_TOO_LONG), "string too long"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_STRING_TOO_SHORT), "string too short"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD),
|
||||
"the asn1 object identifier is not known for this md"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_TIME_NOT_ASCII_FORMAT),
|
||||
"time not ascii format"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_TOO_LARGE), "too large"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_TOO_LONG), "too long"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_TOO_SMALL), "too small"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_TYPE_NOT_CONSTRUCTED),
|
||||
"type not constructed"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_TYPE_NOT_PRIMITIVE),
|
||||
"type not primitive"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_UNEXPECTED_EOC), "unexpected eoc"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH),
|
||||
"universalstring is wrong length"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_UNKNOWN_FORMAT), "unknown format"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM),
|
||||
"unknown message digest algorithm"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_UNKNOWN_OBJECT_TYPE),
|
||||
"unknown object type"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE),
|
||||
"unknown public key type"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM),
|
||||
"unknown signature algorithm"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_UNKNOWN_TAG), "unknown tag"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE),
|
||||
"unsupported any defined by type"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE),
|
||||
"unsupported public key type"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_UNSUPPORTED_TYPE), "unsupported type"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_WRONG_INTEGER_TYPE),
|
||||
"wrong integer type"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_WRONG_PUBLIC_KEY_TYPE),
|
||||
"wrong public key type"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, 0, ASN1_R_WRONG_TAG), "wrong tag"},
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
@@ -261,10 +322,9 @@ static ERR_STRING_DATA ASN1_str_reasons[] = {
|
||||
int ERR_load_ASN1_strings(void)
|
||||
{
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
|
||||
if (ERR_func_error_string(ASN1_str_functs[0].error) == NULL) {
|
||||
ERR_load_strings(0, ASN1_str_functs);
|
||||
ERR_load_strings(0, ASN1_str_reasons);
|
||||
ERR_load_strings_const(ASN1_str_functs);
|
||||
ERR_load_strings_const(ASN1_str_reasons);
|
||||
}
|
||||
#endif
|
||||
return 1;
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (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 "internal/cryptlib.h"
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/cms.h>
|
||||
#include <openssl/dh.h>
|
||||
#include <openssl/ocsp.h>
|
||||
#include <openssl/pkcs7.h>
|
||||
#include <openssl/pkcs12.h>
|
||||
#include <openssl/rsa.h>
|
||||
#include <openssl/x509v3.h>
|
||||
|
||||
#include "asn1_item_list.h"
|
||||
|
||||
const ASN1_ITEM *ASN1_ITEM_lookup(const char *name)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < OSSL_NELEM(asn1_item_list); i++) {
|
||||
const ASN1_ITEM *it = ASN1_ITEM_ptr(asn1_item_list[i]);
|
||||
|
||||
if (strcmp(it->sname, name) == 0)
|
||||
return it;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const ASN1_ITEM *ASN1_ITEM_get(size_t i)
|
||||
{
|
||||
if (i >= OSSL_NELEM(asn1_item_list))
|
||||
return NULL;
|
||||
return ASN1_ITEM_ptr(asn1_item_list[i]);
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
* Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (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
|
||||
*/
|
||||
|
||||
static ASN1_ITEM_EXP *asn1_item_list[] = {
|
||||
|
||||
ASN1_ITEM_ref(ACCESS_DESCRIPTION),
|
||||
#ifndef OPENSSL_NO_RFC3779
|
||||
ASN1_ITEM_ref(ASIdOrRange),
|
||||
ASN1_ITEM_ref(ASIdentifierChoice),
|
||||
ASN1_ITEM_ref(ASIdentifiers),
|
||||
#endif
|
||||
ASN1_ITEM_ref(ASN1_ANY),
|
||||
ASN1_ITEM_ref(ASN1_BIT_STRING),
|
||||
ASN1_ITEM_ref(ASN1_BMPSTRING),
|
||||
ASN1_ITEM_ref(ASN1_BOOLEAN),
|
||||
ASN1_ITEM_ref(ASN1_ENUMERATED),
|
||||
ASN1_ITEM_ref(ASN1_FBOOLEAN),
|
||||
ASN1_ITEM_ref(ASN1_GENERALIZEDTIME),
|
||||
ASN1_ITEM_ref(ASN1_GENERALSTRING),
|
||||
ASN1_ITEM_ref(ASN1_IA5STRING),
|
||||
ASN1_ITEM_ref(ASN1_INTEGER),
|
||||
ASN1_ITEM_ref(ASN1_NULL),
|
||||
ASN1_ITEM_ref(ASN1_OBJECT),
|
||||
ASN1_ITEM_ref(ASN1_OCTET_STRING_NDEF),
|
||||
ASN1_ITEM_ref(ASN1_OCTET_STRING),
|
||||
ASN1_ITEM_ref(ASN1_PRINTABLESTRING),
|
||||
ASN1_ITEM_ref(ASN1_PRINTABLE),
|
||||
ASN1_ITEM_ref(ASN1_SEQUENCE_ANY),
|
||||
ASN1_ITEM_ref(ASN1_SEQUENCE),
|
||||
ASN1_ITEM_ref(ASN1_SET_ANY),
|
||||
ASN1_ITEM_ref(ASN1_T61STRING),
|
||||
ASN1_ITEM_ref(ASN1_TBOOLEAN),
|
||||
ASN1_ITEM_ref(ASN1_TIME),
|
||||
ASN1_ITEM_ref(ASN1_UNIVERSALSTRING),
|
||||
ASN1_ITEM_ref(ASN1_UTCTIME),
|
||||
ASN1_ITEM_ref(ASN1_UTF8STRING),
|
||||
ASN1_ITEM_ref(ASN1_VISIBLESTRING),
|
||||
#ifndef OPENSSL_NO_RFC3779
|
||||
ASN1_ITEM_ref(ASRange),
|
||||
#endif
|
||||
ASN1_ITEM_ref(AUTHORITY_INFO_ACCESS),
|
||||
ASN1_ITEM_ref(AUTHORITY_KEYID),
|
||||
ASN1_ITEM_ref(BASIC_CONSTRAINTS),
|
||||
ASN1_ITEM_ref(BIGNUM),
|
||||
ASN1_ITEM_ref(CBIGNUM),
|
||||
ASN1_ITEM_ref(CERTIFICATEPOLICIES),
|
||||
#ifndef OPENSSL_NO_CMS
|
||||
ASN1_ITEM_ref(CMS_ContentInfo),
|
||||
ASN1_ITEM_ref(CMS_ReceiptRequest),
|
||||
#endif
|
||||
ASN1_ITEM_ref(CRL_DIST_POINTS),
|
||||
#ifndef OPENSSL_NO_DH
|
||||
ASN1_ITEM_ref(DHparams),
|
||||
#endif
|
||||
ASN1_ITEM_ref(DIRECTORYSTRING),
|
||||
ASN1_ITEM_ref(DISPLAYTEXT),
|
||||
ASN1_ITEM_ref(DIST_POINT_NAME),
|
||||
ASN1_ITEM_ref(DIST_POINT),
|
||||
#ifndef OPENSSL_NO_EC
|
||||
ASN1_ITEM_ref(ECPARAMETERS),
|
||||
ASN1_ITEM_ref(ECPKPARAMETERS),
|
||||
#endif
|
||||
ASN1_ITEM_ref(EDIPARTYNAME),
|
||||
ASN1_ITEM_ref(EXTENDED_KEY_USAGE),
|
||||
ASN1_ITEM_ref(GENERAL_NAMES),
|
||||
ASN1_ITEM_ref(GENERAL_NAME),
|
||||
ASN1_ITEM_ref(GENERAL_SUBTREE),
|
||||
#ifndef OPENSSL_NO_RFC3779
|
||||
ASN1_ITEM_ref(IPAddressChoice),
|
||||
ASN1_ITEM_ref(IPAddressFamily),
|
||||
ASN1_ITEM_ref(IPAddressOrRange),
|
||||
ASN1_ITEM_ref(IPAddressRange),
|
||||
#endif
|
||||
ASN1_ITEM_ref(ISSUING_DIST_POINT),
|
||||
#if OPENSSL_API_COMPAT < 0x10200000L
|
||||
ASN1_ITEM_ref(LONG),
|
||||
#endif
|
||||
ASN1_ITEM_ref(NAME_CONSTRAINTS),
|
||||
ASN1_ITEM_ref(NETSCAPE_CERT_SEQUENCE),
|
||||
ASN1_ITEM_ref(NETSCAPE_SPKAC),
|
||||
ASN1_ITEM_ref(NETSCAPE_SPKI),
|
||||
ASN1_ITEM_ref(NOTICEREF),
|
||||
#ifndef OPENSSL_NO_OCSP
|
||||
ASN1_ITEM_ref(OCSP_BASICRESP),
|
||||
ASN1_ITEM_ref(OCSP_CERTID),
|
||||
ASN1_ITEM_ref(OCSP_CERTSTATUS),
|
||||
ASN1_ITEM_ref(OCSP_CRLID),
|
||||
ASN1_ITEM_ref(OCSP_ONEREQ),
|
||||
ASN1_ITEM_ref(OCSP_REQINFO),
|
||||
ASN1_ITEM_ref(OCSP_REQUEST),
|
||||
ASN1_ITEM_ref(OCSP_RESPBYTES),
|
||||
ASN1_ITEM_ref(OCSP_RESPDATA),
|
||||
ASN1_ITEM_ref(OCSP_RESPID),
|
||||
ASN1_ITEM_ref(OCSP_RESPONSE),
|
||||
ASN1_ITEM_ref(OCSP_REVOKEDINFO),
|
||||
ASN1_ITEM_ref(OCSP_SERVICELOC),
|
||||
ASN1_ITEM_ref(OCSP_SIGNATURE),
|
||||
ASN1_ITEM_ref(OCSP_SINGLERESP),
|
||||
#endif
|
||||
ASN1_ITEM_ref(OTHERNAME),
|
||||
ASN1_ITEM_ref(PBE2PARAM),
|
||||
ASN1_ITEM_ref(PBEPARAM),
|
||||
ASN1_ITEM_ref(PBKDF2PARAM),
|
||||
ASN1_ITEM_ref(PKCS12_AUTHSAFES),
|
||||
ASN1_ITEM_ref(PKCS12_BAGS),
|
||||
ASN1_ITEM_ref(PKCS12_MAC_DATA),
|
||||
ASN1_ITEM_ref(PKCS12_SAFEBAGS),
|
||||
ASN1_ITEM_ref(PKCS12_SAFEBAG),
|
||||
ASN1_ITEM_ref(PKCS12),
|
||||
ASN1_ITEM_ref(PKCS7_ATTR_SIGN),
|
||||
ASN1_ITEM_ref(PKCS7_ATTR_VERIFY),
|
||||
ASN1_ITEM_ref(PKCS7_DIGEST),
|
||||
ASN1_ITEM_ref(PKCS7_ENCRYPT),
|
||||
ASN1_ITEM_ref(PKCS7_ENC_CONTENT),
|
||||
ASN1_ITEM_ref(PKCS7_ENVELOPE),
|
||||
ASN1_ITEM_ref(PKCS7_ISSUER_AND_SERIAL),
|
||||
ASN1_ITEM_ref(PKCS7_RECIP_INFO),
|
||||
ASN1_ITEM_ref(PKCS7_SIGNED),
|
||||
ASN1_ITEM_ref(PKCS7_SIGNER_INFO),
|
||||
ASN1_ITEM_ref(PKCS7_SIGN_ENVELOPE),
|
||||
ASN1_ITEM_ref(PKCS7),
|
||||
ASN1_ITEM_ref(PKCS8_PRIV_KEY_INFO),
|
||||
ASN1_ITEM_ref(PKEY_USAGE_PERIOD),
|
||||
ASN1_ITEM_ref(POLICYINFO),
|
||||
ASN1_ITEM_ref(POLICYQUALINFO),
|
||||
ASN1_ITEM_ref(POLICY_CONSTRAINTS),
|
||||
ASN1_ITEM_ref(POLICY_MAPPINGS),
|
||||
ASN1_ITEM_ref(POLICY_MAPPING),
|
||||
ASN1_ITEM_ref(PROXY_CERT_INFO_EXTENSION),
|
||||
ASN1_ITEM_ref(PROXY_POLICY),
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
ASN1_ITEM_ref(RSAPrivateKey),
|
||||
ASN1_ITEM_ref(RSAPublicKey),
|
||||
ASN1_ITEM_ref(RSA_OAEP_PARAMS),
|
||||
ASN1_ITEM_ref(RSA_PSS_PARAMS),
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_SCRYPT
|
||||
ASN1_ITEM_ref(SCRYPT_PARAMS),
|
||||
#endif
|
||||
ASN1_ITEM_ref(SXNETID),
|
||||
ASN1_ITEM_ref(SXNET),
|
||||
ASN1_ITEM_ref(USERNOTICE),
|
||||
ASN1_ITEM_ref(X509_ALGORS),
|
||||
ASN1_ITEM_ref(X509_ALGOR),
|
||||
ASN1_ITEM_ref(X509_ATTRIBUTE),
|
||||
ASN1_ITEM_ref(X509_CERT_AUX),
|
||||
ASN1_ITEM_ref(X509_CINF),
|
||||
ASN1_ITEM_ref(X509_CRL_INFO),
|
||||
ASN1_ITEM_ref(X509_CRL),
|
||||
ASN1_ITEM_ref(X509_EXTENSIONS),
|
||||
ASN1_ITEM_ref(X509_EXTENSION),
|
||||
ASN1_ITEM_ref(X509_NAME_ENTRY),
|
||||
ASN1_ITEM_ref(X509_NAME),
|
||||
ASN1_ITEM_ref(X509_PUBKEY),
|
||||
ASN1_ITEM_ref(X509_REQ_INFO),
|
||||
ASN1_ITEM_ref(X509_REQ),
|
||||
ASN1_ITEM_ref(X509_REVOKED),
|
||||
ASN1_ITEM_ref(X509_SIG),
|
||||
ASN1_ITEM_ref(X509_VAL),
|
||||
ASN1_ITEM_ref(X509),
|
||||
#if OPENSSL_API_COMPAT < 0x10200000L
|
||||
ASN1_ITEM_ref(ZLONG),
|
||||
#endif
|
||||
ASN1_ITEM_ref(INT32),
|
||||
ASN1_ITEM_ref(UINT32),
|
||||
ASN1_ITEM_ref(ZINT32),
|
||||
ASN1_ITEM_ref(ZUINT32),
|
||||
ASN1_ITEM_ref(INT64),
|
||||
ASN1_ITEM_ref(UINT64),
|
||||
ASN1_ITEM_ref(ZINT64),
|
||||
ASN1_ITEM_ref(ZUINT64),
|
||||
};
|
||||
+32
-25
@@ -23,12 +23,12 @@ static int _asn1_check_infinite_end(const unsigned char **p, long len)
|
||||
* If there is 0 or 1 byte left, the length check should pick things up
|
||||
*/
|
||||
if (len <= 0)
|
||||
return (1);
|
||||
return 1;
|
||||
else if ((len >= 2) && ((*p)[0] == 0) && ((*p)[1] == 0)) {
|
||||
(*p) += 2;
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ASN1_check_infinite_end(unsigned char **p, long len)
|
||||
@@ -96,47 +96,54 @@ int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag,
|
||||
ret |= 0x80;
|
||||
}
|
||||
*pp = p;
|
||||
return (ret | inf);
|
||||
return ret | inf;
|
||||
err:
|
||||
ASN1err(ASN1_F_ASN1_GET_OBJECT, ASN1_R_HEADER_TOO_LONG);
|
||||
return (0x80);
|
||||
return 0x80;
|
||||
}
|
||||
|
||||
/*
|
||||
* Decode a length field.
|
||||
* The short form is a single byte defining a length 0 - 127.
|
||||
* The long form is a byte 0 - 127 with the top bit set and this indicates
|
||||
* the number of following octets that contain the length. These octets
|
||||
* are stored most significant digit first.
|
||||
*/
|
||||
static int asn1_get_length(const unsigned char **pp, int *inf, long *rl,
|
||||
long max)
|
||||
{
|
||||
const unsigned char *p = *pp;
|
||||
unsigned long ret = 0;
|
||||
unsigned long i;
|
||||
int i;
|
||||
|
||||
if (max-- < 1)
|
||||
return 0;
|
||||
if (*p == 0x80) {
|
||||
*inf = 1;
|
||||
ret = 0;
|
||||
p++;
|
||||
} else {
|
||||
*inf = 0;
|
||||
i = *p & 0x7f;
|
||||
if (*(p++) & 0x80) {
|
||||
if (max < (long)i + 1)
|
||||
if (*p++ & 0x80) {
|
||||
if (max < i + 1)
|
||||
return 0;
|
||||
/* Skip leading zeroes */
|
||||
while (i && *p == 0) {
|
||||
while (i > 0 && *p == 0) {
|
||||
p++;
|
||||
i--;
|
||||
}
|
||||
if (i > sizeof(long))
|
||||
if (i > (int)sizeof(long))
|
||||
return 0;
|
||||
while (i-- > 0) {
|
||||
ret <<= 8L;
|
||||
ret |= *(p++);
|
||||
while (i > 0) {
|
||||
ret <<= 8;
|
||||
ret |= *p++;
|
||||
i--;
|
||||
}
|
||||
if (ret > LONG_MAX)
|
||||
return 0;
|
||||
} else
|
||||
ret = i;
|
||||
}
|
||||
if (ret > LONG_MAX)
|
||||
return 0;
|
||||
*pp = p;
|
||||
*rl = (long)ret;
|
||||
return 1;
|
||||
@@ -268,7 +275,7 @@ int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)
|
||||
|
||||
if (len < 0) {
|
||||
if (data == NULL)
|
||||
return (0);
|
||||
return 0;
|
||||
else
|
||||
len = strlen(data);
|
||||
}
|
||||
@@ -278,7 +285,7 @@ int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)
|
||||
if (str->data == NULL) {
|
||||
ASN1err(ASN1_F_ASN1_STRING_SET, ERR_R_MALLOC_FAILURE);
|
||||
str->data = c;
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
str->length = len;
|
||||
@@ -287,7 +294,7 @@ int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)
|
||||
/* an allowance for strings :-) */
|
||||
str->data[len] = '\0';
|
||||
}
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ASN1_STRING_set0(ASN1_STRING *str, void *data, int len)
|
||||
@@ -299,7 +306,7 @@ void ASN1_STRING_set0(ASN1_STRING *str, void *data, int len)
|
||||
|
||||
ASN1_STRING *ASN1_STRING_new(void)
|
||||
{
|
||||
return (ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
|
||||
return ASN1_STRING_type_new(V_ASN1_OCTET_STRING);
|
||||
}
|
||||
|
||||
ASN1_STRING *ASN1_STRING_type_new(int type)
|
||||
@@ -309,10 +316,10 @@ ASN1_STRING *ASN1_STRING_type_new(int type)
|
||||
ret = OPENSSL_zalloc(sizeof(*ret));
|
||||
if (ret == NULL) {
|
||||
ASN1err(ASN1_F_ASN1_STRING_TYPE_NEW, ERR_R_MALLOC_FAILURE);
|
||||
return (NULL);
|
||||
return NULL;
|
||||
}
|
||||
ret->type = type;
|
||||
return (ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void asn1_string_embed_free(ASN1_STRING *a, int embed)
|
||||
@@ -349,11 +356,11 @@ int ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b)
|
||||
if (i == 0) {
|
||||
i = memcmp(a->data, b->data, a->length);
|
||||
if (i == 0)
|
||||
return (a->type - b->type);
|
||||
return a->type - b->type;
|
||||
else
|
||||
return (i);
|
||||
return i;
|
||||
} else
|
||||
return (i);
|
||||
return i;
|
||||
}
|
||||
|
||||
int ASN1_STRING_length(const ASN1_STRING *x)
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
/* Internal ASN1 structures and functions: not for application use */
|
||||
|
||||
int asn1_time_to_tm(struct tm *tm, const ASN1_TIME *d);
|
||||
int asn1_utctime_to_tm(struct tm *tm, const ASN1_UTCTIME *d);
|
||||
int asn1_generalizedtime_to_tm(struct tm *tm, const ASN1_GENERALIZEDTIME *d);
|
||||
|
||||
@@ -42,9 +43,6 @@ DEFINE_STACK_OF(MIME_PARAM)
|
||||
typedef struct mime_header_st MIME_HEADER;
|
||||
DEFINE_STACK_OF(MIME_HEADER)
|
||||
|
||||
/* Month values for printing out times */
|
||||
extern const char *_asn1_mon[12];
|
||||
|
||||
void asn1_string_embed_free(ASN1_STRING *a, int embed);
|
||||
|
||||
int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
||||
@@ -81,3 +79,5 @@ ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp,
|
||||
/* Internal functions used by x_int64.c */
|
||||
int c2i_uint64_int(uint64_t *ret, int *neg, const unsigned char **pp, long len);
|
||||
int i2c_uint64_int(unsigned char *p, uint64_t r, int neg);
|
||||
|
||||
ASN1_TIME *asn1_time_from_tm(ASN1_TIME *s, struct tm *ts, int type);
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -50,20 +50,20 @@ static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed,
|
||||
|
||||
if (BIO_printf(bp, fmt, p) <= 0)
|
||||
goto err;
|
||||
return (1);
|
||||
return 1;
|
||||
err:
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ASN1_parse(BIO *bp, const unsigned char *pp, long len, int indent)
|
||||
{
|
||||
return (asn1_parse2(bp, &pp, len, 0, 0, indent, 0));
|
||||
return asn1_parse2(bp, &pp, len, 0, 0, indent, 0);
|
||||
}
|
||||
|
||||
int ASN1_parse_dump(BIO *bp, const unsigned char *pp, long len, int indent,
|
||||
int dump)
|
||||
{
|
||||
return (asn1_parse2(bp, &pp, len, 0, 0, indent, dump));
|
||||
return asn1_parse2(bp, &pp, len, 0, 0, indent, dump);
|
||||
}
|
||||
|
||||
static int asn1_parse2(BIO *bp, const unsigned char **pp, long length,
|
||||
@@ -342,7 +342,7 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length,
|
||||
ASN1_OBJECT_free(o);
|
||||
ASN1_OCTET_STRING_free(os);
|
||||
*pp = p;
|
||||
return (ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
const char *ASN1_tag2str(int tag)
|
||||
|
||||
+14
-30
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include "internal/ctype.h"
|
||||
#include "internal/cryptlib.h"
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/x509.h>
|
||||
@@ -635,7 +635,7 @@ static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio)
|
||||
return NULL;
|
||||
while ((len = BIO_gets(bio, linebuf, MAX_SMLEN)) > 0) {
|
||||
/* If whitespace at line start then continuation line */
|
||||
if (mhdr && isspace((unsigned char)linebuf[0]))
|
||||
if (mhdr && ossl_isspace(linebuf[0]))
|
||||
state = MIME_NAME;
|
||||
else
|
||||
state = MIME_START;
|
||||
@@ -759,7 +759,7 @@ static char *strip_start(char *name)
|
||||
/* Else null string */
|
||||
return NULL;
|
||||
}
|
||||
if (!isspace((unsigned char)c))
|
||||
if (!ossl_isspace(c))
|
||||
return p;
|
||||
}
|
||||
return NULL;
|
||||
@@ -780,7 +780,7 @@ static char *strip_end(char *name)
|
||||
*p = 0;
|
||||
return name;
|
||||
}
|
||||
if (isspace((unsigned char)c))
|
||||
if (ossl_isspace(c))
|
||||
*p = 0;
|
||||
else
|
||||
return name;
|
||||
@@ -792,29 +792,18 @@ static MIME_HEADER *mime_hdr_new(const char *name, const char *value)
|
||||
{
|
||||
MIME_HEADER *mhdr = NULL;
|
||||
char *tmpname = NULL, *tmpval = NULL, *p;
|
||||
int c;
|
||||
|
||||
if (name) {
|
||||
if ((tmpname = OPENSSL_strdup(name)) == NULL)
|
||||
return NULL;
|
||||
for (p = tmpname; *p; p++) {
|
||||
c = (unsigned char)*p;
|
||||
if (isupper(c)) {
|
||||
c = tolower(c);
|
||||
*p = c;
|
||||
}
|
||||
}
|
||||
for (p = tmpname; *p; p++)
|
||||
*p = ossl_tolower(*p);
|
||||
}
|
||||
if (value) {
|
||||
if ((tmpval = OPENSSL_strdup(value)) == NULL)
|
||||
goto err;
|
||||
for (p = tmpval; *p; p++) {
|
||||
c = (unsigned char)*p;
|
||||
if (isupper(c)) {
|
||||
c = tolower(c);
|
||||
*p = c;
|
||||
}
|
||||
}
|
||||
for (p = tmpval; *p; p++)
|
||||
*p = ossl_tolower(*p);
|
||||
}
|
||||
mhdr = OPENSSL_malloc(sizeof(*mhdr));
|
||||
if (mhdr == NULL)
|
||||
@@ -835,19 +824,14 @@ static MIME_HEADER *mime_hdr_new(const char *name, const char *value)
|
||||
static int mime_hdr_addparam(MIME_HEADER *mhdr, const char *name, const char *value)
|
||||
{
|
||||
char *tmpname = NULL, *tmpval = NULL, *p;
|
||||
int c;
|
||||
MIME_PARAM *mparam = NULL;
|
||||
|
||||
if (name) {
|
||||
tmpname = OPENSSL_strdup(name);
|
||||
if (!tmpname)
|
||||
goto err;
|
||||
for (p = tmpname; *p; p++) {
|
||||
c = (unsigned char)*p;
|
||||
if (isupper(c)) {
|
||||
c = tolower(c);
|
||||
*p = c;
|
||||
}
|
||||
}
|
||||
for (p = tmpname; *p; p++)
|
||||
*p = ossl_tolower(*p);
|
||||
}
|
||||
if (value) {
|
||||
tmpval = OPENSSL_strdup(value);
|
||||
@@ -876,7 +860,7 @@ static int mime_hdr_cmp(const MIME_HEADER *const *a,
|
||||
if (!(*a)->name || !(*b)->name)
|
||||
return ! !(*a)->name - ! !(*b)->name;
|
||||
|
||||
return (strcmp((*a)->name, (*b)->name));
|
||||
return strcmp((*a)->name, (*b)->name);
|
||||
}
|
||||
|
||||
static int mime_param_cmp(const MIME_PARAM *const *a,
|
||||
@@ -884,7 +868,7 @@ static int mime_param_cmp(const MIME_PARAM *const *a,
|
||||
{
|
||||
if (!(*a)->param_name || !(*b)->param_name)
|
||||
return ! !(*a)->param_name - ! !(*b)->param_name;
|
||||
return (strcmp((*a)->param_name, (*b)->param_name));
|
||||
return strcmp((*a)->param_name, (*b)->param_name);
|
||||
}
|
||||
|
||||
/* Find a header with a given name (if possible) */
|
||||
@@ -966,7 +950,7 @@ static int strip_eol(char *linebuf, int *plen, int flags)
|
||||
int len = *plen;
|
||||
char *p, c;
|
||||
int is_eol = 0;
|
||||
p = linebuf + len - 1;
|
||||
|
||||
for (p = linebuf + len - 1; len > 0; len--, p--) {
|
||||
c = *p;
|
||||
if (c == '\n')
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2002-2017 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include "internal/ctype.h"
|
||||
#include <openssl/crypto.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include <openssl/conf.h>
|
||||
@@ -72,7 +72,7 @@ static int do_create(const char *value, const char *name)
|
||||
ostr = p + 1;
|
||||
if (!*ostr)
|
||||
return 0;
|
||||
while (isspace((unsigned char)*ostr))
|
||||
while (ossl_isspace(*ostr))
|
||||
ostr++;
|
||||
}
|
||||
|
||||
@@ -83,10 +83,10 @@ static int do_create(const char *value, const char *name)
|
||||
|
||||
if (p) {
|
||||
ln = value;
|
||||
while (isspace((unsigned char)*ln))
|
||||
while (ossl_isspace(*ln))
|
||||
ln++;
|
||||
p--;
|
||||
while (isspace((unsigned char)*p)) {
|
||||
while (ossl_isspace(*p)) {
|
||||
if (p == ln)
|
||||
return 0;
|
||||
p--;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2012-2017 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -8,7 +8,6 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include <openssl/conf.h>
|
||||
|
||||
+11
-5
@@ -14,8 +14,9 @@
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <internal/bio.h>
|
||||
#include "internal/bio.h"
|
||||
#include <openssl/asn1.h>
|
||||
#include "internal/cryptlib.h"
|
||||
|
||||
/* Must be large enough for biggest tag+length */
|
||||
#define DEFAULT_ASN1_BUF_SIZE 20
|
||||
@@ -78,7 +79,11 @@ static int asn1_bio_setup_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx,
|
||||
static const BIO_METHOD methods_asn1 = {
|
||||
BIO_TYPE_ASN1,
|
||||
"asn1",
|
||||
/* TODO: Convert to new style write function */
|
||||
bwrite_conv,
|
||||
asn1_bio_write,
|
||||
/* TODO: Convert to new style read function */
|
||||
bread_conv,
|
||||
asn1_bio_read,
|
||||
asn1_bio_puts,
|
||||
asn1_bio_gets,
|
||||
@@ -90,7 +95,7 @@ static const BIO_METHOD methods_asn1 = {
|
||||
|
||||
const BIO_METHOD *BIO_f_asn1(void)
|
||||
{
|
||||
return (&methods_asn1);
|
||||
return &methods_asn1;
|
||||
}
|
||||
|
||||
static int asn1_bio_new(BIO *b)
|
||||
@@ -157,7 +162,6 @@ static int asn1_bio_write(BIO *b, const char *in, int inl)
|
||||
|
||||
for (;;) {
|
||||
switch (ctx->state) {
|
||||
|
||||
/* Setup prefix data, call it */
|
||||
case ASN1_STATE_START:
|
||||
if (!asn1_bio_setup_ex(b, ctx, ctx->prefix,
|
||||
@@ -178,7 +182,8 @@ static int asn1_bio_write(BIO *b, const char *in, int inl)
|
||||
|
||||
case ASN1_STATE_HEADER:
|
||||
ctx->buflen = ASN1_object_size(0, inl, ctx->asn1_tag) - inl;
|
||||
OPENSSL_assert(ctx->buflen <= ctx->bufsize);
|
||||
if (!ossl_assert(ctx->buflen <= ctx->bufsize))
|
||||
return 0;
|
||||
p = ctx->buf;
|
||||
ASN1_put_object(&p, 0, inl, ctx->asn1_tag, ctx->asn1_class);
|
||||
ctx->copylen = inl;
|
||||
@@ -223,7 +228,8 @@ static int asn1_bio_write(BIO *b, const char *in, int inl)
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
case ASN1_STATE_POST_COPY:
|
||||
case ASN1_STATE_DONE:
|
||||
BIO_clear_retry_flags(b);
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -13,4 +13,4 @@ SOURCE[../../libcrypto]=\
|
||||
x_pkey.c bio_asn1.c bio_ndef.c asn_mime.c \
|
||||
asn1_gen.c asn1_par.c asn1_lib.c asn1_err.c a_strnid.c \
|
||||
evp_asn1.c asn_pack.c p5_pbe.c p5_pbev2.c p5_scrypt.c p8_pkey.c \
|
||||
asn_moid.c asn_mstbl.c
|
||||
asn_moid.c asn_mstbl.c asn1_item_list.c
|
||||
@@ -2,7 +2,7 @@
|
||||
* WARNING: do not edit!
|
||||
* Generated by crypto/asn1/charmap.pl
|
||||
*
|
||||
* Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#! /usr/bin/env perl
|
||||
# Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
# Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the OpenSSL license (the "License"). You may not use
|
||||
# this file except in compliance with the License. You can obtain a copy
|
||||
@@ -82,12 +82,14 @@ $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;
|
||||
print <<EOF;
|
||||
/*
|
||||
* WARNING: do not edit!
|
||||
* Generated by crypto/asn1/charmap.pl
|
||||
*
|
||||
* Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2000-$YEAR The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
|
||||
@@ -27,7 +27,7 @@ EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp,
|
||||
if ((a == NULL) || (*a == NULL)) {
|
||||
if ((ret = EVP_PKEY_new()) == NULL) {
|
||||
ASN1err(ASN1_F_D2I_PRIVATEKEY, ERR_R_EVP_LIB);
|
||||
return (NULL);
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
ret = *a;
|
||||
@@ -64,11 +64,11 @@ EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp,
|
||||
*pp = p;
|
||||
if (a != NULL)
|
||||
(*a) = ret;
|
||||
return (ret);
|
||||
return ret;
|
||||
err:
|
||||
if (a == NULL || *a != ret)
|
||||
EVP_PKEY_free(ret);
|
||||
return (NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -27,7 +27,7 @@ EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp,
|
||||
if ((a == NULL) || (*a == NULL)) {
|
||||
if ((ret = EVP_PKEY_new()) == NULL) {
|
||||
ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_EVP_LIB);
|
||||
return (NULL);
|
||||
return NULL;
|
||||
}
|
||||
} else
|
||||
ret = *a;
|
||||
@@ -66,13 +66,12 @@ EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp,
|
||||
default:
|
||||
ASN1err(ASN1_F_D2I_PUBLICKEY, ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE);
|
||||
goto err;
|
||||
/* break; */
|
||||
}
|
||||
if (a != NULL)
|
||||
(*a) = ret;
|
||||
return (ret);
|
||||
return ret;
|
||||
err:
|
||||
if (a == NULL || *a != ret)
|
||||
EVP_PKEY_free(ret);
|
||||
return (NULL);
|
||||
return NULL;
|
||||
}
|
||||
@@ -17,13 +17,13 @@ int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len)
|
||||
ASN1_STRING *os;
|
||||
|
||||
if ((os = ASN1_OCTET_STRING_new()) == NULL)
|
||||
return (0);
|
||||
return 0;
|
||||
if (!ASN1_OCTET_STRING_set(os, data, len)) {
|
||||
ASN1_OCTET_STRING_free(os);
|
||||
return 0;
|
||||
}
|
||||
ASN1_TYPE_set(a, V_ASN1_OCTET_STRING, os);
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* int max_len: for returned value */
|
||||
@@ -34,7 +34,7 @@ int ASN1_TYPE_get_octetstring(const ASN1_TYPE *a, unsigned char *data, int max_l
|
||||
|
||||
if ((a->type != V_ASN1_OCTET_STRING) || (a->value.octet_string == NULL)) {
|
||||
ASN1err(ASN1_F_ASN1_TYPE_GET_OCTETSTRING, ASN1_R_DATA_IS_WRONG);
|
||||
return (-1);
|
||||
return -1;
|
||||
}
|
||||
p = ASN1_STRING_get0_data(a->value.octet_string);
|
||||
ret = ASN1_STRING_length(a->value.octet_string);
|
||||
@@ -43,16 +43,16 @@ int ASN1_TYPE_get_octetstring(const ASN1_TYPE *a, unsigned char *data, int max_l
|
||||
else
|
||||
num = max_len;
|
||||
memcpy(data, p, num);
|
||||
return (ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
long num;
|
||||
int32_t num;
|
||||
ASN1_OCTET_STRING *oct;
|
||||
} asn1_int_oct;
|
||||
|
||||
ASN1_SEQUENCE(asn1_int_oct) = {
|
||||
ASN1_SIMPLE(asn1_int_oct, num, LONG),
|
||||
ASN1_EMBED(asn1_int_oct, num, INT32),
|
||||
ASN1_SIMPLE(asn1_int_oct, oct, ASN1_OCTET_STRING)
|
||||
} static_ASN1_SEQUENCE_END(asn1_int_oct)
|
||||
|
||||
|
||||
+6
-17
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include "internal/ctype.h"
|
||||
#include "internal/cryptlib.h"
|
||||
#include <openssl/buffer.h>
|
||||
#include <openssl/asn1.h>
|
||||
@@ -20,7 +20,7 @@ int i2a_ASN1_INTEGER(BIO *bp, const ASN1_INTEGER *a)
|
||||
char buf[2];
|
||||
|
||||
if (a == NULL)
|
||||
return (0);
|
||||
return 0;
|
||||
|
||||
if (a->type & V_ASN1_NEG) {
|
||||
if (BIO_write(bp, "-", 1) != 1)
|
||||
@@ -46,9 +46,9 @@ int i2a_ASN1_INTEGER(BIO *bp, const ASN1_INTEGER *a)
|
||||
n += 2;
|
||||
}
|
||||
}
|
||||
return (n);
|
||||
return n;
|
||||
err:
|
||||
return (-1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size)
|
||||
@@ -76,18 +76,7 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size)
|
||||
again = (buf[i - 1] == '\\');
|
||||
|
||||
for (j = 0; j < i; j++) {
|
||||
#ifndef CHARSET_EBCDIC
|
||||
if (!(((buf[j] >= '0') && (buf[j] <= '9')) ||
|
||||
((buf[j] >= 'a') && (buf[j] <= 'f')) ||
|
||||
((buf[j] >= 'A') && (buf[j] <= 'F'))))
|
||||
#else
|
||||
/*
|
||||
* This #ifdef is not strictly necessary, since the characters
|
||||
* A...F a...f 0...9 are contiguous (yes, even in EBCDIC - but
|
||||
* not the whole alphabet). Nevertheless, isxdigit() is faster.
|
||||
*/
|
||||
if (!isxdigit(buf[j]))
|
||||
#endif
|
||||
if (!ossl_isxdigit(buf[j]))
|
||||
{
|
||||
i = j;
|
||||
break;
|
||||
|
||||
+7
-19
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include "internal/ctype.h"
|
||||
#include "internal/cryptlib.h"
|
||||
#include <openssl/buffer.h>
|
||||
#include <openssl/asn1.h>
|
||||
@@ -20,7 +20,7 @@ int i2a_ASN1_STRING(BIO *bp, const ASN1_STRING *a, int type)
|
||||
char buf[2];
|
||||
|
||||
if (a == NULL)
|
||||
return (0);
|
||||
return 0;
|
||||
|
||||
if (a->length == 0) {
|
||||
if (BIO_write(bp, "0", 1) != 1)
|
||||
@@ -40,14 +40,14 @@ int i2a_ASN1_STRING(BIO *bp, const ASN1_STRING *a, int type)
|
||||
n += 2;
|
||||
}
|
||||
}
|
||||
return (n);
|
||||
return n;
|
||||
err:
|
||||
return (-1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size)
|
||||
{
|
||||
int i, j, k, m, n, again, bufsize, spec_char;
|
||||
int i, j, k, m, n, again, bufsize;
|
||||
unsigned char *s = NULL, *sp;
|
||||
unsigned char *bufp;
|
||||
int num = 0, slen = 0, first = 1;
|
||||
@@ -74,19 +74,7 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size)
|
||||
again = (buf[i - 1] == '\\');
|
||||
|
||||
for (j = i - 1; j > 0; j--) {
|
||||
#ifndef CHARSET_EBCDIC
|
||||
spec_char = (!(((buf[j] >= '0') && (buf[j] <= '9')) ||
|
||||
((buf[j] >= 'a') && (buf[j] <= 'f')) ||
|
||||
((buf[j] >= 'A') && (buf[j] <= 'F'))));
|
||||
#else
|
||||
/*
|
||||
* This #ifdef is not strictly necessary, since the characters
|
||||
* A...F a...f 0...9 are contiguous (yes, even in EBCDIC - but
|
||||
* not the whole alphabet). Nevertheless, isxdigit() is faster.
|
||||
*/
|
||||
spec_char = (!isxdigit(buf[j]));
|
||||
#endif
|
||||
if (spec_char) {
|
||||
if (!ossl_isxdigit(buf[j])) {
|
||||
i = j;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ NON_EMPTY_TRANSLATION_UNIT
|
||||
# ifndef OPENSSL_NO_RC4
|
||||
|
||||
typedef struct netscape_pkey_st {
|
||||
long version;
|
||||
int32_t version;
|
||||
X509_ALGOR *algor;
|
||||
ASN1_OCTET_STRING *private_key;
|
||||
} NETSCAPE_PKEY;
|
||||
@@ -48,7 +48,7 @@ DECLARE_ASN1_ENCODE_FUNCTIONS_const(NETSCAPE_ENCRYPTED_PKEY,NETSCAPE_ENCRYPTED_P
|
||||
IMPLEMENT_ASN1_FUNCTIONS_const(NETSCAPE_ENCRYPTED_PKEY)
|
||||
|
||||
ASN1_SEQUENCE(NETSCAPE_PKEY) = {
|
||||
ASN1_SIMPLE(NETSCAPE_PKEY, version, LONG),
|
||||
ASN1_EMBED(NETSCAPE_PKEY, version, INT32),
|
||||
ASN1_SIMPLE(NETSCAPE_PKEY, algor, X509_ALGOR),
|
||||
ASN1_SIMPLE(NETSCAPE_PKEY, private_key, ASN1_OCTET_STRING)
|
||||
} static_ASN1_SEQUENCE_END(NETSCAPE_PKEY)
|
||||
|
||||
+2
-11
@@ -18,24 +18,15 @@
|
||||
#ifndef OPENSSL_NO_SCRYPT
|
||||
/* PKCS#5 scrypt password based encryption structures */
|
||||
|
||||
typedef struct {
|
||||
ASN1_OCTET_STRING *salt;
|
||||
ASN1_INTEGER *costParameter;
|
||||
ASN1_INTEGER *blockSize;
|
||||
ASN1_INTEGER *parallelizationParameter;
|
||||
ASN1_INTEGER *keyLength;
|
||||
} SCRYPT_PARAMS;
|
||||
|
||||
ASN1_SEQUENCE(SCRYPT_PARAMS) = {
|
||||
ASN1_SIMPLE(SCRYPT_PARAMS, salt, ASN1_OCTET_STRING),
|
||||
ASN1_SIMPLE(SCRYPT_PARAMS, costParameter, ASN1_INTEGER),
|
||||
ASN1_SIMPLE(SCRYPT_PARAMS, blockSize, ASN1_INTEGER),
|
||||
ASN1_SIMPLE(SCRYPT_PARAMS, parallelizationParameter, ASN1_INTEGER),
|
||||
ASN1_OPT(SCRYPT_PARAMS, keyLength, ASN1_INTEGER),
|
||||
} static_ASN1_SEQUENCE_END(SCRYPT_PARAMS)
|
||||
} ASN1_SEQUENCE_END(SCRYPT_PARAMS)
|
||||
|
||||
DECLARE_ASN1_ALLOC_FUNCTIONS(SCRYPT_PARAMS)
|
||||
IMPLEMENT_ASN1_ALLOC_FUNCTIONS(SCRYPT_PARAMS)
|
||||
IMPLEMENT_ASN1_FUNCTIONS(SCRYPT_PARAMS)
|
||||
|
||||
static X509_ALGOR *pkcs5_scrypt_set(const unsigned char *salt, size_t saltlen,
|
||||
size_t keylen, uint64_t N, uint64_t r,
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2006-2017 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (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
|
||||
*/
|
||||
|
||||
/*
|
||||
* This table MUST be kept in ascending order of the NID each method
|
||||
* represents (corresponding to the pkey_id field) as OBJ_bsearch
|
||||
* is used to search it.
|
||||
*/
|
||||
static const EVP_PKEY_ASN1_METHOD *standard_methods[] = {
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
&rsa_asn1_meths[0],
|
||||
&rsa_asn1_meths[1],
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DH
|
||||
&dh_asn1_meth,
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
&dsa_asn1_meths[0],
|
||||
&dsa_asn1_meths[1],
|
||||
&dsa_asn1_meths[2],
|
||||
&dsa_asn1_meths[3],
|
||||
&dsa_asn1_meths[4],
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_EC
|
||||
&eckey_asn1_meth,
|
||||
#endif
|
||||
&hmac_asn1_meth,
|
||||
#ifndef OPENSSL_NO_CMAC
|
||||
&cmac_asn1_meth,
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
&rsa_pss_asn1_meth,
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DH
|
||||
&dhx_asn1_meth,
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_EC
|
||||
&ecx25519_asn1_meth,
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_POLY1305
|
||||
&poly1305_asn1_meth,
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_SIPHASH
|
||||
&siphash_asn1_meth,
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_EC
|
||||
&ed25519_asn1_meth,
|
||||
#endif
|
||||
};
|
||||
|
||||
+17
-34
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -17,18 +17,9 @@
|
||||
#include "internal/numbers.h"
|
||||
#include "asn1_locl.h"
|
||||
|
||||
/*
|
||||
* Constructed types with a recursive definition (such as can be found in PKCS7)
|
||||
* could eventually exceed the stack given malicious input with excessive
|
||||
* recursion. Therefore we limit the stack depth. This is the maximum number of
|
||||
* recursive invocations of asn1_item_embed_d2i().
|
||||
*/
|
||||
#define ASN1_MAX_CONSTRUCTED_NEST 30
|
||||
|
||||
static int asn1_item_embed_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
||||
long len, const ASN1_ITEM *it,
|
||||
int tag, int aclass, char opt, ASN1_TLC *ctx,
|
||||
int depth);
|
||||
int tag, int aclass, char opt, ASN1_TLC *ctx);
|
||||
|
||||
static int asn1_check_eoc(const unsigned char **in, long len);
|
||||
static int asn1_find_end(const unsigned char **in, long len, char inf);
|
||||
@@ -46,11 +37,11 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass,
|
||||
static int asn1_template_ex_d2i(ASN1_VALUE **pval,
|
||||
const unsigned char **in, long len,
|
||||
const ASN1_TEMPLATE *tt, char opt,
|
||||
ASN1_TLC *ctx, int depth);
|
||||
ASN1_TLC *ctx);
|
||||
static int asn1_template_noexp_d2i(ASN1_VALUE **val,
|
||||
const unsigned char **in, long len,
|
||||
const ASN1_TEMPLATE *tt, char opt,
|
||||
ASN1_TLC *ctx, int depth);
|
||||
ASN1_TLC *ctx);
|
||||
static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
|
||||
const unsigned char **in, long len,
|
||||
const ASN1_ITEM *it,
|
||||
@@ -120,7 +111,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
|
||||
int tag, int aclass, char opt, ASN1_TLC *ctx)
|
||||
{
|
||||
int rv;
|
||||
rv = asn1_item_embed_d2i(pval, in, len, it, tag, aclass, opt, ctx, 0);
|
||||
rv = asn1_item_embed_d2i(pval, in, len, it, tag, aclass, opt, ctx);
|
||||
if (rv <= 0)
|
||||
ASN1_item_ex_free(pval, it);
|
||||
return rv;
|
||||
@@ -133,8 +124,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
|
||||
|
||||
static int asn1_item_embed_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
||||
long len, const ASN1_ITEM *it,
|
||||
int tag, int aclass, char opt, ASN1_TLC *ctx,
|
||||
int depth)
|
||||
int tag, int aclass, char opt, ASN1_TLC *ctx)
|
||||
{
|
||||
const ASN1_TEMPLATE *tt, *errtt = NULL;
|
||||
const ASN1_EXTERN_FUNCS *ef;
|
||||
@@ -155,11 +145,6 @@ static int asn1_item_embed_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
||||
else
|
||||
asn1_cb = 0;
|
||||
|
||||
if (++depth > ASN1_MAX_CONSTRUCTED_NEST) {
|
||||
ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ASN1_R_NESTED_TOO_DEEP);
|
||||
goto err;
|
||||
}
|
||||
|
||||
switch (it->itype) {
|
||||
case ASN1_ITYPE_PRIMITIVE:
|
||||
if (it->templates) {
|
||||
@@ -175,7 +160,7 @@ static int asn1_item_embed_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
||||
goto err;
|
||||
}
|
||||
return asn1_template_ex_d2i(pval, in, len,
|
||||
it->templates, opt, ctx, depth);
|
||||
it->templates, opt, ctx);
|
||||
}
|
||||
return asn1_d2i_ex_primitive(pval, in, len, it,
|
||||
tag, aclass, opt, ctx);
|
||||
@@ -236,7 +221,7 @@ static int asn1_item_embed_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
||||
/*
|
||||
* We mark field as OPTIONAL so its absence can be recognised.
|
||||
*/
|
||||
ret = asn1_template_ex_d2i(pchptr, &p, len, tt, 1, ctx, depth);
|
||||
ret = asn1_template_ex_d2i(pchptr, &p, len, tt, 1, ctx);
|
||||
/* If field not present, try the next one */
|
||||
if (ret == -1)
|
||||
continue;
|
||||
@@ -359,8 +344,7 @@ static int asn1_item_embed_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
||||
* attempt to read in field, allowing each to be OPTIONAL
|
||||
*/
|
||||
|
||||
ret = asn1_template_ex_d2i(pseqval, &p, len, seqtt, isopt, ctx,
|
||||
depth);
|
||||
ret = asn1_template_ex_d2i(pseqval, &p, len, seqtt, isopt, ctx);
|
||||
if (!ret) {
|
||||
errtt = seqtt;
|
||||
goto err;
|
||||
@@ -436,7 +420,7 @@ static int asn1_item_embed_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
||||
static int asn1_template_ex_d2i(ASN1_VALUE **val,
|
||||
const unsigned char **in, long inlen,
|
||||
const ASN1_TEMPLATE *tt, char opt,
|
||||
ASN1_TLC *ctx, int depth)
|
||||
ASN1_TLC *ctx)
|
||||
{
|
||||
int flags, aclass;
|
||||
int ret;
|
||||
@@ -471,7 +455,7 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val,
|
||||
return 0;
|
||||
}
|
||||
/* We've found the field so it can't be OPTIONAL now */
|
||||
ret = asn1_template_noexp_d2i(val, &p, len, tt, 0, ctx, depth);
|
||||
ret = asn1_template_noexp_d2i(val, &p, len, tt, 0, ctx);
|
||||
if (!ret) {
|
||||
ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
|
||||
return 0;
|
||||
@@ -495,7 +479,7 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val,
|
||||
}
|
||||
}
|
||||
} else
|
||||
return asn1_template_noexp_d2i(val, in, inlen, tt, opt, ctx, depth);
|
||||
return asn1_template_noexp_d2i(val, in, inlen, tt, opt, ctx);
|
||||
|
||||
*in = p;
|
||||
return 1;
|
||||
@@ -507,7 +491,7 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val,
|
||||
static int asn1_template_noexp_d2i(ASN1_VALUE **val,
|
||||
const unsigned char **in, long len,
|
||||
const ASN1_TEMPLATE *tt, char opt,
|
||||
ASN1_TLC *ctx, int depth)
|
||||
ASN1_TLC *ctx)
|
||||
{
|
||||
int flags, aclass;
|
||||
int ret;
|
||||
@@ -554,7 +538,7 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val,
|
||||
} else if (ret == -1)
|
||||
return -1;
|
||||
if (!*val)
|
||||
*val = (ASN1_VALUE *)OPENSSL_sk_new_null();
|
||||
*val = (ASN1_VALUE *)sk_ASN1_VALUE_new_null();
|
||||
else {
|
||||
/*
|
||||
* We've got a valid STACK: free up any items present
|
||||
@@ -589,8 +573,7 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val,
|
||||
}
|
||||
skfield = NULL;
|
||||
if (!asn1_item_embed_d2i(&skfield, &p, len,
|
||||
ASN1_ITEM_ptr(tt->item), -1, 0, 0, ctx,
|
||||
depth)) {
|
||||
ASN1_ITEM_ptr(tt->item), -1, 0, 0, ctx)) {
|
||||
ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
|
||||
ERR_R_NESTED_ASN1_ERROR);
|
||||
/* |skfield| may be partially allocated despite failure. */
|
||||
@@ -612,7 +595,7 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val,
|
||||
/* IMPLICIT tagging */
|
||||
ret = asn1_item_embed_d2i(val, &p, len,
|
||||
ASN1_ITEM_ptr(tt->item), tt->tag, aclass, opt,
|
||||
ctx, depth);
|
||||
ctx);
|
||||
if (!ret) {
|
||||
ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ERR_R_NESTED_ASN1_ERROR);
|
||||
goto err;
|
||||
@@ -621,7 +604,7 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val,
|
||||
} else {
|
||||
/* Nothing special */
|
||||
ret = asn1_item_embed_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item),
|
||||
-1, 0, opt, ctx, depth);
|
||||
-1, 0, opt, ctx);
|
||||
if (!ret) {
|
||||
ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ERR_R_NESTED_ASN1_ERROR);
|
||||
goto err;
|
||||
|
||||
@@ -315,7 +315,8 @@ static int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
|
||||
pctx))
|
||||
return 0;
|
||||
}
|
||||
if (!i && BIO_printf(out, "%*s<EMPTY>\n", indent + 2, "") <= 0)
|
||||
if (i == 0 && BIO_printf(out, "%*s<%s>\n", indent + 2, "",
|
||||
stack == NULL ? "ABSENT" : "EMPTY") <= 0)
|
||||
return 0;
|
||||
if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) {
|
||||
if (BIO_printf(out, "%*s}\n", indent, "") <= 0)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2000-2017 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -9,7 +9,8 @@
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <internal/cryptlib.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include "internal/refcount.h"
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/objects.h>
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (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
|
||||
*/
|
||||
|
||||
/* size limits: this stuff is taken straight from RFC3280 */
|
||||
|
||||
#define ub_name 32768
|
||||
#define ub_common_name 64
|
||||
#define ub_locality_name 128
|
||||
#define ub_state_name 128
|
||||
#define ub_organization_name 64
|
||||
#define ub_organization_unit_name 64
|
||||
#define ub_title 64
|
||||
#define ub_email_address 128
|
||||
#define ub_serial_number 64
|
||||
|
||||
/* From RFC4524 */
|
||||
|
||||
#define ub_rfc822_mailbox 256
|
||||
|
||||
/* This table must be kept in NID order */
|
||||
|
||||
static const ASN1_STRING_TABLE tbl_standard[] = {
|
||||
{NID_commonName, 1, ub_common_name, DIRSTRING_TYPE, 0},
|
||||
{NID_countryName, 2, 2, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK},
|
||||
{NID_localityName, 1, ub_locality_name, DIRSTRING_TYPE, 0},
|
||||
{NID_stateOrProvinceName, 1, ub_state_name, DIRSTRING_TYPE, 0},
|
||||
{NID_organizationName, 1, ub_organization_name, DIRSTRING_TYPE, 0},
|
||||
{NID_organizationalUnitName, 1, ub_organization_unit_name, DIRSTRING_TYPE,
|
||||
0},
|
||||
{NID_pkcs9_emailAddress, 1, ub_email_address, B_ASN1_IA5STRING,
|
||||
STABLE_NO_MASK},
|
||||
{NID_pkcs9_unstructuredName, 1, -1, PKCS9STRING_TYPE, 0},
|
||||
{NID_pkcs9_challengePassword, 1, -1, PKCS9STRING_TYPE, 0},
|
||||
{NID_pkcs9_unstructuredAddress, 1, -1, DIRSTRING_TYPE, 0},
|
||||
{NID_givenName, 1, ub_name, DIRSTRING_TYPE, 0},
|
||||
{NID_surname, 1, ub_name, DIRSTRING_TYPE, 0},
|
||||
{NID_initials, 1, ub_name, DIRSTRING_TYPE, 0},
|
||||
{NID_serialNumber, 1, ub_serial_number, B_ASN1_PRINTABLESTRING,
|
||||
STABLE_NO_MASK},
|
||||
{NID_friendlyName, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK},
|
||||
{NID_name, 1, ub_name, DIRSTRING_TYPE, 0},
|
||||
{NID_dnQualifier, -1, -1, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK},
|
||||
{NID_domainComponent, 1, -1, B_ASN1_IA5STRING, STABLE_NO_MASK},
|
||||
{NID_ms_csp_name, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK},
|
||||
{NID_rfc822Mailbox, 1, ub_rfc822_mailbox, B_ASN1_IA5STRING,
|
||||
STABLE_NO_MASK},
|
||||
{NID_jurisdictionCountryName, 2, 2, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK},
|
||||
{NID_INN, 1, 12, B_ASN1_NUMERICSTRING, STABLE_NO_MASK},
|
||||
{NID_OGRN, 1, 13, B_ASN1_NUMERICSTRING, STABLE_NO_MASK},
|
||||
{NID_SNILS, 1, 11, B_ASN1_NUMERICSTRING, STABLE_NO_MASK},
|
||||
{NID_countryCode3c, 3, 3, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK},
|
||||
{NID_countryCode3n, 3, 3, B_ASN1_NUMERICSTRING, STABLE_NO_MASK},
|
||||
{NID_dnsName, 0, -1, B_ASN1_UTF8STRING, STABLE_NO_MASK}
|
||||
};
|
||||
|
||||
@@ -28,18 +28,19 @@ IMPLEMENT_ASN1_DUP_FUNCTION(X509_ALGOR)
|
||||
|
||||
int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype, void *pval)
|
||||
{
|
||||
if (!alg)
|
||||
if (alg == NULL)
|
||||
return 0;
|
||||
|
||||
if (ptype != V_ASN1_UNDEF) {
|
||||
if (alg->parameter == NULL)
|
||||
alg->parameter = ASN1_TYPE_new();
|
||||
if (alg->parameter == NULL)
|
||||
return 0;
|
||||
}
|
||||
if (alg) {
|
||||
ASN1_OBJECT_free(alg->algorithm);
|
||||
alg->algorithm = aobj;
|
||||
}
|
||||
|
||||
ASN1_OBJECT_free(alg->algorithm);
|
||||
alg->algorithm = aobj;
|
||||
|
||||
if (ptype == 0)
|
||||
return 1;
|
||||
if (ptype == V_ASN1_UNDEF) {
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include "internal/asn1t.h"
|
||||
#include "internal/numbers.h"
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/bn.h>
|
||||
#include "asn1_locl.h"
|
||||
|
||||
@@ -102,8 +102,8 @@ static int uint64_print(BIO *out, ASN1_VALUE **pval, const ASN1_ITEM *it,
|
||||
int indent, const ASN1_PCTX *pctx)
|
||||
{
|
||||
if ((it->size & INTxx_FLAG_SIGNED) == INTxx_FLAG_SIGNED)
|
||||
return BIO_printf(out, "%"BIO_PRI64"d\n", **(int64_t **)pval);
|
||||
return BIO_printf(out, "%"BIO_PRI64"u\n", **(uint64_t **)pval);
|
||||
return BIO_printf(out, "%jd\n", **(int64_t **)pval);
|
||||
return BIO_printf(out, "%ju\n", **(uint64_t **)pval);
|
||||
}
|
||||
|
||||
/* 32-bit variants */
|
||||
|
||||
+16
-11
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2000-2017 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -11,6 +11,12 @@
|
||||
#include "internal/cryptlib.h"
|
||||
#include <openssl/asn1t.h>
|
||||
|
||||
#if !(OPENSSL_API_COMPAT < 0x10200000L)
|
||||
NON_EMPTY_TRANSLATION_UNIT
|
||||
#else
|
||||
|
||||
#define COPY_SIZE(a, b) (sizeof(a) < sizeof(b) ? sizeof(a) : sizeof(b))
|
||||
|
||||
/*
|
||||
* Custom primitive type for long handling. This converts between an
|
||||
* ASN1_INTEGER and a long directly.
|
||||
@@ -46,13 +52,13 @@ ASN1_ITEM_end(ZLONG)
|
||||
|
||||
static int long_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
|
||||
{
|
||||
*(long *)pval = it->size;
|
||||
memcpy(pval, &it->size, COPY_SIZE(*pval, it->size));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void long_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
|
||||
{
|
||||
*(long *)pval = it->size;
|
||||
memcpy(pval, &it->size, COPY_SIZE(*pval, it->size));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -86,12 +92,8 @@ static int long_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype,
|
||||
long ltmp;
|
||||
unsigned long utmp, sign;
|
||||
int clen, pad, i;
|
||||
/* this exists to bypass broken gcc optimization */
|
||||
char *cp = (char *)pval;
|
||||
|
||||
/* use memcpy, because we may not be long aligned */
|
||||
memcpy(<mp, cp, sizeof(long));
|
||||
|
||||
memcpy(<mp, pval, COPY_SIZE(*pval, ltmp));
|
||||
if (ltmp == it->size)
|
||||
return -1;
|
||||
/*
|
||||
@@ -133,7 +135,6 @@ static int long_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
|
||||
int i;
|
||||
long ltmp;
|
||||
unsigned long utmp = 0, sign = 0x100;
|
||||
char *cp = (char *)pval;
|
||||
|
||||
if (len > 1) {
|
||||
/*
|
||||
@@ -185,12 +186,16 @@ static int long_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
|
||||
ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG);
|
||||
return 0;
|
||||
}
|
||||
memcpy(cp, <mp, sizeof(long));
|
||||
memcpy(pval, <mp, COPY_SIZE(*pval, ltmp));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int long_print(BIO *out, ASN1_VALUE **pval, const ASN1_ITEM *it,
|
||||
int indent, const ASN1_PCTX *pctx)
|
||||
{
|
||||
return BIO_printf(out, "%ld\n", *(long *)pval);
|
||||
long l;
|
||||
|
||||
memcpy(&l, pval, COPY_SIZE(*pval, l));
|
||||
return BIO_printf(out, "%ld\n", l);
|
||||
}
|
||||
#endif
|
||||
@@ -7,11 +7,6 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* This module was send to me my Pat Richards <patr@x509.com> who wrote it.
|
||||
* It is under my Copyright with his permission
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include <openssl/x509.h>
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
|
||||
# include <ucontext.h>
|
||||
# include <setjmp.h>
|
||||
# include "e_os.h"
|
||||
|
||||
typedef struct async_fibre_st {
|
||||
ucontext_t fibre;
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#include "async_locl.h"
|
||||
|
||||
#include <openssl/err.h>
|
||||
#include <internal/cryptlib_int.h>
|
||||
#include "internal/cryptlib_int.h"
|
||||
#include <string.h>
|
||||
|
||||
#define ASYNC_JOB_RUNNING 0
|
||||
@@ -36,7 +36,7 @@ static async_ctx *async_ctx_new(void)
|
||||
{
|
||||
async_ctx *nctx = NULL;
|
||||
|
||||
nctx = OPENSSL_malloc(sizeof(async_ctx));
|
||||
nctx = OPENSSL_malloc(sizeof(*nctx));
|
||||
if (nctx == NULL) {
|
||||
ASYNCerr(ASYNC_F_ASYNC_CTX_NEW, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
@@ -81,7 +81,7 @@ static ASYNC_JOB *async_job_new(void)
|
||||
{
|
||||
ASYNC_JOB *job = NULL;
|
||||
|
||||
job = OPENSSL_zalloc(sizeof(ASYNC_JOB));
|
||||
job = OPENSSL_zalloc(sizeof(*job));
|
||||
if (job == NULL) {
|
||||
ASYNCerr(ASYNC_F_ASYNC_JOB_NEW, ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
@@ -336,7 +336,7 @@ int ASYNC_init_thread(size_t max_size, size_t init_size)
|
||||
return 0;
|
||||
}
|
||||
|
||||
pool->jobs = sk_ASYNC_JOB_new_null();
|
||||
pool->jobs = sk_ASYNC_JOB_new_reserve(NULL, init_size);
|
||||
if (pool->jobs == NULL) {
|
||||
ASYNCerr(ASYNC_F_ASYNC_INIT_THREAD, ERR_R_MALLOC_FAILURE);
|
||||
OPENSSL_free(pool);
|
||||
@@ -358,7 +358,7 @@ int ASYNC_init_thread(size_t max_size, size_t init_size)
|
||||
break;
|
||||
}
|
||||
job->funcargs = NULL;
|
||||
sk_ASYNC_JOB_push(pool->jobs, job);
|
||||
sk_ASYNC_JOB_push(pool->jobs, job); /* Cannot fail due to reserve */
|
||||
curr_size++;
|
||||
}
|
||||
pool->curr_size = curr_size;
|
||||
|
||||
+20
-22
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Generated by util/mkerr.pl DO NOT EDIT
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -8,31 +8,30 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/async.h>
|
||||
#include <openssl/asyncerr.h>
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
|
||||
# define ERR_FUNC(func) ERR_PACK(ERR_LIB_ASYNC,func,0)
|
||||
# define ERR_REASON(reason) ERR_PACK(ERR_LIB_ASYNC,0,reason)
|
||||
|
||||
static ERR_STRING_DATA ASYNC_str_functs[] = {
|
||||
{ERR_FUNC(ASYNC_F_ASYNC_CTX_NEW), "async_ctx_new"},
|
||||
{ERR_FUNC(ASYNC_F_ASYNC_INIT_THREAD), "ASYNC_init_thread"},
|
||||
{ERR_FUNC(ASYNC_F_ASYNC_JOB_NEW), "async_job_new"},
|
||||
{ERR_FUNC(ASYNC_F_ASYNC_PAUSE_JOB), "ASYNC_pause_job"},
|
||||
{ERR_FUNC(ASYNC_F_ASYNC_START_FUNC), "async_start_func"},
|
||||
{ERR_FUNC(ASYNC_F_ASYNC_START_JOB), "ASYNC_start_job"},
|
||||
static const ERR_STRING_DATA ASYNC_str_functs[] = {
|
||||
{ERR_PACK(ERR_LIB_ASYNC, ASYNC_F_ASYNC_CTX_NEW, 0), "async_ctx_new"},
|
||||
{ERR_PACK(ERR_LIB_ASYNC, ASYNC_F_ASYNC_INIT_THREAD, 0),
|
||||
"ASYNC_init_thread"},
|
||||
{ERR_PACK(ERR_LIB_ASYNC, ASYNC_F_ASYNC_JOB_NEW, 0), "async_job_new"},
|
||||
{ERR_PACK(ERR_LIB_ASYNC, ASYNC_F_ASYNC_PAUSE_JOB, 0), "ASYNC_pause_job"},
|
||||
{ERR_PACK(ERR_LIB_ASYNC, ASYNC_F_ASYNC_START_FUNC, 0), "async_start_func"},
|
||||
{ERR_PACK(ERR_LIB_ASYNC, ASYNC_F_ASYNC_START_JOB, 0), "ASYNC_start_job"},
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
static ERR_STRING_DATA ASYNC_str_reasons[] = {
|
||||
{ERR_REASON(ASYNC_R_FAILED_TO_SET_POOL), "failed to set pool"},
|
||||
{ERR_REASON(ASYNC_R_FAILED_TO_SWAP_CONTEXT), "failed to swap context"},
|
||||
{ERR_REASON(ASYNC_R_INIT_FAILED), "init failed"},
|
||||
{ERR_REASON(ASYNC_R_INVALID_POOL_SIZE), "invalid pool size"},
|
||||
static const ERR_STRING_DATA ASYNC_str_reasons[] = {
|
||||
{ERR_PACK(ERR_LIB_ASYNC, 0, ASYNC_R_FAILED_TO_SET_POOL),
|
||||
"failed to set pool"},
|
||||
{ERR_PACK(ERR_LIB_ASYNC, 0, ASYNC_R_FAILED_TO_SWAP_CONTEXT),
|
||||
"failed to swap context"},
|
||||
{ERR_PACK(ERR_LIB_ASYNC, 0, ASYNC_R_INIT_FAILED), "init failed"},
|
||||
{ERR_PACK(ERR_LIB_ASYNC, 0, ASYNC_R_INVALID_POOL_SIZE),
|
||||
"invalid pool size"},
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
@@ -41,10 +40,9 @@ static ERR_STRING_DATA ASYNC_str_reasons[] = {
|
||||
int ERR_load_ASYNC_strings(void)
|
||||
{
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
|
||||
if (ERR_func_error_string(ASYNC_str_functs[0].error) == NULL) {
|
||||
ERR_load_strings(0, ASYNC_str_functs);
|
||||
ERR_load_strings(0, ASYNC_str_reasons);
|
||||
ERR_load_strings_const(ASYNC_str_functs);
|
||||
ERR_load_strings_const(ASYNC_str_reasons);
|
||||
}
|
||||
#endif
|
||||
return 1;
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <internal/async.h>
|
||||
#include "internal/async.h"
|
||||
#include <openssl/crypto.h>
|
||||
|
||||
typedef struct async_ctx_st async_ctx;
|
||||
|
||||
@@ -145,6 +145,7 @@ int ASYNC_WAIT_CTX_clear_fd(ASYNC_WAIT_CTX *ctx, const void *key)
|
||||
while (curr != NULL) {
|
||||
if (curr->del == 1) {
|
||||
/* This one has been marked deleted already so do nothing */
|
||||
prev = curr;
|
||||
curr = curr->next;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ require "cbc.pl";
|
||||
$output = pop;
|
||||
open STDOUT,">$output";
|
||||
|
||||
&asm_init($ARGV[0],"bf-586.pl",$ARGV[$#ARGV] eq "386");
|
||||
&asm_init($ARGV[0],$ARGV[$#ARGV] eq "386");
|
||||
|
||||
$BF_ROUNDS=16;
|
||||
$BF_OFF=($BF_ROUNDS+2)*4;
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (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 <openssl/blowfish.h>
|
||||
#include "bf_locl.h"
|
||||
|
||||
void BF_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
|
||||
const BF_KEY *schedule, unsigned char *ivec, int encrypt)
|
||||
{
|
||||
register BF_LONG tin0, tin1;
|
||||
register BF_LONG tout0, tout1, xor0, xor1;
|
||||
register long l = length;
|
||||
BF_LONG tin[2];
|
||||
|
||||
if (encrypt) {
|
||||
n2l(ivec, tout0);
|
||||
n2l(ivec, tout1);
|
||||
ivec -= 8;
|
||||
for (l -= 8; l >= 0; l -= 8) {
|
||||
n2l(in, tin0);
|
||||
n2l(in, tin1);
|
||||
tin0 ^= tout0;
|
||||
tin1 ^= tout1;
|
||||
tin[0] = tin0;
|
||||
tin[1] = tin1;
|
||||
BF_encrypt(tin, schedule);
|
||||
tout0 = tin[0];
|
||||
tout1 = tin[1];
|
||||
l2n(tout0, out);
|
||||
l2n(tout1, out);
|
||||
}
|
||||
if (l != -8) {
|
||||
n2ln(in, tin0, tin1, l + 8);
|
||||
tin0 ^= tout0;
|
||||
tin1 ^= tout1;
|
||||
tin[0] = tin0;
|
||||
tin[1] = tin1;
|
||||
BF_encrypt(tin, schedule);
|
||||
tout0 = tin[0];
|
||||
tout1 = tin[1];
|
||||
l2n(tout0, out);
|
||||
l2n(tout1, out);
|
||||
}
|
||||
l2n(tout0, ivec);
|
||||
l2n(tout1, ivec);
|
||||
} else {
|
||||
n2l(ivec, xor0);
|
||||
n2l(ivec, xor1);
|
||||
ivec -= 8;
|
||||
for (l -= 8; l >= 0; l -= 8) {
|
||||
n2l(in, tin0);
|
||||
n2l(in, tin1);
|
||||
tin[0] = tin0;
|
||||
tin[1] = tin1;
|
||||
BF_decrypt(tin, schedule);
|
||||
tout0 = tin[0] ^ xor0;
|
||||
tout1 = tin[1] ^ xor1;
|
||||
l2n(tout0, out);
|
||||
l2n(tout1, out);
|
||||
xor0 = tin0;
|
||||
xor1 = tin1;
|
||||
}
|
||||
if (l != -8) {
|
||||
n2l(in, tin0);
|
||||
n2l(in, tin1);
|
||||
tin[0] = tin0;
|
||||
tin[1] = tin1;
|
||||
BF_decrypt(tin, schedule);
|
||||
tout0 = tin[0] ^ xor0;
|
||||
tout1 = tin[1] ^ xor1;
|
||||
l2nn(tout0, tout1, out, l + 8);
|
||||
xor0 = tin0;
|
||||
xor1 = tin1;
|
||||
}
|
||||
l2n(xor0, ivec);
|
||||
l2n(xor1, ivec);
|
||||
}
|
||||
tin0 = tin1 = tout0 = tout1 = xor0 = xor1 = 0;
|
||||
tin[0] = tin[1] = 0;
|
||||
}
|
||||
+1
-1
@@ -19,7 +19,7 @@
|
||||
|
||||
const char *BF_options(void)
|
||||
{
|
||||
return ("blowfish(ptr)");
|
||||
return "blowfish(ptr)";
|
||||
}
|
||||
|
||||
void BF_ecb_encrypt(const unsigned char *in, unsigned char *out,
|
||||
|
||||
@@ -60,8 +60,6 @@ void BF_encrypt(BF_LONG *data, const BF_KEY *key)
|
||||
data[0] = r & 0xffffffffU;
|
||||
}
|
||||
|
||||
#ifndef BF_DEFAULT_OPTIONS
|
||||
|
||||
void BF_decrypt(BF_LONG *data, const BF_KEY *key)
|
||||
{
|
||||
register BF_LONG l, r;
|
||||
@@ -175,5 +173,3 @@ void BF_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
|
||||
tin0 = tin1 = tout0 = tout1 = xor0 = xor1 = 0;
|
||||
tin[0] = tin[1] = 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -2,5 +2,6 @@ LIBS=../../libcrypto
|
||||
SOURCE[../../libcrypto]=bf_skey.c bf_ecb.c bf_cfb64.c bf_ofb64.c \
|
||||
{- $target{bf_asm_src} -}
|
||||
|
||||
GENERATE[bf-586.s]=asm/bf-586.pl $(PERLASM_SCHEME) $(CFLAGS) $(LIB_CFLAGS) $(PROCESSOR)
|
||||
GENERATE[bf-586.s]=asm/bf-586.pl \
|
||||
$(PERLASM_SCHEME) $(LIB_CFLAGS) $(LIB_CPPFLAGS) $(PROCESSOR)
|
||||
DEPEND[bf-586.s]=../perlasm/x86asm.pl ../perlasm/cbc.pl
|
||||
+31
-19
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -7,6 +7,7 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "bio_lcl.h"
|
||||
@@ -15,8 +16,7 @@
|
||||
#ifndef OPENSSL_NO_SOCK
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/buffer.h>
|
||||
#include <internal/thread_once.h>
|
||||
#include <ctype.h>
|
||||
#include "internal/thread_once.h"
|
||||
|
||||
CRYPTO_RWLOCK *bio_lookup_lock;
|
||||
static CRYPTO_ONCE bio_lookup_init = CRYPTO_ONCE_STATIC_INIT;
|
||||
@@ -565,8 +565,6 @@ static int addrinfo_wrap(int family, int socktype,
|
||||
unsigned short port,
|
||||
BIO_ADDRINFO **bai)
|
||||
{
|
||||
OPENSSL_assert(bai != NULL);
|
||||
|
||||
*bai = OPENSSL_zalloc(sizeof(**bai));
|
||||
if (*bai == NULL)
|
||||
return 0;
|
||||
@@ -609,8 +607,15 @@ DEFINE_RUN_ONCE_STATIC(do_bio_lookup_init)
|
||||
return bio_lookup_lock != NULL;
|
||||
}
|
||||
|
||||
int BIO_lookup(const char *host, const char *service,
|
||||
enum BIO_lookup_type lookup_type,
|
||||
int family, int socktype, BIO_ADDRINFO **res)
|
||||
{
|
||||
return BIO_lookup_ex(host, service, lookup_type, family, socktype, 0, res);
|
||||
}
|
||||
|
||||
/*-
|
||||
* BIO_lookup - look up the node and service you want to connect to.
|
||||
* BIO_lookup_ex - look up the node and service you want to connect to.
|
||||
* @node: the node you want to connect to.
|
||||
* @service: the service you want to connect to.
|
||||
* @lookup_type: declare intent with the result, client or server.
|
||||
@@ -618,6 +623,10 @@ DEFINE_RUN_ONCE_STATIC(do_bio_lookup_init)
|
||||
* AF_INET, AF_INET6 or AF_UNIX.
|
||||
* @socktype: The socket type you want to use. Can be SOCK_STREAM, SOCK_DGRAM
|
||||
* or 0 for all.
|
||||
* @protocol: The protocol to use, e.g. IPPROTO_TCP or IPPROTO_UDP or 0 for all.
|
||||
* Note that some platforms may not return IPPROTO_SCTP without
|
||||
* explicitly requesting it (i.e. IPPROTO_SCTP may not be returned
|
||||
* with 0 for the protocol)
|
||||
* @res: Storage place for the resulting list of returned addresses
|
||||
*
|
||||
* This will do a lookup of the node and service that you want to connect to.
|
||||
@@ -627,9 +636,8 @@ DEFINE_RUN_ONCE_STATIC(do_bio_lookup_init)
|
||||
*
|
||||
* The return value is 1 on success or 0 in case of error.
|
||||
*/
|
||||
int BIO_lookup(const char *host, const char *service,
|
||||
enum BIO_lookup_type lookup_type,
|
||||
int family, int socktype, BIO_ADDRINFO **res)
|
||||
int BIO_lookup_ex(const char *host, const char *service, int lookup_type,
|
||||
int family, int socktype, int protocol, BIO_ADDRINFO **res)
|
||||
{
|
||||
int ret = 0; /* Assume failure */
|
||||
|
||||
@@ -646,7 +654,7 @@ int BIO_lookup(const char *host, const char *service,
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
BIOerr(BIO_F_BIO_LOOKUP, BIO_R_UNSUPPORTED_PROTOCOL_FAMILY);
|
||||
BIOerr(BIO_F_BIO_LOOKUP_EX, BIO_R_UNSUPPORTED_PROTOCOL_FAMILY);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -655,7 +663,7 @@ int BIO_lookup(const char *host, const char *service,
|
||||
if (addrinfo_wrap(family, socktype, host, strlen(host), 0, res))
|
||||
return 1;
|
||||
else
|
||||
BIOerr(BIO_F_BIO_LOOKUP, ERR_R_MALLOC_FAILURE);
|
||||
BIOerr(BIO_F_BIO_LOOKUP_EX, ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@@ -672,6 +680,7 @@ int BIO_lookup(const char *host, const char *service,
|
||||
|
||||
hints.ai_family = family;
|
||||
hints.ai_socktype = socktype;
|
||||
hints.ai_protocol = protocol;
|
||||
|
||||
if (lookup_type == BIO_LOOKUP_SERVER)
|
||||
hints.ai_flags |= AI_PASSIVE;
|
||||
@@ -683,14 +692,14 @@ int BIO_lookup(const char *host, const char *service,
|
||||
# ifdef EAI_SYSTEM
|
||||
case EAI_SYSTEM:
|
||||
SYSerr(SYS_F_GETADDRINFO, get_last_socket_error());
|
||||
BIOerr(BIO_F_BIO_LOOKUP, ERR_R_SYS_LIB);
|
||||
BIOerr(BIO_F_BIO_LOOKUP_EX, ERR_R_SYS_LIB);
|
||||
break;
|
||||
# endif
|
||||
case 0:
|
||||
ret = 1; /* Success */
|
||||
break;
|
||||
default:
|
||||
BIOerr(BIO_F_BIO_LOOKUP, ERR_R_SYS_LIB);
|
||||
BIOerr(BIO_F_BIO_LOOKUP_EX, ERR_R_SYS_LIB);
|
||||
ERR_add_error_data(1, gai_strerror(gai_ret));
|
||||
break;
|
||||
}
|
||||
@@ -732,7 +741,7 @@ int BIO_lookup(const char *host, const char *service,
|
||||
#endif
|
||||
|
||||
if (!RUN_ONCE(&bio_lookup_init, do_bio_lookup_init)) {
|
||||
BIOerr(BIO_F_BIO_LOOKUP, ERR_R_MALLOC_FAILURE);
|
||||
BIOerr(BIO_F_BIO_LOOKUP_EX, ERR_R_MALLOC_FAILURE);
|
||||
ret = 0;
|
||||
goto err;
|
||||
}
|
||||
@@ -749,8 +758,11 @@ int BIO_lookup(const char *host, const char *service,
|
||||
he_fallback_address = INADDR_ANY;
|
||||
break;
|
||||
default:
|
||||
OPENSSL_assert(("We forgot to handle a lookup type!" == 0));
|
||||
break;
|
||||
/* We forgot to handle a lookup type! */
|
||||
assert("We forgot to handle a lookup type!" == NULL);
|
||||
BIOerr(BIO_F_BIO_LOOKUP_EX, ERR_R_INTERNAL_ERROR);
|
||||
ret = 0;
|
||||
goto err;
|
||||
}
|
||||
} else {
|
||||
he = gethostbyname(host);
|
||||
@@ -809,7 +821,7 @@ int BIO_lookup(const char *host, const char *service,
|
||||
|
||||
if (endp != service && *endp == '\0'
|
||||
&& portnum > 0 && portnum < 65536) {
|
||||
se_fallback.s_port = htons(portnum);
|
||||
se_fallback.s_port = htons((unsigned short)portnum);
|
||||
se_fallback.s_proto = proto;
|
||||
se = &se_fallback;
|
||||
} else if (endp == service) {
|
||||
@@ -824,7 +836,7 @@ int BIO_lookup(const char *host, const char *service,
|
||||
goto err;
|
||||
}
|
||||
} else {
|
||||
BIOerr(BIO_F_BIO_LOOKUP, BIO_R_MALFORMED_HOST_OR_SERVICE);
|
||||
BIOerr(BIO_F_BIO_LOOKUP_EX, BIO_R_MALFORMED_HOST_OR_SERVICE);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
@@ -866,7 +878,7 @@ int BIO_lookup(const char *host, const char *service,
|
||||
addrinfo_malloc_err:
|
||||
BIO_ADDRINFO_free(*res);
|
||||
*res = NULL;
|
||||
BIOerr(BIO_F_BIO_LOOKUP, ERR_R_MALLOC_FAILURE);
|
||||
BIOerr(BIO_F_BIO_LOOKUP_EX, ERR_R_MALLOC_FAILURE);
|
||||
ret = 0;
|
||||
goto err;
|
||||
}
|
||||
|
||||
+36
-31
@@ -15,7 +15,9 @@
|
||||
#include "bio_lcl.h"
|
||||
|
||||
#define DUMP_WIDTH 16
|
||||
#define DUMP_WIDTH_LESS_INDENT(i) (DUMP_WIDTH-((i-(i>6?6:i)+3)/4))
|
||||
#define DUMP_WIDTH_LESS_INDENT(i) (DUMP_WIDTH - ((i - (i > 6 ? 6 : i) + 3) / 4))
|
||||
|
||||
#define SPACE(buf, pos, n) (sizeof(buf) - (pos) > (n))
|
||||
|
||||
int BIO_dump_cb(int (*cb) (const void *data, size_t len, void *u),
|
||||
void *u, const char *s, int len)
|
||||
@@ -27,60 +29,63 @@ int BIO_dump_indent_cb(int (*cb) (const void *data, size_t len, void *u),
|
||||
void *u, const char *s, int len, int indent)
|
||||
{
|
||||
int ret = 0;
|
||||
char buf[288 + 1], tmp[20], str[128 + 1];
|
||||
int i, j, rows;
|
||||
char buf[288 + 1];
|
||||
int i, j, rows, n;
|
||||
unsigned char ch;
|
||||
int dump_width;
|
||||
|
||||
if (indent < 0)
|
||||
indent = 0;
|
||||
if (indent) {
|
||||
if (indent > 128)
|
||||
indent = 128;
|
||||
memset(str, ' ', indent);
|
||||
}
|
||||
str[indent] = '\0';
|
||||
else if (indent > 128)
|
||||
indent = 128;
|
||||
|
||||
dump_width = DUMP_WIDTH_LESS_INDENT(indent);
|
||||
rows = (len / dump_width);
|
||||
rows = len / dump_width;
|
||||
if ((rows * dump_width) < len)
|
||||
rows++;
|
||||
for (i = 0; i < rows; i++) {
|
||||
OPENSSL_strlcpy(buf, str, sizeof(buf));
|
||||
BIO_snprintf(tmp, sizeof(tmp), "%04x - ", i * dump_width);
|
||||
OPENSSL_strlcat(buf, tmp, sizeof(buf));
|
||||
n = BIO_snprintf(buf, sizeof(buf), "%*s%04x - ", indent, "",
|
||||
i * dump_width);
|
||||
for (j = 0; j < dump_width; j++) {
|
||||
if (((i * dump_width) + j) >= len) {
|
||||
OPENSSL_strlcat(buf, " ", sizeof(buf));
|
||||
} else {
|
||||
ch = ((unsigned char)*(s + i * dump_width + j)) & 0xff;
|
||||
BIO_snprintf(tmp, sizeof(tmp), "%02x%c", ch,
|
||||
j == 7 ? '-' : ' ');
|
||||
OPENSSL_strlcat(buf, tmp, sizeof(buf));
|
||||
if (SPACE(buf, n, 3)) {
|
||||
if (((i * dump_width) + j) >= len) {
|
||||
strcpy(buf + n, " ");
|
||||
} else {
|
||||
ch = ((unsigned char)*(s + i * dump_width + j)) & 0xff;
|
||||
BIO_snprintf(buf + n, 4, "%02x%c", ch,
|
||||
j == 7 ? '-' : ' ');
|
||||
}
|
||||
n += 3;
|
||||
}
|
||||
}
|
||||
OPENSSL_strlcat(buf, " ", sizeof(buf));
|
||||
if (SPACE(buf, n, 2)) {
|
||||
strcpy(buf + n, " ");
|
||||
n += 2;
|
||||
}
|
||||
for (j = 0; j < dump_width; j++) {
|
||||
if (((i * dump_width) + j) >= len)
|
||||
break;
|
||||
ch = ((unsigned char)*(s + i * dump_width + j)) & 0xff;
|
||||
if (SPACE(buf, n, 1)) {
|
||||
ch = ((unsigned char)*(s + i * dump_width + j)) & 0xff;
|
||||
#ifndef CHARSET_EBCDIC
|
||||
BIO_snprintf(tmp, sizeof(tmp), "%c",
|
||||
((ch >= ' ') && (ch <= '~')) ? ch : '.');
|
||||
buf[n++] = ((ch >= ' ') && (ch <= '~')) ? ch : '.';
|
||||
#else
|
||||
BIO_snprintf(tmp, sizeof(tmp), "%c",
|
||||
((ch >= os_toascii[' ']) && (ch <= os_toascii['~']))
|
||||
? os_toebcdic[ch]
|
||||
: '.');
|
||||
buf[n++] = ((ch >= os_toascii[' ']) && (ch <= os_toascii['~']))
|
||||
? os_toebcdic[ch]
|
||||
: '.';
|
||||
#endif
|
||||
OPENSSL_strlcat(buf, tmp, sizeof(buf));
|
||||
buf[n] = '\0';
|
||||
}
|
||||
}
|
||||
if (SPACE(buf, n, 1)) {
|
||||
buf[n++] = '\n';
|
||||
buf[n] = '\0';
|
||||
}
|
||||
OPENSSL_strlcat(buf, "\n", sizeof(buf));
|
||||
/*
|
||||
* if this is the last call then update the ddt_dump thing so that we
|
||||
* will move the selection point in the debug window
|
||||
*/
|
||||
ret += cb((void *)buf, strlen(buf), u);
|
||||
ret += cb((void *)buf, n, u);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
+44
-41
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include "internal/numbers.h"
|
||||
#include "internal/cryptlib.h"
|
||||
#include "internal/ctype.h"
|
||||
#include "internal/numbers.h"
|
||||
#include <openssl/bio.h>
|
||||
|
||||
/*
|
||||
@@ -69,6 +69,7 @@ static int _dopr(char **sbuffer, char **buffer,
|
||||
#define DP_C_LONG 2
|
||||
#define DP_C_LDOUBLE 3
|
||||
#define DP_C_LLONG 4
|
||||
#define DP_C_SIZE 5
|
||||
|
||||
/* Floating point formats */
|
||||
#define F_FORMAT 0
|
||||
@@ -110,7 +111,7 @@ _dopr(char **sbuffer,
|
||||
if (ch == '%')
|
||||
state = DP_S_FLAGS;
|
||||
else
|
||||
if(!doapr_outch(sbuffer, buffer, &currlen, maxlen, ch))
|
||||
if (!doapr_outch(sbuffer, buffer, &currlen, maxlen, ch))
|
||||
return 0;
|
||||
ch = *format++;
|
||||
break;
|
||||
@@ -142,7 +143,7 @@ _dopr(char **sbuffer,
|
||||
}
|
||||
break;
|
||||
case DP_S_MIN:
|
||||
if (isdigit((unsigned char)ch)) {
|
||||
if (ossl_isdigit(ch)) {
|
||||
min = 10 * min + char_to_int(ch);
|
||||
ch = *format++;
|
||||
} else if (ch == '*') {
|
||||
@@ -160,7 +161,7 @@ _dopr(char **sbuffer,
|
||||
state = DP_S_MOD;
|
||||
break;
|
||||
case DP_S_MAX:
|
||||
if (isdigit((unsigned char)ch)) {
|
||||
if (ossl_isdigit(ch)) {
|
||||
if (max < 0)
|
||||
max = 0;
|
||||
max = 10 * max + char_to_int(ch);
|
||||
@@ -187,6 +188,7 @@ _dopr(char **sbuffer,
|
||||
ch = *format++;
|
||||
break;
|
||||
case 'q':
|
||||
case 'j':
|
||||
cflags = DP_C_LLONG;
|
||||
ch = *format++;
|
||||
break;
|
||||
@@ -194,6 +196,10 @@ _dopr(char **sbuffer,
|
||||
cflags = DP_C_LDOUBLE;
|
||||
ch = *format++;
|
||||
break;
|
||||
case 'z':
|
||||
cflags = DP_C_SIZE;
|
||||
ch = *format++;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -213,6 +219,9 @@ _dopr(char **sbuffer,
|
||||
case DP_C_LLONG:
|
||||
value = va_arg(args, int64_t);
|
||||
break;
|
||||
case DP_C_SIZE:
|
||||
value = va_arg(args, ossl_ssize_t);
|
||||
break;
|
||||
default:
|
||||
value = va_arg(args, int);
|
||||
break;
|
||||
@@ -238,6 +247,9 @@ _dopr(char **sbuffer,
|
||||
case DP_C_LLONG:
|
||||
value = va_arg(args, uint64_t);
|
||||
break;
|
||||
case DP_C_SIZE:
|
||||
value = va_arg(args, size_t);
|
||||
break;
|
||||
default:
|
||||
value = va_arg(args, unsigned int);
|
||||
break;
|
||||
@@ -281,8 +293,8 @@ _dopr(char **sbuffer,
|
||||
return 0;
|
||||
break;
|
||||
case 'c':
|
||||
if(!doapr_outch(sbuffer, buffer, &currlen, maxlen,
|
||||
va_arg(args, int)))
|
||||
if (!doapr_outch(sbuffer, buffer, &currlen, maxlen,
|
||||
va_arg(args, int)))
|
||||
return 0;
|
||||
break;
|
||||
case 's':
|
||||
@@ -303,27 +315,15 @@ _dopr(char **sbuffer,
|
||||
value, 16, min, max, flags | DP_F_NUM))
|
||||
return 0;
|
||||
break;
|
||||
case 'n': /* XXX */
|
||||
if (cflags == DP_C_SHORT) {
|
||||
short int *num;
|
||||
num = va_arg(args, short int *);
|
||||
*num = currlen;
|
||||
} else if (cflags == DP_C_LONG) { /* XXX */
|
||||
long int *num;
|
||||
num = va_arg(args, long int *);
|
||||
*num = (long int)currlen;
|
||||
} else if (cflags == DP_C_LLONG) { /* XXX */
|
||||
int64_t *num;
|
||||
num = va_arg(args, int64_t *);
|
||||
*num = (int64_t)currlen;
|
||||
} else {
|
||||
case 'n':
|
||||
{
|
||||
int *num;
|
||||
num = va_arg(args, int *);
|
||||
*num = currlen;
|
||||
}
|
||||
break;
|
||||
case '%':
|
||||
if(!doapr_outch(sbuffer, buffer, &currlen, maxlen, ch))
|
||||
if (!doapr_outch(sbuffer, buffer, &currlen, maxlen, ch))
|
||||
return 0;
|
||||
break;
|
||||
case 'w':
|
||||
@@ -354,7 +354,7 @@ _dopr(char **sbuffer,
|
||||
if (*truncated)
|
||||
currlen = *maxlen - 1;
|
||||
}
|
||||
if(!doapr_outch(sbuffer, buffer, &currlen, maxlen, '\0'))
|
||||
if (!doapr_outch(sbuffer, buffer, &currlen, maxlen, '\0'))
|
||||
return 0;
|
||||
*retlen = currlen - 1;
|
||||
return 1;
|
||||
@@ -392,19 +392,19 @@ fmtstr(char **sbuffer,
|
||||
padlen = -padlen;
|
||||
|
||||
while ((padlen > 0) && (max < 0 || cnt < max)) {
|
||||
if(!doapr_outch(sbuffer, buffer, currlen, maxlen, ' '))
|
||||
if (!doapr_outch(sbuffer, buffer, currlen, maxlen, ' '))
|
||||
return 0;
|
||||
--padlen;
|
||||
++cnt;
|
||||
}
|
||||
while (strln > 0 && (max < 0 || cnt < max)) {
|
||||
if(!doapr_outch(sbuffer, buffer, currlen, maxlen, *value++))
|
||||
if (!doapr_outch(sbuffer, buffer, currlen, maxlen, *value++))
|
||||
return 0;
|
||||
--strln;
|
||||
++cnt;
|
||||
}
|
||||
while ((padlen < 0) && (max < 0 || cnt < max)) {
|
||||
if(!doapr_outch(sbuffer, buffer, currlen, maxlen, ' '))
|
||||
if (!doapr_outch(sbuffer, buffer, currlen, maxlen, ' '))
|
||||
return 0;
|
||||
++padlen;
|
||||
++cnt;
|
||||
@@ -472,19 +472,19 @@ fmtint(char **sbuffer,
|
||||
|
||||
/* spaces */
|
||||
while (spadlen > 0) {
|
||||
if(!doapr_outch(sbuffer, buffer, currlen, maxlen, ' '))
|
||||
if (!doapr_outch(sbuffer, buffer, currlen, maxlen, ' '))
|
||||
return 0;
|
||||
--spadlen;
|
||||
}
|
||||
|
||||
/* sign */
|
||||
if (signvalue)
|
||||
if(!doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue))
|
||||
if (!doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue))
|
||||
return 0;
|
||||
|
||||
/* prefix */
|
||||
while (*prefix) {
|
||||
if(!doapr_outch(sbuffer, buffer, currlen, maxlen, *prefix))
|
||||
if (!doapr_outch(sbuffer, buffer, currlen, maxlen, *prefix))
|
||||
return 0;
|
||||
prefix++;
|
||||
}
|
||||
@@ -492,7 +492,7 @@ fmtint(char **sbuffer,
|
||||
/* zeros */
|
||||
if (zpadlen > 0) {
|
||||
while (zpadlen > 0) {
|
||||
if(!doapr_outch(sbuffer, buffer, currlen, maxlen, '0'))
|
||||
if (!doapr_outch(sbuffer, buffer, currlen, maxlen, '0'))
|
||||
return 0;
|
||||
--zpadlen;
|
||||
}
|
||||
@@ -758,8 +758,8 @@ fmtfp(char **sbuffer,
|
||||
return 0;
|
||||
|
||||
while (fplace > 0) {
|
||||
if(!doapr_outch(sbuffer, buffer, currlen, maxlen,
|
||||
fconvert[--fplace]))
|
||||
if (!doapr_outch(sbuffer, buffer, currlen, maxlen,
|
||||
fconvert[--fplace]))
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -805,11 +805,13 @@ static int
|
||||
doapr_outch(char **sbuffer,
|
||||
char **buffer, size_t *currlen, size_t *maxlen, int c)
|
||||
{
|
||||
/* If we haven't at least one buffer, someone has doe a big booboo */
|
||||
OPENSSL_assert(*sbuffer != NULL || buffer != NULL);
|
||||
/* If we haven't at least one buffer, someone has done a big booboo */
|
||||
if (!ossl_assert(*sbuffer != NULL || buffer != NULL))
|
||||
return 0;
|
||||
|
||||
/* |currlen| must always be <= |*maxlen| */
|
||||
OPENSSL_assert(*currlen <= *maxlen);
|
||||
if (!ossl_assert(*currlen <= *maxlen))
|
||||
return 0;
|
||||
|
||||
if (buffer && *currlen == *maxlen) {
|
||||
if (*maxlen > INT_MAX - BUFFER_INC)
|
||||
@@ -821,7 +823,8 @@ doapr_outch(char **sbuffer,
|
||||
if (*buffer == NULL)
|
||||
return 0;
|
||||
if (*currlen > 0) {
|
||||
OPENSSL_assert(*sbuffer != NULL);
|
||||
if (!ossl_assert(*sbuffer != NULL))
|
||||
return 0;
|
||||
memcpy(*buffer, *sbuffer, *currlen);
|
||||
}
|
||||
*sbuffer = NULL;
|
||||
@@ -856,7 +859,7 @@ int BIO_printf(BIO *bio, const char *format, ...)
|
||||
ret = BIO_vprintf(bio, format, args);
|
||||
|
||||
va_end(args);
|
||||
return (ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int BIO_vprintf(BIO *bio, const char *format, va_list args)
|
||||
@@ -883,7 +886,7 @@ int BIO_vprintf(BIO *bio, const char *format, va_list args)
|
||||
} else {
|
||||
ret = BIO_write(bio, hugebuf, (int)retlen);
|
||||
}
|
||||
return (ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -902,7 +905,7 @@ int BIO_snprintf(char *buf, size_t n, const char *format, ...)
|
||||
ret = BIO_vsnprintf(buf, n, format, args);
|
||||
|
||||
va_end(args);
|
||||
return (ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args)
|
||||
@@ -910,7 +913,7 @@ int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args)
|
||||
size_t retlen;
|
||||
int truncated;
|
||||
|
||||
if(!_dopr(&buf, NULL, &n, &retlen, &truncated, format, args))
|
||||
if (!_dopr(&buf, NULL, &n, &retlen, &truncated, format, args))
|
||||
return -1;
|
||||
|
||||
if (truncated)
|
||||
|
||||
+15
-24
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -11,10 +11,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include "bio_lcl.h"
|
||||
#if defined(NETWARE_CLIB)
|
||||
# include <sys/ioctl.h>
|
||||
NETDB_DEFINE_CONTEXT
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_SOCK
|
||||
# define SOCKET_PROTOCOL IPPROTO_TCP
|
||||
# ifdef SO_MAXCONN
|
||||
@@ -43,14 +39,13 @@ int BIO_get_host_ip(const char *str, unsigned char *ip)
|
||||
if (BIO_ADDRINFO_family(res) != AF_INET) {
|
||||
BIOerr(BIO_F_BIO_GET_HOST_IP,
|
||||
BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET);
|
||||
} else {
|
||||
BIO_ADDR_rawaddress(BIO_ADDRINFO_address(res), NULL, &l);
|
||||
/* Because only AF_INET addresses will reach this far,
|
||||
we can assert that l should be 4 */
|
||||
OPENSSL_assert(l == 4);
|
||||
|
||||
BIO_ADDR_rawaddress(BIO_ADDRINFO_address(res), ip, &l);
|
||||
ret = 1;
|
||||
} else if (BIO_ADDR_rawaddress(BIO_ADDRINFO_address(res), NULL, &l)) {
|
||||
/*
|
||||
* Because only AF_INET addresses will reach this far, we can assert
|
||||
* that l should be 4
|
||||
*/
|
||||
if (ossl_assert(l == 4))
|
||||
ret = BIO_ADDR_rawaddress(BIO_ADDRINFO_address(res), ip, &l);
|
||||
}
|
||||
BIO_ADDRINFO_free(res);
|
||||
} else {
|
||||
@@ -67,7 +62,7 @@ int BIO_get_port(const char *str, unsigned short *port_ptr)
|
||||
|
||||
if (str == NULL) {
|
||||
BIOerr(BIO_F_BIO_GET_PORT, BIO_R_NO_PORT_DEFINED);
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (BIO_sock_init() != 1)
|
||||
@@ -103,9 +98,9 @@ int BIO_sock_error(int sock)
|
||||
*/
|
||||
i = getsockopt(sock, SOL_SOCKET, SO_ERROR, (void *)&j, &size);
|
||||
if (i < 0)
|
||||
return (get_last_socket_error());
|
||||
return get_last_socket_error();
|
||||
else
|
||||
return (j);
|
||||
return j;
|
||||
}
|
||||
|
||||
# if OPENSSL_API_COMPAT < 0x10100000L
|
||||
@@ -115,11 +110,7 @@ struct hostent *BIO_gethostbyname(const char *name)
|
||||
* Caching gethostbyname() results forever is wrong, so we have to let
|
||||
* the true gethostbyname() worry about this
|
||||
*/
|
||||
# if (defined(NETWARE_BSDSOCK) && !defined(__NOVELL_LIBC__))
|
||||
return gethostbyname((char *)name);
|
||||
# else
|
||||
return gethostbyname(name);
|
||||
# endif
|
||||
}
|
||||
# endif
|
||||
|
||||
@@ -143,7 +134,7 @@ int BIO_sock_init(void)
|
||||
err = WSAGetLastError();
|
||||
SYSerr(SYS_F_WSASTARTUP, err);
|
||||
BIOerr(BIO_F_BIO_SOCK_INIT, BIO_R_WSASTARTUP);
|
||||
return (-1);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
# endif /* OPENSSL_SYS_WINDOWS */
|
||||
@@ -151,10 +142,10 @@ int BIO_sock_init(void)
|
||||
extern int _watt_do_exit;
|
||||
_watt_do_exit = 0; /* don't make sock_init() call exit() */
|
||||
if (sock_init())
|
||||
return (-1);
|
||||
return -1;
|
||||
# endif
|
||||
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void bio_sock_cleanup_int(void)
|
||||
@@ -202,7 +193,7 @@ int BIO_socket_ioctl(int fd, long type, void *arg)
|
||||
# endif /* __DJGPP__ */
|
||||
if (i < 0)
|
||||
SYSerr(SYS_F_IOCTLSOCKET, get_last_socket_error());
|
||||
return (i);
|
||||
return i;
|
||||
}
|
||||
|
||||
# if OPENSSL_API_COMPAT < 0x10100000L
|
||||
|
||||
+63
-25
@@ -76,7 +76,7 @@ int BIO_socket(int domain, int socktype, int protocol, int options)
|
||||
*/
|
||||
int BIO_connect(int sock, const BIO_ADDR *addr, int options)
|
||||
{
|
||||
int on = 1;
|
||||
const int on = 1;
|
||||
|
||||
if (sock == -1) {
|
||||
BIOerr(BIO_F_BIO_CONNECT, BIO_R_INVALID_SOCKET);
|
||||
@@ -87,7 +87,8 @@ int BIO_connect(int sock, const BIO_ADDR *addr, int options)
|
||||
return 0;
|
||||
|
||||
if (options & BIO_SOCK_KEEPALIVE) {
|
||||
if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on)) != 0) {
|
||||
if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE,
|
||||
(const void *)&on, sizeof(on)) != 0) {
|
||||
SYSerr(SYS_F_SETSOCKOPT, get_last_socket_error());
|
||||
BIOerr(BIO_F_BIO_CONNECT, BIO_R_UNABLE_TO_KEEPALIVE);
|
||||
return 0;
|
||||
@@ -95,7 +96,8 @@ int BIO_connect(int sock, const BIO_ADDR *addr, int options)
|
||||
}
|
||||
|
||||
if (options & BIO_SOCK_NODELAY) {
|
||||
if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)) != 0) {
|
||||
if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
|
||||
(const void *)&on, sizeof(on)) != 0) {
|
||||
SYSerr(SYS_F_SETSOCKOPT, get_last_socket_error());
|
||||
BIOerr(BIO_F_BIO_CONNECT, BIO_R_UNABLE_TO_NODELAY);
|
||||
return 0;
|
||||
@@ -113,6 +115,55 @@ int BIO_connect(int sock, const BIO_ADDR *addr, int options)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*-
|
||||
* BIO_bind - bind socket to address
|
||||
* @sock: the socket to set
|
||||
* @addr: local address to bind to
|
||||
* @options: BIO socket options
|
||||
*
|
||||
* Binds to the address using the given socket and options.
|
||||
*
|
||||
* Options can be a combination of the following:
|
||||
* - BIO_SOCK_REUSEADDR: Try to reuse the address and port combination
|
||||
* for a recently closed port.
|
||||
*
|
||||
* When restarting the program it could be that the port is still in use. If
|
||||
* you set to BIO_SOCK_REUSEADDR option it will try to reuse the port anyway.
|
||||
* It's recommended that you use this.
|
||||
*/
|
||||
int BIO_bind(int sock, const BIO_ADDR *addr, int options)
|
||||
{
|
||||
int on = 1;
|
||||
|
||||
if (sock == -1) {
|
||||
BIOerr(BIO_F_BIO_BIND, BIO_R_INVALID_SOCKET);
|
||||
return 0;
|
||||
}
|
||||
|
||||
# ifndef OPENSSL_SYS_WINDOWS
|
||||
/*
|
||||
* SO_REUSEADDR has different behavior on Windows than on
|
||||
* other operating systems, don't set it there.
|
||||
*/
|
||||
if (options & BIO_SOCK_REUSEADDR) {
|
||||
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
|
||||
(const void *)&on, sizeof(on)) != 0) {
|
||||
SYSerr(SYS_F_SETSOCKOPT, get_last_socket_error());
|
||||
BIOerr(BIO_F_BIO_BIND, BIO_R_UNABLE_TO_REUSEADDR);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
if (bind(sock, BIO_ADDR_sockaddr(addr), BIO_ADDR_sockaddr_size(addr)) != 0) {
|
||||
SYSerr(SYS_F_BIND, get_last_socket_error());
|
||||
BIOerr(BIO_F_BIO_BIND, BIO_R_UNABLE_TO_BIND_SOCKET);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*-
|
||||
* BIO_listen - Creates a listen socket
|
||||
* @sock: the socket to listen with
|
||||
@@ -161,7 +212,8 @@ int BIO_listen(int sock, const BIO_ADDR *addr, int options)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (getsockopt(sock, SOL_SOCKET, SO_TYPE, &socktype, &socktype_len) != 0
|
||||
if (getsockopt(sock, SOL_SOCKET, SO_TYPE,
|
||||
(void *)&socktype, &socktype_len) != 0
|
||||
|| socktype_len != sizeof(socktype)) {
|
||||
SYSerr(SYS_F_GETSOCKOPT, get_last_socket_error());
|
||||
BIOerr(BIO_F_BIO_LISTEN, BIO_R_GETTING_SOCKTYPE);
|
||||
@@ -171,22 +223,9 @@ int BIO_listen(int sock, const BIO_ADDR *addr, int options)
|
||||
if (!BIO_socket_nbio(sock, (options & BIO_SOCK_NONBLOCK) != 0))
|
||||
return 0;
|
||||
|
||||
# ifndef OPENSSL_SYS_WINDOWS
|
||||
/*
|
||||
* SO_REUSEADDR has different behavior on Windows than on
|
||||
* other operating systems, don't set it there.
|
||||
*/
|
||||
if (options & BIO_SOCK_REUSEADDR) {
|
||||
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) != 0) {
|
||||
SYSerr(SYS_F_SETSOCKOPT, get_last_socket_error());
|
||||
BIOerr(BIO_F_BIO_LISTEN, BIO_R_UNABLE_TO_REUSEADDR);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
if (options & BIO_SOCK_KEEPALIVE) {
|
||||
if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on)) != 0) {
|
||||
if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE,
|
||||
(const void *)&on, sizeof(on)) != 0) {
|
||||
SYSerr(SYS_F_SETSOCKOPT, get_last_socket_error());
|
||||
BIOerr(BIO_F_BIO_LISTEN, BIO_R_UNABLE_TO_KEEPALIVE);
|
||||
return 0;
|
||||
@@ -194,7 +233,8 @@ int BIO_listen(int sock, const BIO_ADDR *addr, int options)
|
||||
}
|
||||
|
||||
if (options & BIO_SOCK_NODELAY) {
|
||||
if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)) != 0) {
|
||||
if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
|
||||
(const void *)&on, sizeof(on)) != 0) {
|
||||
SYSerr(SYS_F_SETSOCKOPT, get_last_socket_error());
|
||||
BIOerr(BIO_F_BIO_LISTEN, BIO_R_UNABLE_TO_NODELAY);
|
||||
return 0;
|
||||
@@ -208,7 +248,8 @@ int BIO_listen(int sock, const BIO_ADDR *addr, int options)
|
||||
* Therefore we always have to use setsockopt here.
|
||||
*/
|
||||
on = options & BIO_SOCK_V6_ONLY ? 1 : 0;
|
||||
if (setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) != 0) {
|
||||
if (setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY,
|
||||
(const void *)&on, sizeof(on)) != 0) {
|
||||
SYSerr(SYS_F_SETSOCKOPT, get_last_socket_error());
|
||||
BIOerr(BIO_F_BIO_LISTEN, BIO_R_LISTEN_V6_ONLY);
|
||||
return 0;
|
||||
@@ -216,11 +257,8 @@ int BIO_listen(int sock, const BIO_ADDR *addr, int options)
|
||||
}
|
||||
# endif
|
||||
|
||||
if (bind(sock, BIO_ADDR_sockaddr(addr), BIO_ADDR_sockaddr_size(addr)) != 0) {
|
||||
SYSerr(SYS_F_BIND, get_last_socket_error());
|
||||
BIOerr(BIO_F_BIO_LISTEN, BIO_R_UNABLE_TO_BIND_SOCKET);
|
||||
if (!BIO_bind(sock, addr, options))
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (socktype != SOCK_DGRAM && listen(sock, MAX_LISTEN) == -1) {
|
||||
SYSerr(SYS_F_LISTEN, get_last_socket_error());
|
||||
|
||||
+52
-32
@@ -25,7 +25,11 @@ static long buffer_callback_ctrl(BIO *h, int cmd, BIO_info_cb *fp);
|
||||
static const BIO_METHOD methods_buffer = {
|
||||
BIO_TYPE_BUFFER,
|
||||
"buffer",
|
||||
/* TODO: Convert to new style write function */
|
||||
bwrite_conv,
|
||||
buffer_write,
|
||||
/* TODO: Convert to new style read function */
|
||||
bread_conv,
|
||||
buffer_read,
|
||||
buffer_puts,
|
||||
buffer_gets,
|
||||
@@ -37,7 +41,7 @@ static const BIO_METHOD methods_buffer = {
|
||||
|
||||
const BIO_METHOD *BIO_f_buffer(void)
|
||||
{
|
||||
return (&methods_buffer);
|
||||
return &methods_buffer;
|
||||
}
|
||||
|
||||
static int buffer_new(BIO *bi)
|
||||
@@ -45,25 +49,25 @@ static int buffer_new(BIO *bi)
|
||||
BIO_F_BUFFER_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
|
||||
|
||||
if (ctx == NULL)
|
||||
return (0);
|
||||
return 0;
|
||||
ctx->ibuf_size = DEFAULT_BUFFER_SIZE;
|
||||
ctx->ibuf = OPENSSL_malloc(DEFAULT_BUFFER_SIZE);
|
||||
if (ctx->ibuf == NULL) {
|
||||
OPENSSL_free(ctx);
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
ctx->obuf_size = DEFAULT_BUFFER_SIZE;
|
||||
ctx->obuf = OPENSSL_malloc(DEFAULT_BUFFER_SIZE);
|
||||
if (ctx->obuf == NULL) {
|
||||
OPENSSL_free(ctx->ibuf);
|
||||
OPENSSL_free(ctx);
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bi->init = 1;
|
||||
bi->ptr = (char *)ctx;
|
||||
bi->flags = 0;
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int buffer_free(BIO *a)
|
||||
@@ -71,7 +75,7 @@ static int buffer_free(BIO *a)
|
||||
BIO_F_BUFFER_CTX *b;
|
||||
|
||||
if (a == NULL)
|
||||
return (0);
|
||||
return 0;
|
||||
b = (BIO_F_BUFFER_CTX *)a->ptr;
|
||||
OPENSSL_free(b->ibuf);
|
||||
OPENSSL_free(b->obuf);
|
||||
@@ -79,7 +83,7 @@ static int buffer_free(BIO *a)
|
||||
a->ptr = NULL;
|
||||
a->init = 0;
|
||||
a->flags = 0;
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int buffer_read(BIO *b, char *out, int outl)
|
||||
@@ -88,11 +92,11 @@ static int buffer_read(BIO *b, char *out, int outl)
|
||||
BIO_F_BUFFER_CTX *ctx;
|
||||
|
||||
if (out == NULL)
|
||||
return (0);
|
||||
return 0;
|
||||
ctx = (BIO_F_BUFFER_CTX *)b->ptr;
|
||||
|
||||
if ((ctx == NULL) || (b->next_bio == NULL))
|
||||
return (0);
|
||||
return 0;
|
||||
num = 0;
|
||||
BIO_clear_retry_flags(b);
|
||||
|
||||
@@ -107,7 +111,7 @@ static int buffer_read(BIO *b, char *out, int outl)
|
||||
ctx->ibuf_len -= i;
|
||||
num += i;
|
||||
if (outl == i)
|
||||
return (num);
|
||||
return num;
|
||||
outl -= i;
|
||||
out += i;
|
||||
}
|
||||
@@ -126,11 +130,11 @@ static int buffer_read(BIO *b, char *out, int outl)
|
||||
if (i < 0)
|
||||
return ((num > 0) ? num : i);
|
||||
if (i == 0)
|
||||
return (num);
|
||||
return num;
|
||||
}
|
||||
num += i;
|
||||
if (outl == i)
|
||||
return (num);
|
||||
return num;
|
||||
out += i;
|
||||
outl -= i;
|
||||
}
|
||||
@@ -144,7 +148,7 @@ static int buffer_read(BIO *b, char *out, int outl)
|
||||
if (i < 0)
|
||||
return ((num > 0) ? num : i);
|
||||
if (i == 0)
|
||||
return (num);
|
||||
return num;
|
||||
}
|
||||
ctx->ibuf_off = 0;
|
||||
ctx->ibuf_len = i;
|
||||
@@ -159,10 +163,10 @@ static int buffer_write(BIO *b, const char *in, int inl)
|
||||
BIO_F_BUFFER_CTX *ctx;
|
||||
|
||||
if ((in == NULL) || (inl <= 0))
|
||||
return (0);
|
||||
return 0;
|
||||
ctx = (BIO_F_BUFFER_CTX *)b->ptr;
|
||||
if ((ctx == NULL) || (b->next_bio == NULL))
|
||||
return (0);
|
||||
return 0;
|
||||
|
||||
BIO_clear_retry_flags(b);
|
||||
start:
|
||||
@@ -193,7 +197,7 @@ static int buffer_write(BIO *b, const char *in, int inl)
|
||||
if (i < 0)
|
||||
return ((num > 0) ? num : i);
|
||||
if (i == 0)
|
||||
return (num);
|
||||
return num;
|
||||
}
|
||||
ctx->obuf_off += i;
|
||||
ctx->obuf_len -= i;
|
||||
@@ -215,13 +219,13 @@ static int buffer_write(BIO *b, const char *in, int inl)
|
||||
if (i < 0)
|
||||
return ((num > 0) ? num : i);
|
||||
if (i == 0)
|
||||
return (num);
|
||||
return num;
|
||||
}
|
||||
num += i;
|
||||
in += i;
|
||||
inl -= i;
|
||||
if (inl == 0)
|
||||
return (num);
|
||||
return num;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -248,7 +252,12 @@ static long buffer_ctrl(BIO *b, int cmd, long num, void *ptr)
|
||||
ctx->obuf_off = 0;
|
||||
ctx->obuf_len = 0;
|
||||
if (b->next_bio == NULL)
|
||||
return (0);
|
||||
return 0;
|
||||
ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
|
||||
break;
|
||||
case BIO_CTRL_EOF:
|
||||
if (ctx->ibuf_len > 0)
|
||||
return 0;
|
||||
ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
|
||||
break;
|
||||
case BIO_CTRL_INFO:
|
||||
@@ -266,7 +275,7 @@ static long buffer_ctrl(BIO *b, int cmd, long num, void *ptr)
|
||||
ret = (long)ctx->obuf_len;
|
||||
if (ret == 0) {
|
||||
if (b->next_bio == NULL)
|
||||
return (0);
|
||||
return 0;
|
||||
ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
|
||||
}
|
||||
break;
|
||||
@@ -274,7 +283,7 @@ static long buffer_ctrl(BIO *b, int cmd, long num, void *ptr)
|
||||
ret = (long)ctx->ibuf_len;
|
||||
if (ret == 0) {
|
||||
if (b->next_bio == NULL)
|
||||
return (0);
|
||||
return 0;
|
||||
ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
|
||||
}
|
||||
break;
|
||||
@@ -338,7 +347,7 @@ static long buffer_ctrl(BIO *b, int cmd, long num, void *ptr)
|
||||
break;
|
||||
case BIO_C_DO_STATE_MACHINE:
|
||||
if (b->next_bio == NULL)
|
||||
return (0);
|
||||
return 0;
|
||||
BIO_clear_retry_flags(b);
|
||||
ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
|
||||
BIO_copy_next_retry(b);
|
||||
@@ -346,7 +355,7 @@ static long buffer_ctrl(BIO *b, int cmd, long num, void *ptr)
|
||||
|
||||
case BIO_CTRL_FLUSH:
|
||||
if (b->next_bio == NULL)
|
||||
return (0);
|
||||
return 0;
|
||||
if (ctx->obuf_len <= 0) {
|
||||
ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
|
||||
break;
|
||||
@@ -359,7 +368,7 @@ static long buffer_ctrl(BIO *b, int cmd, long num, void *ptr)
|
||||
&(ctx->obuf[ctx->obuf_off]), ctx->obuf_len);
|
||||
BIO_copy_next_retry(b);
|
||||
if (r <= 0)
|
||||
return ((long)r);
|
||||
return (long)r;
|
||||
ctx->obuf_off += r;
|
||||
ctx->obuf_len -= r;
|
||||
} else {
|
||||
@@ -376,16 +385,27 @@ static long buffer_ctrl(BIO *b, int cmd, long num, void *ptr)
|
||||
!BIO_set_write_buffer_size(dbio, ctx->obuf_size))
|
||||
ret = 0;
|
||||
break;
|
||||
case BIO_CTRL_PEEK:
|
||||
/* Ensure there's stuff in the input buffer */
|
||||
{
|
||||
char fake_buf[1];
|
||||
(void)buffer_read(b, fake_buf, 0);
|
||||
}
|
||||
if (num > ctx->ibuf_len)
|
||||
num = ctx->ibuf_len;
|
||||
memcpy(ptr, &(ctx->ibuf[ctx->ibuf_off]), num);
|
||||
ret = num;
|
||||
break;
|
||||
default:
|
||||
if (b->next_bio == NULL)
|
||||
return (0);
|
||||
return 0;
|
||||
ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
|
||||
break;
|
||||
}
|
||||
return (ret);
|
||||
return ret;
|
||||
malloc_error:
|
||||
BIOerr(BIO_F_BUFFER_CTRL, ERR_R_MALLOC_FAILURE);
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static long buffer_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp)
|
||||
@@ -393,13 +413,13 @@ static long buffer_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp)
|
||||
long ret = 1;
|
||||
|
||||
if (b->next_bio == NULL)
|
||||
return (0);
|
||||
return 0;
|
||||
switch (cmd) {
|
||||
default:
|
||||
ret = BIO_callback_ctrl(b->next_bio, cmd, fp);
|
||||
break;
|
||||
}
|
||||
return (ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int buffer_gets(BIO *b, char *buf, int size)
|
||||
@@ -430,7 +450,7 @@ static int buffer_gets(BIO *b, char *buf, int size)
|
||||
ctx->ibuf_off += i;
|
||||
if (flag || size == 0) {
|
||||
*buf = '\0';
|
||||
return (num);
|
||||
return num;
|
||||
}
|
||||
} else { /* read another chunk */
|
||||
|
||||
@@ -441,7 +461,7 @@ static int buffer_gets(BIO *b, char *buf, int size)
|
||||
if (i < 0)
|
||||
return ((num > 0) ? num : i);
|
||||
if (i == 0)
|
||||
return (num);
|
||||
return num;
|
||||
}
|
||||
ctx->ibuf_len = i;
|
||||
ctx->ibuf_off = 0;
|
||||
@@ -451,5 +471,5 @@ static int buffer_gets(BIO *b, char *buf, int size)
|
||||
|
||||
static int buffer_puts(BIO *b, const char *str)
|
||||
{
|
||||
return (buffer_write(b, str, strlen(str)));
|
||||
return buffer_write(b, str, strlen(str));
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user