diff options
Diffstat (limited to '')
-rw-r--r-- | src/lib/libcrypto/modes/modes_local.h | 80 |
1 files changed, 11 insertions, 69 deletions
diff --git a/src/lib/libcrypto/modes/modes_local.h b/src/lib/libcrypto/modes/modes_local.h index 511855f2e0..5c1acfc25f 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.2 2023/07/08 14:55:36 beck Exp $ */ | 1 | /* $OpenBSD: modes_local.h,v 1.7 2025/07/13 06:01:33 jsing 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 | * |
@@ -15,105 +15,47 @@ | |||
15 | __BEGIN_HIDDEN_DECLS | 15 | __BEGIN_HIDDEN_DECLS |
16 | 16 | ||
17 | #if defined(_LP64) | 17 | #if defined(_LP64) |
18 | typedef long i64; | ||
19 | typedef unsigned long u64; | ||
20 | #define U64(C) C##UL | 18 | #define U64(C) C##UL |
21 | #else | 19 | #else |
22 | typedef long long i64; | ||
23 | typedef unsigned long long u64; | ||
24 | #define U64(C) C##ULL | 20 | #define U64(C) C##ULL |
25 | #endif | 21 | #endif |
26 | 22 | ||
27 | typedef unsigned int u32; | ||
28 | typedef unsigned char u8; | ||
29 | |||
30 | #if !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) | ||
31 | #if defined(__GNUC__) && __GNUC__>=2 | ||
32 | # if defined(__x86_64) || defined(__x86_64__) | ||
33 | # define BSWAP8(x) ({ u64 ret=(x); \ | ||
34 | asm ("bswapq %0" \ | ||
35 | : "+r"(ret)); ret; }) | ||
36 | # define BSWAP4(x) ({ u32 ret=(x); \ | ||
37 | asm ("bswapl %0" \ | ||
38 | : "+r"(ret)); ret; }) | ||
39 | # elif (defined(__i386) || defined(__i386__)) | ||
40 | # define BSWAP8(x) ({ u32 lo=(u64)(x)>>32,hi=(x); \ | ||
41 | asm ("bswapl %0; bswapl %1" \ | ||
42 | : "+r"(hi),"+r"(lo)); \ | ||
43 | (u64)hi<<32|lo; }) | ||
44 | # define BSWAP4(x) ({ u32 ret=(x); \ | ||
45 | asm ("bswapl %0" \ | ||
46 | : "+r"(ret)); ret; }) | ||
47 | # elif (defined(__arm__) || defined(__arm)) && !defined(__STRICT_ALIGNMENT) | ||
48 | # define BSWAP8(x) ({ u32 lo=(u64)(x)>>32,hi=(x); \ | ||
49 | asm ("rev %0,%0; rev %1,%1" \ | ||
50 | : "+r"(hi),"+r"(lo)); \ | ||
51 | (u64)hi<<32|lo; }) | ||
52 | # define BSWAP4(x) ({ u32 ret; \ | ||
53 | asm ("rev %0,%1" \ | ||
54 | : "=r"(ret) : "r"((u32)(x))); \ | ||
55 | ret; }) | ||
56 | # endif | ||
57 | #endif | ||
58 | #endif | ||
59 | |||
60 | #if defined(BSWAP4) && !defined(__STRICT_ALIGNMENT) | ||
61 | #define GETU32(p) BSWAP4(*(const u32 *)(p)) | ||
62 | #define PUTU32(p,v) *(u32 *)(p) = BSWAP4(v) | ||
63 | #else | ||
64 | #define GETU32(p) ((u32)(p)[0]<<24|(u32)(p)[1]<<16|(u32)(p)[2]<<8|(u32)(p)[3]) | ||
65 | #define PUTU32(p,v) ((p)[0]=(u8)((v)>>24),(p)[1]=(u8)((v)>>16),(p)[2]=(u8)((v)>>8),(p)[3]=(u8)(v)) | ||
66 | #endif | ||
67 | |||
68 | /* GCM definitions */ | 23 | /* GCM definitions */ |
69 | 24 | ||
70 | typedef struct { | 25 | typedef struct { |
71 | u64 hi, lo; | 26 | uint64_t hi, lo; |
72 | } u128; | 27 | } u128; |
73 | 28 | ||
74 | #ifdef TABLE_BITS | ||
75 | #undef TABLE_BITS | ||
76 | #endif | ||
77 | /* | ||
78 | * Even though permitted values for TABLE_BITS are 8, 4 and 1, it should | ||
79 | * never be set to 8 [or 1]. For further information see gcm128.c. | ||
80 | */ | ||
81 | #define TABLE_BITS 4 | ||
82 | |||
83 | struct gcm128_context { | 29 | struct gcm128_context { |
84 | /* Following 6 names follow names in GCM specification */ | 30 | /* Following 6 names follow names in GCM specification */ |
85 | union { | 31 | union { |
86 | u64 u[2]; | 32 | uint64_t u[2]; |
87 | u32 d[4]; | 33 | uint32_t d[4]; |
88 | u8 c[16]; | 34 | uint8_t c[16]; |
89 | size_t t[16/sizeof(size_t)]; | 35 | size_t t[16/sizeof(size_t)]; |
90 | } Yi, EKi, EK0, len, Xi, H; | 36 | } Yi, EKi, EK0, len, Xi, H; |
91 | /* Relative position of Xi, H and pre-computed Htable is used | 37 | /* Relative position of Xi, H and pre-computed Htable is used |
92 | * in some assembler modules, i.e. don't change the order! */ | 38 | * in some assembler modules, i.e. don't change the order! */ |
93 | #if TABLE_BITS==8 | ||
94 | u128 Htable[256]; | ||
95 | #else | ||
96 | u128 Htable[16]; | 39 | u128 Htable[16]; |
97 | void (*gmult)(u64 Xi[2], const u128 Htable[16]); | 40 | void (*gmult)(uint64_t Xi[2], const u128 Htable[16]); |
98 | void (*ghash)(u64 Xi[2], const u128 Htable[16], const u8 *inp, | 41 | void (*ghash)(uint64_t Xi[2], const u128 Htable[16], const uint8_t *inp, |
99 | size_t len); | 42 | size_t len); |
100 | #endif | ||
101 | unsigned int mres, ares; | 43 | unsigned int mres, ares; |
102 | block128_f block; | 44 | block128_f block; |
103 | void *key; | 45 | void *key; |
104 | }; | 46 | }; |
105 | 47 | ||
106 | struct xts128_context { | 48 | struct xts128_context { |
107 | void *key1, *key2; | 49 | const void *key1, *key2; |
108 | block128_f block1, block2; | 50 | block128_f block1, block2; |
109 | }; | 51 | }; |
110 | 52 | ||
111 | struct ccm128_context { | 53 | struct ccm128_context { |
112 | union { | 54 | union { |
113 | u64 u[2]; | 55 | uint64_t u[2]; |
114 | u8 c[16]; | 56 | uint8_t c[16]; |
115 | } nonce, cmac; | 57 | } nonce, cmac; |
116 | u64 blocks; | 58 | uint64_t blocks; |
117 | block128_f block; | 59 | block128_f block; |
118 | void *key; | 60 | void *key; |
119 | }; | 61 | }; |