]>
Commit | Line | Data |
---|---|---|
1308e022 | 1 | /* |
3c2bdd7d | 2 | * Copyright 2017-2021 The OpenSSL Project Authors. All Rights Reserved. |
1308e022 | 3 | * Copyright 2015 Cryptography Research, Inc. |
7324473f | 4 | * |
a7f182b7 | 5 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
1308e022 MC |
6 | * this file except in compliance with the License. You can obtain a copy |
7 | * in the file LICENSE in the source distribution or at | |
8 | * https://www.openssl.org/source/license.html | |
7324473f | 9 | * |
1308e022 | 10 | * Originally written by Mike Hamburg |
7324473f MC |
11 | */ |
12 | ||
ae4186b0 DMSP |
13 | #ifndef OSSL_CRYPTO_EC_CURVE448UTILS_H |
14 | # define OSSL_CRYPTO_EC_CURVE448UTILS_H | |
7324473f | 15 | |
205fd638 | 16 | # include <openssl/e_os2.h> |
7324473f | 17 | |
5de32f22 AI |
18 | # include "internal/numbers.h" |
19 | ||
205fd638 MC |
20 | /* |
21 | * Internal word types. Somewhat tricky. This could be decided separately per | |
22 | * platform. However, the structs do need to be all the same size and | |
23 | * alignment on a given platform to support dynamic linking, since even if you | |
24 | * header was built with eg arch_neon, you might end up linking a library built | |
25 | * with arch_arm32. | |
7324473f | 26 | */ |
aeeef83c | 27 | # ifndef C448_WORD_BITS |
ae1ffe0f | 28 | # if (defined(__SIZEOF_INT128__) && (__SIZEOF_INT128__ == 16)) \ |
3a86f1db SL |
29 | && !defined(__sparc__) \ |
30 | && (!defined(__SIZEOF_LONG__) || (__SIZEOF_LONG__ == 8)) | |
31 | ||
aeeef83c | 32 | # define C448_WORD_BITS 64 /* The number of bits in a word */ |
205fd638 | 33 | # else |
aeeef83c | 34 | # define C448_WORD_BITS 32 /* The number of bits in a word */ |
205fd638 MC |
35 | # endif |
36 | # endif | |
37 | ||
aeeef83c | 38 | # if C448_WORD_BITS == 64 |
8d55f844 | 39 | /* Word size for internal computations */ |
aeeef83c | 40 | typedef uint64_t c448_word_t; |
8d55f844 | 41 | /* Signed word size for internal computations */ |
aeeef83c | 42 | typedef int64_t c448_sword_t; |
8d55f844 | 43 | /* "Boolean" type, will be set to all-zero or all-one (i.e. -1u) */ |
aeeef83c | 44 | typedef uint64_t c448_bool_t; |
8d55f844 | 45 | /* Double-word size for internal computations */ |
5de32f22 | 46 | typedef uint128_t c448_dword_t; |
8d55f844 | 47 | /* Signed double-word size for internal computations */ |
5de32f22 | 48 | typedef int128_t c448_dsword_t; |
aeeef83c | 49 | # elif C448_WORD_BITS == 32 |
8d55f844 | 50 | /* Word size for internal computations */ |
aeeef83c | 51 | typedef uint32_t c448_word_t; |
8d55f844 | 52 | /* Signed word size for internal computations */ |
aeeef83c | 53 | typedef int32_t c448_sword_t; |
8d55f844 | 54 | /* "Boolean" type, will be set to all-zero or all-one (i.e. -1u) */ |
aeeef83c | 55 | typedef uint32_t c448_bool_t; |
8d55f844 | 56 | /* Double-word size for internal computations */ |
aeeef83c | 57 | typedef uint64_t c448_dword_t; |
8d55f844 | 58 | /* Signed double-word size for internal computations */ |
aeeef83c | 59 | typedef int64_t c448_dsword_t; |
205fd638 | 60 | # else |
aeeef83c | 61 | # error "Only supporting C448_WORD_BITS = 32 or 64 for now" |
205fd638 MC |
62 | # endif |
63 | ||
aeeef83c | 64 | /* C448_TRUE = -1 so that C448_TRUE & x = x */ |
68b20c00 | 65 | # define C448_TRUE (0 - (c448_bool_t)1) |
7324473f | 66 | |
aeeef83c | 67 | /* C448_FALSE = 0 so that C448_FALSE & x = 0 */ |
68b20c00 | 68 | # define C448_FALSE 0 |
7324473f | 69 | |
8d55f844 | 70 | /* Another boolean type used to indicate success or failure. */ |
7324473f | 71 | typedef enum { |
aeeef83c MC |
72 | C448_SUCCESS = -1, /**< The operation succeeded. */ |
73 | C448_FAILURE = 0 /**< The operation failed. */ | |
74 | } c448_error_t; | |
7324473f | 75 | |
8d55f844 | 76 | /* Return success if x is true */ |
aeeef83c | 77 | static ossl_inline c448_error_t c448_succeed_if(c448_bool_t x) |
205fd638 | 78 | { |
aeeef83c | 79 | return (c448_error_t) x; |
7324473f MC |
80 | } |
81 | ||
aeeef83c | 82 | #endif /* __C448_COMMON_H__ */ |