summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/modes/modes_local.h
diff options
context:
space:
mode:
authorbeck <>2023-07-08 14:55:36 +0000
committerbeck <>2023-07-08 14:55:36 +0000
commit3c27356c4047c5869d9365e12ad90ccbdbb882ab (patch)
tree8b52e2acda02335df7e6b79862b2a92ae5046a0f /src/lib/libcrypto/modes/modes_local.h
parentcfe8c9ef5ce212d7cb6e1b00c34a8835dd08c925 (diff)
downloadopenbsd-3c27356c4047c5869d9365e12ad90ccbdbb882ab.tar.gz
openbsd-3c27356c4047c5869d9365e12ad90ccbdbb882ab.tar.bz2
openbsd-3c27356c4047c5869d9365e12ad90ccbdbb882ab.zip
Hit modes with the loving mallet of knfmt
ok tb@
Diffstat (limited to 'src/lib/libcrypto/modes/modes_local.h')
-rw-r--r--src/lib/libcrypto/modes/modes_local.h56
1 files changed, 33 insertions, 23 deletions
diff --git a/src/lib/libcrypto/modes/modes_local.h b/src/lib/libcrypto/modes/modes_local.h
index 943f139245..511855f2e0 100644
--- a/src/lib/libcrypto/modes/modes_local.h
+++ b/src/lib/libcrypto/modes/modes_local.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: modes_local.h,v 1.1 2022/11/26 16:08:53 tb Exp $ */ 1/* $OpenBSD: modes_local.h,v 1.2 2023/07/08 14:55:36 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 2010 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 2010 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -30,28 +30,28 @@ typedef unsigned char u8;
30#if !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) 30#if !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM)
31#if defined(__GNUC__) && __GNUC__>=2 31#if defined(__GNUC__) && __GNUC__>=2
32# if defined(__x86_64) || defined(__x86_64__) 32# if defined(__x86_64) || defined(__x86_64__)
33# define BSWAP8(x) ({ u64 ret=(x); \ 33# define BSWAP8(x) ({ u64 ret=(x); \
34 asm ("bswapq %0" \ 34 asm ("bswapq %0" \
35 : "+r"(ret)); ret; }) 35 : "+r"(ret)); ret; })
36# define BSWAP4(x) ({ u32 ret=(x); \ 36# define BSWAP4(x) ({ u32 ret=(x); \
37 asm ("bswapl %0" \ 37 asm ("bswapl %0" \
38 : "+r"(ret)); ret; }) 38 : "+r"(ret)); ret; })
39# elif (defined(__i386) || defined(__i386__)) 39# elif (defined(__i386) || defined(__i386__))
40# define BSWAP8(x) ({ u32 lo=(u64)(x)>>32,hi=(x); \ 40# define BSWAP8(x) ({ u32 lo=(u64)(x)>>32,hi=(x); \
41 asm ("bswapl %0; bswapl %1" \ 41 asm ("bswapl %0; bswapl %1" \
42 : "+r"(hi),"+r"(lo)); \ 42 : "+r"(hi),"+r"(lo)); \
43 (u64)hi<<32|lo; }) 43 (u64)hi<<32|lo; })
44# define BSWAP4(x) ({ u32 ret=(x); \ 44# define BSWAP4(x) ({ u32 ret=(x); \
45 asm ("bswapl %0" \ 45 asm ("bswapl %0" \
46 : "+r"(ret)); ret; }) 46 : "+r"(ret)); ret; })
47# elif (defined(__arm__) || defined(__arm)) && !defined(__STRICT_ALIGNMENT) 47# elif (defined(__arm__) || defined(__arm)) && !defined(__STRICT_ALIGNMENT)
48# define BSWAP8(x) ({ u32 lo=(u64)(x)>>32,hi=(x); \ 48# define BSWAP8(x) ({ u32 lo=(u64)(x)>>32,hi=(x); \
49 asm ("rev %0,%0; rev %1,%1" \ 49 asm ("rev %0,%0; rev %1,%1" \
50 : "+r"(hi),"+r"(lo)); \ 50 : "+r"(hi),"+r"(lo)); \
51 (u64)hi<<32|lo; }) 51 (u64)hi<<32|lo; })
52# define BSWAP4(x) ({ u32 ret; \ 52# define BSWAP4(x) ({ u32 ret; \
53 asm ("rev %0,%1" \ 53 asm ("rev %0,%1" \
54 : "=r"(ret) : "r"((u32)(x))); \ 54 : "=r"(ret) : "r"((u32)(x))); \
55 ret; }) 55 ret; })
56# endif 56# endif
57#endif 57#endif
@@ -67,7 +67,9 @@ typedef unsigned char u8;
67 67
68/* GCM definitions */ 68/* GCM definitions */
69 69
70typedef struct { u64 hi,lo; } u128; 70typedef struct {
71 u64 hi, lo;
72} u128;
71 73
72#ifdef TABLE_BITS 74#ifdef TABLE_BITS
73#undef TABLE_BITS 75#undef TABLE_BITS
@@ -80,16 +82,21 @@ typedef struct { u64 hi,lo; } u128;
80 82
81struct gcm128_context { 83struct gcm128_context {
82 /* Following 6 names follow names in GCM specification */ 84 /* Following 6 names follow names in GCM specification */
83 union { u64 u[2]; u32 d[4]; u8 c[16]; size_t t[16/sizeof(size_t)]; } 85 union {
84 Yi,EKi,EK0,len,Xi,H; 86 u64 u[2];
87 u32 d[4];
88 u8 c[16];
89 size_t t[16/sizeof(size_t)];
90 } Yi, EKi, EK0, len, Xi, H;
85 /* Relative position of Xi, H and pre-computed Htable is used 91 /* Relative position of Xi, H and pre-computed Htable is used
86 * in some assembler modules, i.e. don't change the order! */ 92 * in some assembler modules, i.e. don't change the order! */
87#if TABLE_BITS==8 93#if TABLE_BITS==8
88 u128 Htable[256]; 94 u128 Htable[256];
89#else 95#else
90 u128 Htable[16]; 96 u128 Htable[16];
91 void (*gmult)(u64 Xi[2],const u128 Htable[16]); 97 void (*gmult)(u64 Xi[2], const u128 Htable[16]);
92 void (*ghash)(u64 Xi[2],const u128 Htable[16],const u8 *inp,size_t len); 98 void (*ghash)(u64 Xi[2], const u128 Htable[16], const u8 *inp,
99 size_t len);
93#endif 100#endif
94 unsigned int mres, ares; 101 unsigned int mres, ares;
95 block128_f block; 102 block128_f block;
@@ -98,11 +105,14 @@ struct gcm128_context {
98 105
99struct xts128_context { 106struct xts128_context {
100 void *key1, *key2; 107 void *key1, *key2;
101 block128_f block1,block2; 108 block128_f block1, block2;
102}; 109};
103 110
104struct ccm128_context { 111struct ccm128_context {
105 union { u64 u[2]; u8 c[16]; } nonce, cmac; 112 union {
113 u64 u[2];
114 u8 c[16];
115 } nonce, cmac;
106 u64 blocks; 116 u64 blocks;
107 block128_f block; 117 block128_f block;
108 void *key; 118 void *key;