]>
Commit | Line | Data |
---|---|---|
1308e022 | 1 | /* |
3a86f1db | 2 | * Copyright 2017-2019 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 | |
205fd638 MC |
18 | /* |
19 | * Internal word types. Somewhat tricky. This could be decided separately per | |
20 | * platform. However, the structs do need to be all the same size and | |
21 | * alignment on a given platform to support dynamic linking, since even if you | |
22 | * header was built with eg arch_neon, you might end up linking a library built | |
23 | * with arch_arm32. | |
7324473f | 24 | */ |
aeeef83c | 25 | # ifndef C448_WORD_BITS |
ae1ffe0f | 26 | # if (defined(__SIZEOF_INT128__) && (__SIZEOF_INT128__ == 16)) \ |
3a86f1db SL |
27 | && !defined(__sparc__) \ |
28 | && (!defined(__SIZEOF_LONG__) || (__SIZEOF_LONG__ == 8)) | |
29 | ||
aeeef83c | 30 | # define C448_WORD_BITS 64 /* The number of bits in a word */ |
205fd638 | 31 | # else |
aeeef83c | 32 | # define C448_WORD_BITS 32 /* The number of bits in a word */ |
205fd638 MC |
33 | # endif |
34 | # endif | |
35 | ||
aeeef83c | 36 | # if C448_WORD_BITS == 64 |
8d55f844 | 37 | /* Word size for internal computations */ |
aeeef83c | 38 | typedef uint64_t c448_word_t; |
8d55f844 | 39 | /* Signed word size for internal computations */ |
aeeef83c | 40 | typedef int64_t c448_sword_t; |
8d55f844 | 41 | /* "Boolean" type, will be set to all-zero or all-one (i.e. -1u) */ |
aeeef83c | 42 | typedef uint64_t c448_bool_t; |
8d55f844 | 43 | /* Double-word size for internal computations */ |
aeeef83c | 44 | typedef __uint128_t c448_dword_t; |
8d55f844 | 45 | /* Signed double-word size for internal computations */ |
aeeef83c MC |
46 | typedef __int128_t c448_dsword_t; |
47 | # elif C448_WORD_BITS == 32 | |
8d55f844 | 48 | /* Word size for internal computations */ |
aeeef83c | 49 | typedef uint32_t c448_word_t; |
8d55f844 | 50 | /* Signed word size for internal computations */ |
aeeef83c | 51 | typedef int32_t c448_sword_t; |
8d55f844 | 52 | /* "Boolean" type, will be set to all-zero or all-one (i.e. -1u) */ |
aeeef83c | 53 | typedef uint32_t c448_bool_t; |
8d55f844 | 54 | /* Double-word size for internal computations */ |
aeeef83c | 55 | typedef uint64_t c448_dword_t; |
8d55f844 | 56 | /* Signed double-word size for internal computations */ |
aeeef83c | 57 | typedef int64_t c448_dsword_t; |
205fd638 | 58 | # else |
aeeef83c | 59 | # error "Only supporting C448_WORD_BITS = 32 or 64 for now" |
205fd638 MC |
60 | # endif |
61 | ||
aeeef83c | 62 | /* C448_TRUE = -1 so that C448_TRUE & x = x */ |
68b20c00 | 63 | # define C448_TRUE (0 - (c448_bool_t)1) |
7324473f | 64 | |
aeeef83c | 65 | /* C448_FALSE = 0 so that C448_FALSE & x = 0 */ |
68b20c00 | 66 | # define C448_FALSE 0 |
7324473f | 67 | |
8d55f844 | 68 | /* Another boolean type used to indicate success or failure. */ |
7324473f | 69 | typedef enum { |
aeeef83c MC |
70 | C448_SUCCESS = -1, /**< The operation succeeded. */ |
71 | C448_FAILURE = 0 /**< The operation failed. */ | |
72 | } c448_error_t; | |
7324473f | 73 | |
8d55f844 | 74 | /* Return success if x is true */ |
aeeef83c | 75 | static ossl_inline c448_error_t c448_succeed_if(c448_bool_t x) |
205fd638 | 76 | { |
aeeef83c | 77 | return (c448_error_t) x; |
7324473f MC |
78 | } |
79 | ||
aeeef83c | 80 | #endif /* __C448_COMMON_H__ */ |