Latest update.
This commit is contained in:
@@ -40,9 +40,10 @@
|
||||
# [1] http://rt.openssl.org/Ticket/Display.html?id=2900&user=guest&pass=guest
|
||||
# [2] http://www.intel.com/content/dam/www/public/us/en/documents/software-support/enabling-high-performance-gcm.pdf
|
||||
|
||||
$flavour = shift;
|
||||
$output = shift;
|
||||
if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
|
||||
# $output is the last argument if it looks like a file (it has an extension)
|
||||
# $flavour is the first argument if it doesn't look like a file
|
||||
$output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
|
||||
$flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
|
||||
|
||||
$win64=0; $win64=1 if ($flavour =~ /[nm]asm|mingw64/ || $output =~ /\.asm$/);
|
||||
|
||||
@@ -70,7 +71,8 @@ if (!$avx && `$ENV{CC} -v 2>&1` =~ /((?:^clang|LLVM) version|.*based on LLVM) ([
|
||||
$avx = ($2>=3.0) + ($2>3.0);
|
||||
}
|
||||
|
||||
open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\"";
|
||||
open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\""
|
||||
or die "can't call $xlate: $!";
|
||||
*STDOUT=*OUT;
|
||||
|
||||
if ($avx>1) {{{
|
||||
|
||||
@@ -78,9 +78,10 @@
|
||||
# *native* byte order on current platform. See gcm128.c for working
|
||||
# example...
|
||||
|
||||
$flavour = shift;
|
||||
if ($flavour=~/\w[\w\-]*\.\w+$/) { $output=$flavour; undef $flavour; }
|
||||
else { while (($output=shift) && ($output!~/\w[\w\-]*\.\w+$/)) {} }
|
||||
# $output is the last argument if it looks like a file (it has an extension)
|
||||
# $flavour is the first argument if it doesn't look like a file
|
||||
$output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
|
||||
$flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
|
||||
|
||||
if ($flavour && $flavour ne "void") {
|
||||
$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
|
||||
@@ -88,9 +89,10 @@ if ($flavour && $flavour ne "void") {
|
||||
( $xlate="${dir}../../perlasm/arm-xlate.pl" and -f $xlate) or
|
||||
die "can't locate arm-xlate.pl";
|
||||
|
||||
open STDOUT,"| \"$^X\" $xlate $flavour $output";
|
||||
open STDOUT,"| \"$^X\" $xlate $flavour \"$output\""
|
||||
or die "can't call $xlate: $!";
|
||||
} else {
|
||||
open STDOUT,">$output";
|
||||
$output and open STDOUT,">$output";
|
||||
}
|
||||
|
||||
$Xi="r0"; # argument block
|
||||
|
||||
@@ -26,8 +26,7 @@
|
||||
# better, because theoretical [though not necessarily achievable]
|
||||
# estimate for "4-bit" table-driven implementation is ~12 cycles.
|
||||
|
||||
while (($output=shift) && ($output!~/\w[\w\-]*\.\w+$/)) {}
|
||||
open STDOUT,">$output";
|
||||
$output = pop and open STDOUT,">$output";
|
||||
|
||||
($Xip,$Htable,$inp,$len)=("A4","B4","A6","B6"); # arguments
|
||||
|
||||
|
||||
@@ -27,9 +27,12 @@
|
||||
#
|
||||
# Special thanks to polarhome.com for providing HP-UX account.
|
||||
|
||||
$flavour = shift;
|
||||
$output = shift;
|
||||
open STDOUT,">$output";
|
||||
# $output is the last argument if it looks like a file (it has an extension)
|
||||
# $flavour is the first argument if it doesn't look like a file
|
||||
$output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
|
||||
$flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
|
||||
|
||||
$output and open STDOUT,">$output";
|
||||
|
||||
if ($flavour =~ /64/) {
|
||||
$LEVEL ="2.0W";
|
||||
|
||||
@@ -44,7 +44,10 @@
|
||||
# it's actually almost 2 times slower. Which is the reason why
|
||||
# KIMD-GHASH is not used in gcm_gmult_4bit.
|
||||
|
||||
$flavour = shift;
|
||||
# $output is the last argument if it looks like a file (it has an extension)
|
||||
# $flavour is the first argument if it doesn't look like a file
|
||||
$output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
|
||||
$flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
|
||||
|
||||
if ($flavour =~ /3[12]/) {
|
||||
$SIZE_T=4;
|
||||
@@ -54,8 +57,7 @@ if ($flavour =~ /3[12]/) {
|
||||
$g="g";
|
||||
}
|
||||
|
||||
while (($output=shift) && ($output!~/\w[\w\-]*\.\w+$/)) {}
|
||||
open STDOUT,">$output";
|
||||
$output and open STDOUT,">$output";
|
||||
|
||||
$softonly=0;
|
||||
|
||||
|
||||
@@ -53,8 +53,7 @@
|
||||
# saturates at ~15.5x single-process result on 8-core processor,
|
||||
# or ~20.5GBps per 2.85GHz socket.
|
||||
|
||||
$output=pop;
|
||||
open STDOUT,">$output";
|
||||
$output=pop and open STDOUT,">$output";
|
||||
|
||||
$frame="STACK_FRAME";
|
||||
$bias="STACK_BIAS";
|
||||
|
||||
@@ -135,8 +135,7 @@ $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
|
||||
push(@INC,"${dir}","${dir}../../perlasm");
|
||||
require "x86asm.pl";
|
||||
|
||||
$output=pop;
|
||||
open STDOUT,">$output";
|
||||
$output=pop and open STDOUT,">$output";
|
||||
|
||||
&asm_init($ARGV[0],$x86only = $ARGV[$#ARGV] eq "386");
|
||||
|
||||
|
||||
@@ -90,9 +90,10 @@
|
||||
#
|
||||
# [1] http://rt.openssl.org/Ticket/Display.html?id=2900&user=guest&pass=guest
|
||||
|
||||
$flavour = shift;
|
||||
$output = shift;
|
||||
if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
|
||||
# $output is the last argument if it looks like a file (it has an extension)
|
||||
# $flavour is the first argument if it doesn't look like a file
|
||||
$output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
|
||||
$flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
|
||||
|
||||
$win64=0; $win64=1 if ($flavour =~ /[nm]asm|mingw64/ || $output =~ /\.asm$/);
|
||||
|
||||
@@ -120,7 +121,8 @@ if (!$avx && `$ENV{CC} -v 2>&1` =~ /((?:^clang|LLVM) version|.*based on LLVM) ([
|
||||
$avx = ($2>=3.0) + ($2>3.0);
|
||||
}
|
||||
|
||||
open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\"";
|
||||
open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\""
|
||||
or die "can't call $xlate: $!";
|
||||
*STDOUT=*OUT;
|
||||
|
||||
$do4xaggr=1;
|
||||
|
||||
@@ -32,8 +32,10 @@
|
||||
# aggregated reduction - by 170% or 2.7x (resulting in 0.55 cpb).
|
||||
# POWER9 delivers 0.51 cpb.
|
||||
|
||||
$flavour=shift;
|
||||
$output =shift;
|
||||
# $output is the last argument if it looks like a file (it has an extension)
|
||||
# $flavour is the first argument if it doesn't look like a file
|
||||
$output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
|
||||
$flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
|
||||
|
||||
if ($flavour =~ /64/) {
|
||||
$SIZE_T=8;
|
||||
@@ -61,7 +63,8 @@ $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
|
||||
( $xlate="${dir}../../perlasm/ppc-xlate.pl" and -f $xlate) or
|
||||
die "can't locate ppc-xlate.pl";
|
||||
|
||||
open STDOUT,"| $^X $xlate $flavour $output" || die "can't call $xlate: $!";
|
||||
open STDOUT,"| $^X $xlate $flavour \"$output\""
|
||||
or die "can't call $xlate: $!";
|
||||
|
||||
my ($Xip,$Htbl,$inp,$len)=map("r$_",(3..6)); # argument block
|
||||
|
||||
|
||||
@@ -46,15 +46,18 @@
|
||||
#
|
||||
# (*) presented for reference/comparison purposes;
|
||||
|
||||
$flavour = shift;
|
||||
$output = shift;
|
||||
# $output is the last argument if it looks like a file (it has an extension)
|
||||
# $flavour is the first argument if it doesn't look like a file
|
||||
$output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
|
||||
$flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
|
||||
|
||||
$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
|
||||
( $xlate="${dir}arm-xlate.pl" and -f $xlate ) or
|
||||
( $xlate="${dir}../../perlasm/arm-xlate.pl" and -f $xlate) or
|
||||
die "can't locate arm-xlate.pl";
|
||||
|
||||
open OUT,"| \"$^X\" $xlate $flavour $output";
|
||||
open OUT,"| \"$^X\" $xlate $flavour \"$output\""
|
||||
or die "can't call $xlate: $!";
|
||||
*STDOUT=*OUT;
|
||||
|
||||
$Xi="x0"; # argument block
|
||||
|
||||
+16
-15
@@ -48,29 +48,30 @@ IF[{- !$disabled{asm} -}]
|
||||
ENDIF
|
||||
ENDIF
|
||||
|
||||
$COMMON=cbc128.c ctr128.c cfb128.c ofb128.c $MODESASM
|
||||
$COMMON=cbc128.c ctr128.c cfb128.c ofb128.c gcm128.c ccm128.c xts128.c \
|
||||
wrap128.c $MODESASM
|
||||
SOURCE[../../libcrypto]=$COMMON \
|
||||
cts128.c gcm128.c ccm128.c xts128.c wrap128.c ocb128.c siv128.c
|
||||
cts128.c ocb128.c siv128.c
|
||||
|
||||
DEFINE[../../libcrypto]=$MODESDEF
|
||||
SOURCE[../../providers/fips]=$COMMON
|
||||
DEFINE[../../providers/fips]=$MODESDEF
|
||||
|
||||
INCLUDE[gcm128.o]=..
|
||||
|
||||
GENERATE[ghash-ia64.s]=asm/ghash-ia64.pl $(LIB_CFLAGS) $(LIB_CPPFLAGS)
|
||||
GENERATE[ghash-x86.s]=asm/ghash-x86.pl \
|
||||
$(PERLASM_SCHEME) $(LIB_CFLAGS) $(LIB_CPPFLAGS) $(PROCESSOR)
|
||||
GENERATE[ghash-x86_64.s]=asm/ghash-x86_64.pl $(PERLASM_SCHEME)
|
||||
GENERATE[aesni-gcm-x86_64.s]=asm/aesni-gcm-x86_64.pl $(PERLASM_SCHEME)
|
||||
GENERATE[ghash-sparcv9.S]=asm/ghash-sparcv9.pl $(PERLASM_SCHEME)
|
||||
GENERATE[ghash-ia64.s]=asm/ghash-ia64.pl
|
||||
GENERATE[ghash-x86.s]=asm/ghash-x86.pl
|
||||
GENERATE[ghash-x86_64.s]=asm/ghash-x86_64.pl
|
||||
GENERATE[aesni-gcm-x86_64.s]=asm/aesni-gcm-x86_64.pl
|
||||
GENERATE[ghash-sparcv9.S]=asm/ghash-sparcv9.pl
|
||||
INCLUDE[ghash-sparcv9.o]=..
|
||||
GENERATE[ghash-alpha.S]=asm/ghash-alpha.pl $(PERLASM_SCHEME)
|
||||
GENERATE[ghash-parisc.s]=asm/ghash-parisc.pl $(PERLASM_SCHEME)
|
||||
GENERATE[ghashp8-ppc.s]=asm/ghashp8-ppc.pl $(PERLASM_SCHEME)
|
||||
GENERATE[ghash-armv4.S]=asm/ghash-armv4.pl $(PERLASM_SCHEME)
|
||||
GENERATE[ghash-alpha.S]=asm/ghash-alpha.pl
|
||||
GENERATE[ghash-parisc.s]=asm/ghash-parisc.pl
|
||||
GENERATE[ghashp8-ppc.s]=asm/ghashp8-ppc.pl
|
||||
GENERATE[ghash-armv4.S]=asm/ghash-armv4.pl
|
||||
INCLUDE[ghash-armv4.o]=..
|
||||
GENERATE[ghashv8-armx.S]=asm/ghashv8-armx.pl $(PERLASM_SCHEME)
|
||||
GENERATE[ghashv8-armx.S]=asm/ghashv8-armx.pl
|
||||
INCLUDE[ghashv8-armx.o]=..
|
||||
GENERATE[ghash-s390x.S]=asm/ghash-s390x.pl $(PERLASM_SCHEME)
|
||||
GENERATE[ghash-s390x.S]=asm/ghash-s390x.pl
|
||||
INCLUDE[ghash-s390x.o]=..
|
||||
GENERATE[ghash-c64xplus.S]=asm/ghash-c64xplus.pl $(PERLASM_SCHEME)
|
||||
GENERATE[ghash-c64xplus.S]=asm/ghash-c64xplus.pl
|
||||
@@ -7,9 +7,9 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <openssl/crypto.h>
|
||||
#include "modes_lcl.h"
|
||||
#include <string.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include "internal/modes_int.h"
|
||||
|
||||
#if !defined(STRICT_ALIGNMENT) && !defined(PEDANTIC)
|
||||
# define STRICT_ALIGNMENT 0
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <openssl/crypto.h>
|
||||
#include "modes_lcl.h"
|
||||
#include <string.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include "internal/modes_int.h"
|
||||
|
||||
/*
|
||||
* First you setup M and L parameters and pass the key schedule. This is
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <openssl/crypto.h>
|
||||
#include "modes_lcl.h"
|
||||
#include <string.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include "internal/modes_int.h"
|
||||
|
||||
/*
|
||||
* The input and output encrypted as though 128bit cfb mode is being used.
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <openssl/crypto.h>
|
||||
#include "modes_lcl.h"
|
||||
#include <string.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include "internal/modes_int.h"
|
||||
|
||||
/*
|
||||
* NOTE: the IV/counter CTR mode is big-endian. The code itself is
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <openssl/crypto.h>
|
||||
#include "modes_lcl.h"
|
||||
#include <string.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include "internal/modes_int.h"
|
||||
|
||||
/*
|
||||
* Trouble with Ciphertext Stealing, CTS, mode is that there is no
|
||||
|
||||
@@ -7,9 +7,10 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <openssl/crypto.h>
|
||||
#include "modes_lcl.h"
|
||||
#include <string.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include "internal/modes_int.h"
|
||||
|
||||
#if defined(BSWAP4) && defined(STRICT_ALIGNMENT)
|
||||
/* redefine, because alignment is ensured */
|
||||
@@ -635,7 +636,6 @@ static void gcm_gmult_1bit(u64 Xi[2], const u64 H[2])
|
||||
defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64))
|
||||
# define GHASH_ASM_X86_OR_64
|
||||
# define GCM_FUNCREF_4BIT
|
||||
extern unsigned int OPENSSL_ia32cap_P[];
|
||||
|
||||
void gcm_init_clmul(u128 Htable[16], const u64 Xi[2]);
|
||||
void gcm_gmult_clmul(u64 Xi[2], const u128 Htable[16]);
|
||||
|
||||
@@ -1,220 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <openssl/modes.h>
|
||||
|
||||
#if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__)
|
||||
typedef __int64 i64;
|
||||
typedef unsigned __int64 u64;
|
||||
# define U64(C) C##UI64
|
||||
#elif defined(__arch64__)
|
||||
typedef long i64;
|
||||
typedef unsigned long u64;
|
||||
# define U64(C) C##UL
|
||||
#else
|
||||
typedef long long i64;
|
||||
typedef unsigned long long u64;
|
||||
# define U64(C) C##ULL
|
||||
#endif
|
||||
|
||||
typedef unsigned int u32;
|
||||
typedef unsigned char u8;
|
||||
|
||||
#define STRICT_ALIGNMENT 1
|
||||
#ifndef PEDANTIC
|
||||
# if defined(__i386) || defined(__i386__) || \
|
||||
defined(__x86_64) || defined(__x86_64__) || \
|
||||
defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64) || \
|
||||
defined(__aarch64__) || \
|
||||
defined(__s390__) || defined(__s390x__)
|
||||
# undef STRICT_ALIGNMENT
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined(PEDANTIC) && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM)
|
||||
# if defined(__GNUC__) && __GNUC__>=2
|
||||
# if defined(__x86_64) || defined(__x86_64__)
|
||||
# define BSWAP8(x) ({ u64 ret_=(x); \
|
||||
asm ("bswapq %0" \
|
||||
: "+r"(ret_)); ret_; })
|
||||
# define BSWAP4(x) ({ u32 ret_=(x); \
|
||||
asm ("bswapl %0" \
|
||||
: "+r"(ret_)); ret_; })
|
||||
# elif (defined(__i386) || defined(__i386__)) && !defined(I386_ONLY)
|
||||
# define BSWAP8(x) ({ u32 lo_=(u64)(x)>>32,hi_=(x); \
|
||||
asm ("bswapl %0; bswapl %1" \
|
||||
: "+r"(hi_),"+r"(lo_)); \
|
||||
(u64)hi_<<32|lo_; })
|
||||
# define BSWAP4(x) ({ u32 ret_=(x); \
|
||||
asm ("bswapl %0" \
|
||||
: "+r"(ret_)); ret_; })
|
||||
# elif defined(__aarch64__)
|
||||
# define BSWAP8(x) ({ u64 ret_; \
|
||||
asm ("rev %0,%1" \
|
||||
: "=r"(ret_) : "r"(x)); ret_; })
|
||||
# define BSWAP4(x) ({ u32 ret_; \
|
||||
asm ("rev %w0,%w1" \
|
||||
: "=r"(ret_) : "r"(x)); ret_; })
|
||||
# elif (defined(__arm__) || defined(__arm)) && !defined(STRICT_ALIGNMENT)
|
||||
# define BSWAP8(x) ({ u32 lo_=(u64)(x)>>32,hi_=(x); \
|
||||
asm ("rev %0,%0; rev %1,%1" \
|
||||
: "+r"(hi_),"+r"(lo_)); \
|
||||
(u64)hi_<<32|lo_; })
|
||||
# define BSWAP4(x) ({ u32 ret_; \
|
||||
asm ("rev %0,%1" \
|
||||
: "=r"(ret_) : "r"((u32)(x))); \
|
||||
ret_; })
|
||||
# endif
|
||||
# elif defined(_MSC_VER)
|
||||
# if _MSC_VER>=1300
|
||||
# include <stdlib.h>
|
||||
# pragma intrinsic(_byteswap_uint64,_byteswap_ulong)
|
||||
# define BSWAP8(x) _byteswap_uint64((u64)(x))
|
||||
# define BSWAP4(x) _byteswap_ulong((u32)(x))
|
||||
# elif defined(_M_IX86)
|
||||
__inline u32 _bswap4(u32 val)
|
||||
{
|
||||
_asm mov eax, val _asm bswap eax}
|
||||
# define BSWAP4(x) _bswap4(x)
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
#if defined(BSWAP4) && !defined(STRICT_ALIGNMENT)
|
||||
# define GETU32(p) BSWAP4(*(const u32 *)(p))
|
||||
# define PUTU32(p,v) *(u32 *)(p) = BSWAP4(v)
|
||||
#else
|
||||
# define GETU32(p) ((u32)(p)[0]<<24|(u32)(p)[1]<<16|(u32)(p)[2]<<8|(u32)(p)[3])
|
||||
# define PUTU32(p,v) ((p)[0]=(u8)((v)>>24),(p)[1]=(u8)((v)>>16),(p)[2]=(u8)((v)>>8),(p)[3]=(u8)(v))
|
||||
#endif
|
||||
/*- GCM definitions */ typedef struct {
|
||||
u64 hi, lo;
|
||||
} u128;
|
||||
|
||||
#ifdef TABLE_BITS
|
||||
# undef TABLE_BITS
|
||||
#endif
|
||||
/*
|
||||
* Even though permitted values for TABLE_BITS are 8, 4 and 1, it should
|
||||
* never be set to 8 [or 1]. For further information see gcm128.c.
|
||||
*/
|
||||
#define TABLE_BITS 4
|
||||
|
||||
struct gcm128_context {
|
||||
/* Following 6 names follow names in GCM specification */
|
||||
union {
|
||||
u64 u[2];
|
||||
u32 d[4];
|
||||
u8 c[16];
|
||||
size_t t[16 / sizeof(size_t)];
|
||||
} Yi, EKi, EK0, len, Xi, H;
|
||||
/*
|
||||
* Relative position of Xi, H and pre-computed Htable is used in some
|
||||
* assembler modules, i.e. don't change the order!
|
||||
*/
|
||||
#if TABLE_BITS==8
|
||||
u128 Htable[256];
|
||||
#else
|
||||
u128 Htable[16];
|
||||
void (*gmult) (u64 Xi[2], const u128 Htable[16]);
|
||||
void (*ghash) (u64 Xi[2], const u128 Htable[16], const u8 *inp,
|
||||
size_t len);
|
||||
#endif
|
||||
unsigned int mres, ares;
|
||||
block128_f block;
|
||||
void *key;
|
||||
#if !defined(OPENSSL_SMALL_FOOTPRINT)
|
||||
unsigned char Xn[48];
|
||||
#endif
|
||||
};
|
||||
|
||||
/*
|
||||
* The maximum permitted number of cipher blocks per data unit in XTS mode.
|
||||
* Reference IEEE Std 1619-2018.
|
||||
*/
|
||||
#define XTS_MAX_BLOCKS_PER_DATA_UNIT (1<<20)
|
||||
|
||||
struct xts128_context {
|
||||
void *key1, *key2;
|
||||
block128_f block1, block2;
|
||||
};
|
||||
|
||||
struct ccm128_context {
|
||||
union {
|
||||
u64 u[2];
|
||||
u8 c[16];
|
||||
} nonce, cmac;
|
||||
u64 blocks;
|
||||
block128_f block;
|
||||
void *key;
|
||||
};
|
||||
|
||||
#ifndef OPENSSL_NO_OCB
|
||||
|
||||
typedef union {
|
||||
u64 a[2];
|
||||
unsigned char c[16];
|
||||
} OCB_BLOCK;
|
||||
# define ocb_block16_xor(in1,in2,out) \
|
||||
( (out)->a[0]=(in1)->a[0]^(in2)->a[0], \
|
||||
(out)->a[1]=(in1)->a[1]^(in2)->a[1] )
|
||||
# if STRICT_ALIGNMENT
|
||||
# define ocb_block16_xor_misaligned(in1,in2,out) \
|
||||
ocb_block_xor((in1)->c,(in2)->c,16,(out)->c)
|
||||
# else
|
||||
# define ocb_block16_xor_misaligned ocb_block16_xor
|
||||
# endif
|
||||
|
||||
struct ocb128_context {
|
||||
/* Need both encrypt and decrypt key schedules for decryption */
|
||||
block128_f encrypt;
|
||||
block128_f decrypt;
|
||||
void *keyenc;
|
||||
void *keydec;
|
||||
ocb128_f stream; /* direction dependent */
|
||||
/* Key dependent variables. Can be reused if key remains the same */
|
||||
size_t l_index;
|
||||
size_t max_l_index;
|
||||
OCB_BLOCK l_star;
|
||||
OCB_BLOCK l_dollar;
|
||||
OCB_BLOCK *l;
|
||||
/* Must be reset for each session */
|
||||
struct {
|
||||
u64 blocks_hashed;
|
||||
u64 blocks_processed;
|
||||
OCB_BLOCK offset_aad;
|
||||
OCB_BLOCK sum;
|
||||
OCB_BLOCK offset;
|
||||
OCB_BLOCK checksum;
|
||||
} sess;
|
||||
};
|
||||
#endif /* OPENSSL_NO_OCB */
|
||||
|
||||
#ifndef OPENSSL_NO_SIV
|
||||
|
||||
#include <openssl/cmac.h>
|
||||
|
||||
#define SIV_LEN 16
|
||||
|
||||
typedef union siv_block_u {
|
||||
uint64_t word[SIV_LEN/sizeof(uint64_t)];
|
||||
unsigned char byte[SIV_LEN];
|
||||
} SIV_BLOCK;
|
||||
|
||||
struct siv128_context {
|
||||
/* d stores intermediate results of S2V; it corresponds to D from the
|
||||
pseudocode in section 2.4 of RFC 5297. */
|
||||
SIV_BLOCK d;
|
||||
SIV_BLOCK tag;
|
||||
EVP_CIPHER_CTX *cipher_ctx;
|
||||
EVP_MAC_CTX *mac_ctx_init;
|
||||
int final_ret;
|
||||
int crypto_ok;
|
||||
};
|
||||
|
||||
#endif /* OPENSSL_NO_SIV */
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <string.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/err.h>
|
||||
#include "modes_lcl.h"
|
||||
#include "internal/modes_int.h"
|
||||
|
||||
#ifndef OPENSSL_NO_OCB
|
||||
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <openssl/crypto.h>
|
||||
#include "modes_lcl.h"
|
||||
#include <string.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include "internal/modes_int.h"
|
||||
|
||||
/*
|
||||
* The input and output encrypted as though 128bit ofb mode is being used.
|
||||
|
||||
+26
-9
@@ -10,8 +10,11 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/core_names.h>
|
||||
#include <openssl/params.h>
|
||||
#include "internal/modes_int.h"
|
||||
#include "modes_lcl.h"
|
||||
#include "internal/siv_int.h"
|
||||
|
||||
#ifndef OPENSSL_NO_SIV
|
||||
|
||||
@@ -116,7 +119,7 @@ __owur static ossl_inline int siv128_do_s2v_p(SIV128_CONTEXT *ctx, SIV_BLOCK *ou
|
||||
if (!EVP_MAC_update(mac_ctx, t.byte, SIV_LEN))
|
||||
goto err;
|
||||
}
|
||||
if (!EVP_MAC_final(mac_ctx, out->byte, &out_len)
|
||||
if (!EVP_MAC_final(mac_ctx, out->byte, &out_len, sizeof(out->byte))
|
||||
|| out_len != SIV_LEN)
|
||||
goto err;
|
||||
|
||||
@@ -166,6 +169,14 @@ int CRYPTO_siv128_init(SIV128_CONTEXT *ctx, const unsigned char *key, int klen,
|
||||
static const unsigned char zero[SIV_LEN] = { 0 };
|
||||
size_t out_len = SIV_LEN;
|
||||
EVP_MAC_CTX *mac_ctx = NULL;
|
||||
OSSL_PARAM params[3];
|
||||
const char *cbc_name = EVP_CIPHER_name(cbc);
|
||||
|
||||
params[0] = OSSL_PARAM_construct_utf8_string(OSSL_MAC_PARAM_CIPHER,
|
||||
(char *)cbc_name, 0);
|
||||
params[1] = OSSL_PARAM_construct_octet_string(OSSL_MAC_PARAM_KEY,
|
||||
(void *)key, klen);
|
||||
params[2] = OSSL_PARAM_construct_end();
|
||||
|
||||
memset(&ctx->d, 0, sizeof(ctx->d));
|
||||
ctx->cipher_ctx = NULL;
|
||||
@@ -173,16 +184,20 @@ int CRYPTO_siv128_init(SIV128_CONTEXT *ctx, const unsigned char *key, int klen,
|
||||
|
||||
if (key == NULL || cbc == NULL || ctr == NULL
|
||||
|| (ctx->cipher_ctx = EVP_CIPHER_CTX_new()) == NULL
|
||||
|| (ctx->mac_ctx_init = EVP_MAC_CTX_new_id(EVP_MAC_CMAC)) == NULL
|
||||
|| EVP_MAC_ctrl(ctx->mac_ctx_init, EVP_MAC_CTRL_SET_CIPHER, cbc) <= 0
|
||||
|| EVP_MAC_ctrl(ctx->mac_ctx_init, EVP_MAC_CTRL_SET_KEY, key, klen) <= 0
|
||||
/* TODO(3.0) library context */
|
||||
|| (ctx->mac =
|
||||
EVP_MAC_fetch(NULL, OSSL_MAC_NAME_CMAC, NULL)) == NULL
|
||||
|| (ctx->mac_ctx_init = EVP_MAC_CTX_new(ctx->mac)) == NULL
|
||||
|| !EVP_MAC_CTX_set_params(ctx->mac_ctx_init, params)
|
||||
|| !EVP_EncryptInit_ex(ctx->cipher_ctx, ctr, NULL, key + klen, NULL)
|
||||
|| (mac_ctx = EVP_MAC_CTX_dup(ctx->mac_ctx_init)) == NULL
|
||||
|| !EVP_MAC_update(mac_ctx, zero, sizeof(zero))
|
||||
|| !EVP_MAC_final(mac_ctx, ctx->d.byte, &out_len)) {
|
||||
|| !EVP_MAC_final(mac_ctx, ctx->d.byte, &out_len,
|
||||
sizeof(ctx->d.byte))) {
|
||||
EVP_CIPHER_CTX_free(ctx->cipher_ctx);
|
||||
EVP_MAC_CTX_free(ctx->mac_ctx_init);
|
||||
EVP_MAC_CTX_free(mac_ctx);
|
||||
EVP_MAC_free(ctx->mac);
|
||||
return 0;
|
||||
}
|
||||
EVP_MAC_CTX_free(mac_ctx);
|
||||
@@ -222,10 +237,10 @@ int CRYPTO_siv128_aad(SIV128_CONTEXT *ctx, const unsigned char *aad,
|
||||
|
||||
siv128_dbl(&ctx->d);
|
||||
|
||||
mac_ctx = EVP_MAC_CTX_dup(ctx->mac_ctx_init);
|
||||
if (mac_ctx == NULL
|
||||
if ((mac_ctx = EVP_MAC_CTX_dup(ctx->mac_ctx_init)) == NULL
|
||||
|| !EVP_MAC_update(mac_ctx, aad, len)
|
||||
|| !EVP_MAC_final(mac_ctx, mac_out.byte, &out_len)
|
||||
|| !EVP_MAC_final(mac_ctx, mac_out.byte, &out_len,
|
||||
sizeof(mac_out.byte))
|
||||
|| out_len != SIV_LEN) {
|
||||
EVP_MAC_CTX_free(mac_ctx);
|
||||
return 0;
|
||||
@@ -344,6 +359,8 @@ int CRYPTO_siv128_cleanup(SIV128_CONTEXT *ctx)
|
||||
ctx->cipher_ctx = NULL;
|
||||
EVP_MAC_CTX_free(ctx->mac_ctx_init);
|
||||
ctx->mac_ctx_init = NULL;
|
||||
EVP_MAC_free(ctx->mac);
|
||||
ctx->mac = NULL;
|
||||
OPENSSL_cleanse(&ctx->d, sizeof(ctx->d));
|
||||
OPENSSL_cleanse(&ctx->tag, sizeof(ctx->tag));
|
||||
ctx->final_ret = -1;
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <openssl/crypto.h>
|
||||
#include "modes_lcl.h"
|
||||
#include <string.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include "internal/modes_int.h"
|
||||
|
||||
int CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx,
|
||||
const unsigned char iv[16],
|
||||
|
||||
Reference in New Issue
Block a user