diff options
Diffstat (limited to '')
-rw-r--r-- | src/lib/libcrypto/modes/gcm128_i386.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/lib/libcrypto/modes/gcm128_i386.c b/src/lib/libcrypto/modes/gcm128_i386.c new file mode 100644 index 0000000000..ac517fdb04 --- /dev/null +++ b/src/lib/libcrypto/modes/gcm128_i386.c | |||
@@ -0,0 +1,56 @@ | |||
1 | /* $OpenBSD: gcm128_i386.c,v 1.1 2025/06/28 12:39:10 jsing Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2025 Joel Sing <jsing@openbsd.org> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | #include "crypto_arch.h" | ||
19 | #include "modes_local.h" | ||
20 | |||
21 | void gcm_init_4bit(u128 Htable[16], uint64_t H[2]); | ||
22 | |||
23 | void gcm_gmult_4bit_mmx(uint64_t Xi[2], const u128 Htable[16]); | ||
24 | void gcm_ghash_4bit_mmx(uint64_t Xi[2], const u128 Htable[16], const uint8_t *inp, | ||
25 | size_t len); | ||
26 | |||
27 | void gcm_gmult_4bit_x86(uint64_t Xi[2], const u128 Htable[16]); | ||
28 | void gcm_ghash_4bit_x86(uint64_t Xi[2], const u128 Htable[16], const uint8_t *inp, | ||
29 | size_t len); | ||
30 | |||
31 | void gcm_init_clmul(u128 Htable[16], const uint64_t Xi[2]); | ||
32 | void gcm_gmult_clmul(uint64_t Xi[2], const u128 Htable[16]); | ||
33 | void gcm_ghash_clmul(uint64_t Xi[2], const u128 Htable[16], const uint8_t *inp, | ||
34 | size_t len); | ||
35 | |||
36 | void | ||
37 | gcm128_init(GCM128_CONTEXT *ctx) | ||
38 | { | ||
39 | if ((crypto_cpu_caps_i386 & CRYPTO_CPU_CAPS_I386_CLMUL) != 0) { | ||
40 | gcm_init_clmul(ctx->Htable, ctx->H.u); | ||
41 | ctx->gmult = gcm_gmult_clmul; | ||
42 | ctx->ghash = gcm_ghash_clmul; | ||
43 | return; | ||
44 | } | ||
45 | |||
46 | if ((crypto_cpu_caps_i386 & CRYPTO_CPU_CAPS_I386_MMX) != 0) { | ||
47 | gcm_init_4bit(ctx->Htable, ctx->H.u); | ||
48 | ctx->gmult = gcm_gmult_4bit_mmx; | ||
49 | ctx->ghash = gcm_ghash_4bit_mmx; | ||
50 | return; | ||
51 | } | ||
52 | |||
53 | gcm_init_4bit(ctx->Htable, ctx->H.u); | ||
54 | ctx->gmult = gcm_gmult_4bit_x86; | ||
55 | ctx->ghash = gcm_ghash_4bit_x86; | ||
56 | } | ||