diff options
Diffstat (limited to 'src/crypto/fipsmodule/modes/internal.h')
-rw-r--r-- | src/crypto/fipsmodule/modes/internal.h | 214 |
1 files changed, 107 insertions, 107 deletions
diff --git a/src/crypto/fipsmodule/modes/internal.h b/src/crypto/fipsmodule/modes/internal.h index 227f704b..6a5ff99b 100644 --- a/src/crypto/fipsmodule/modes/internal.h +++ b/src/crypto/fipsmodule/modes/internal.h @@ -109,28 +109,28 @@ static inline void PUTU32(void *out, uint32_t v) { OPENSSL_memcpy(out, &v, sizeof(v)); } -/* block128_f is the type of a 128-bit, block cipher. */ +// block128_f is the type of a 128-bit, block cipher. typedef void (*block128_f)(const uint8_t in[16], uint8_t out[16], const void *key); -/* GCM definitions */ +// GCM definitions typedef struct { uint64_t hi,lo; } u128; -/* gmult_func multiplies |Xi| by the GCM key and writes the result back to - * |Xi|. */ +// gmult_func multiplies |Xi| by the GCM key and writes the result back to +// |Xi|. typedef void (*gmult_func)(uint64_t Xi[2], const u128 Htable[16]); -/* ghash_func repeatedly multiplies |Xi| by the GCM key and adds in blocks from - * |inp|. The result is written back to |Xi| and the |len| argument must be a - * multiple of 16. */ +// ghash_func repeatedly multiplies |Xi| by the GCM key and adds in blocks from +// |inp|. The result is written back to |Xi| and the |len| argument must be a +// multiple of 16. typedef void (*ghash_func)(uint64_t Xi[2], const u128 Htable[16], const uint8_t *inp, size_t len); -/* This differs from upstream's |gcm128_context| in that it does not have the - * |key| pointer, in order to make it |memcpy|-friendly. Rather the key is - * passed into each call that needs it. */ +// This differs from upstream's |gcm128_context| in that it does not have the +// |key| pointer, in order to make it |memcpy|-friendly. Rather the key is +// passed into each call that needs it. struct gcm128_context { - /* Following 6 names follow names in GCM specification */ + // Following 6 names follow names in GCM specification union { uint64_t u[2]; uint32_t d[4]; @@ -138,8 +138,8 @@ struct gcm128_context { size_t t[16 / sizeof(size_t)]; } Yi, EKi, EK0, len, Xi; - /* Note that the order of |Xi|, |H| and |Htable| is fixed by the MOVBE-based, - * x86-64, GHASH assembly. */ + // Note that the order of |Xi|, |H| and |Htable| is fixed by the MOVBE-based, + // x86-64, GHASH assembly. u128 H; u128 Htable[16]; gmult_func gmult; @@ -148,39 +148,39 @@ struct gcm128_context { unsigned int mres, ares; block128_f block; - /* use_aesni_gcm_crypt is true if this context should use the assembly - * functions |aesni_gcm_encrypt| and |aesni_gcm_decrypt| to process data. */ + // use_aesni_gcm_crypt is true if this context should use the assembly + // functions |aesni_gcm_encrypt| and |aesni_gcm_decrypt| to process data. unsigned use_aesni_gcm_crypt:1; }; #if defined(OPENSSL_X86) || defined(OPENSSL_X86_64) -/* crypto_gcm_clmul_enabled returns one if the CLMUL implementation of GCM is - * used. */ +// crypto_gcm_clmul_enabled returns one if the CLMUL implementation of GCM is +// used. int crypto_gcm_clmul_enabled(void); #endif -/* CTR. */ +// CTR. -/* ctr128_f is the type of a function that performs CTR-mode encryption. */ +// ctr128_f is the type of a function that performs CTR-mode encryption. typedef void (*ctr128_f)(const uint8_t *in, uint8_t *out, size_t blocks, const void *key, const uint8_t ivec[16]); -/* CRYPTO_ctr128_encrypt encrypts (or decrypts, it's the same in CTR mode) - * |len| bytes from |in| to |out| using |block| in counter mode. There's no - * requirement that |len| be a multiple of any value and any partial blocks are - * stored in |ecount_buf| and |*num|, which must be zeroed before the initial - * call. The counter is a 128-bit, big-endian value in |ivec| and is - * incremented by this function. */ +// CRYPTO_ctr128_encrypt encrypts (or decrypts, it's the same in CTR mode) +// |len| bytes from |in| to |out| using |block| in counter mode. There's no +// requirement that |len| be a multiple of any value and any partial blocks are +// stored in |ecount_buf| and |*num|, which must be zeroed before the initial +// call. The counter is a 128-bit, big-endian value in |ivec| and is +// incremented by this function. void CRYPTO_ctr128_encrypt(const uint8_t *in, uint8_t *out, size_t len, const void *key, uint8_t ivec[16], uint8_t ecount_buf[16], unsigned *num, block128_f block); -/* CRYPTO_ctr128_encrypt_ctr32 acts like |CRYPTO_ctr128_encrypt| but takes - * |ctr|, a function that performs CTR mode but only deals with the lower 32 - * bits of the counter. This is useful when |ctr| can be an optimised - * function. */ +// CRYPTO_ctr128_encrypt_ctr32 acts like |CRYPTO_ctr128_encrypt| but takes +// |ctr|, a function that performs CTR mode but only deals with the lower 32 +// bits of the counter. This is useful when |ctr| can be an optimised +// function. void CRYPTO_ctr128_encrypt_ctr32(const uint8_t *in, uint8_t *out, size_t len, const void *key, uint8_t ivec[16], uint8_t ecount_buf[16], unsigned *num, @@ -193,137 +193,137 @@ void aesni_ctr32_encrypt_blocks(const uint8_t *in, uint8_t *out, size_t blocks, #endif -/* GCM. - * - * This API differs from the upstream API slightly. The |GCM128_CONTEXT| does - * not have a |key| pointer that points to the key as upstream's version does. - * Instead, every function takes a |key| parameter. This way |GCM128_CONTEXT| - * can be safely copied. */ +// GCM. +// +// This API differs from the upstream API slightly. The |GCM128_CONTEXT| does +// not have a |key| pointer that points to the key as upstream's version does. +// Instead, every function takes a |key| parameter. This way |GCM128_CONTEXT| +// can be safely copied. typedef struct gcm128_context GCM128_CONTEXT; -/* CRYPTO_ghash_init writes a precomputed table of powers of |gcm_key| to - * |out_table| and sets |*out_mult| and |*out_hash| to (potentially hardware - * accelerated) functions for performing operations in the GHASH field. If the - * AVX implementation was used |*out_is_avx| will be true. */ +// CRYPTO_ghash_init writes a precomputed table of powers of |gcm_key| to +// |out_table| and sets |*out_mult| and |*out_hash| to (potentially hardware +// accelerated) functions for performing operations in the GHASH field. If the +// AVX implementation was used |*out_is_avx| will be true. void CRYPTO_ghash_init(gmult_func *out_mult, ghash_func *out_hash, u128 *out_key, u128 out_table[16], int *out_is_avx, const uint8_t *gcm_key); -/* CRYPTO_gcm128_init initialises |ctx| to use |block| (typically AES) with - * the given key. |is_aesni_encrypt| is one if |block| is |aesni_encrypt|. */ +// CRYPTO_gcm128_init initialises |ctx| to use |block| (typically AES) with +// the given key. |is_aesni_encrypt| is one if |block| is |aesni_encrypt|. OPENSSL_EXPORT void CRYPTO_gcm128_init(GCM128_CONTEXT *ctx, const void *key, block128_f block, int is_aesni_encrypt); -/* CRYPTO_gcm128_setiv sets the IV (nonce) for |ctx|. The |key| must be the - * same key that was passed to |CRYPTO_gcm128_init|. */ +// CRYPTO_gcm128_setiv sets the IV (nonce) for |ctx|. The |key| must be the +// same key that was passed to |CRYPTO_gcm128_init|. OPENSSL_EXPORT void CRYPTO_gcm128_setiv(GCM128_CONTEXT *ctx, const void *key, const uint8_t *iv, size_t iv_len); -/* CRYPTO_gcm128_aad sets the authenticated data for an instance of GCM. - * This must be called before and data is encrypted. It returns one on success - * and zero otherwise. */ +// CRYPTO_gcm128_aad sets the authenticated data for an instance of GCM. +// This must be called before and data is encrypted. It returns one on success +// and zero otherwise. OPENSSL_EXPORT int CRYPTO_gcm128_aad(GCM128_CONTEXT *ctx, const uint8_t *aad, size_t len); -/* CRYPTO_gcm128_encrypt encrypts |len| bytes from |in| to |out|. The |key| - * must be the same key that was passed to |CRYPTO_gcm128_init|. It returns one - * on success and zero otherwise. */ +// CRYPTO_gcm128_encrypt encrypts |len| bytes from |in| to |out|. The |key| +// must be the same key that was passed to |CRYPTO_gcm128_init|. It returns one +// on success and zero otherwise. OPENSSL_EXPORT int CRYPTO_gcm128_encrypt(GCM128_CONTEXT *ctx, const void *key, const uint8_t *in, uint8_t *out, size_t len); -/* CRYPTO_gcm128_decrypt decrypts |len| bytes from |in| to |out|. The |key| - * must be the same key that was passed to |CRYPTO_gcm128_init|. It returns one - * on success and zero otherwise. */ +// CRYPTO_gcm128_decrypt decrypts |len| bytes from |in| to |out|. The |key| +// must be the same key that was passed to |CRYPTO_gcm128_init|. It returns one +// on success and zero otherwise. OPENSSL_EXPORT int CRYPTO_gcm128_decrypt(GCM128_CONTEXT *ctx, const void *key, const uint8_t *in, uint8_t *out, size_t len); -/* CRYPTO_gcm128_encrypt_ctr32 encrypts |len| bytes from |in| to |out| using - * a CTR function that only handles the bottom 32 bits of the nonce, like - * |CRYPTO_ctr128_encrypt_ctr32|. The |key| must be the same key that was - * passed to |CRYPTO_gcm128_init|. It returns one on success and zero - * otherwise. */ +// CRYPTO_gcm128_encrypt_ctr32 encrypts |len| bytes from |in| to |out| using +// a CTR function that only handles the bottom 32 bits of the nonce, like +// |CRYPTO_ctr128_encrypt_ctr32|. The |key| must be the same key that was +// passed to |CRYPTO_gcm128_init|. It returns one on success and zero +// otherwise. OPENSSL_EXPORT int CRYPTO_gcm128_encrypt_ctr32(GCM128_CONTEXT *ctx, const void *key, const uint8_t *in, uint8_t *out, size_t len, ctr128_f stream); -/* CRYPTO_gcm128_decrypt_ctr32 decrypts |len| bytes from |in| to |out| using - * a CTR function that only handles the bottom 32 bits of the nonce, like - * |CRYPTO_ctr128_encrypt_ctr32|. The |key| must be the same key that was - * passed to |CRYPTO_gcm128_init|. It returns one on success and zero - * otherwise. */ +// CRYPTO_gcm128_decrypt_ctr32 decrypts |len| bytes from |in| to |out| using +// a CTR function that only handles the bottom 32 bits of the nonce, like +// |CRYPTO_ctr128_encrypt_ctr32|. The |key| must be the same key that was +// passed to |CRYPTO_gcm128_init|. It returns one on success and zero +// otherwise. OPENSSL_EXPORT int CRYPTO_gcm128_decrypt_ctr32(GCM128_CONTEXT *ctx, const void *key, const uint8_t *in, uint8_t *out, size_t len, ctr128_f stream); -/* CRYPTO_gcm128_finish calculates the authenticator and compares it against - * |len| bytes of |tag|. It returns one on success and zero otherwise. */ +// CRYPTO_gcm128_finish calculates the authenticator and compares it against +// |len| bytes of |tag|. It returns one on success and zero otherwise. OPENSSL_EXPORT int CRYPTO_gcm128_finish(GCM128_CONTEXT *ctx, const uint8_t *tag, size_t len); -/* CRYPTO_gcm128_tag calculates the authenticator and copies it into |tag|. - * The minimum of |len| and 16 bytes are copied into |tag|. */ +// CRYPTO_gcm128_tag calculates the authenticator and copies it into |tag|. +// The minimum of |len| and 16 bytes are copied into |tag|. OPENSSL_EXPORT void CRYPTO_gcm128_tag(GCM128_CONTEXT *ctx, uint8_t *tag, size_t len); -/* CBC. */ +// CBC. -/* cbc128_f is the type of a function that performs CBC-mode encryption. */ +// cbc128_f is the type of a function that performs CBC-mode encryption. typedef void (*cbc128_f)(const uint8_t *in, uint8_t *out, size_t len, const void *key, uint8_t ivec[16], int enc); -/* CRYPTO_cbc128_encrypt encrypts |len| bytes from |in| to |out| using the - * given IV and block cipher in CBC mode. The input need not be a multiple of - * 128 bits long, but the output will round up to the nearest 128 bit multiple, - * zero padding the input if needed. The IV will be updated on return. */ +// CRYPTO_cbc128_encrypt encrypts |len| bytes from |in| to |out| using the +// given IV and block cipher in CBC mode. The input need not be a multiple of +// 128 bits long, but the output will round up to the nearest 128 bit multiple, +// zero padding the input if needed. The IV will be updated on return. void CRYPTO_cbc128_encrypt(const uint8_t *in, uint8_t *out, size_t len, const void *key, uint8_t ivec[16], block128_f block); -/* CRYPTO_cbc128_decrypt decrypts |len| bytes from |in| to |out| using the - * given IV and block cipher in CBC mode. If |len| is not a multiple of 128 - * bits then only that many bytes will be written, but a multiple of 128 bits - * is always read from |in|. The IV will be updated on return. */ +// CRYPTO_cbc128_decrypt decrypts |len| bytes from |in| to |out| using the +// given IV and block cipher in CBC mode. If |len| is not a multiple of 128 +// bits then only that many bytes will be written, but a multiple of 128 bits +// is always read from |in|. The IV will be updated on return. void CRYPTO_cbc128_decrypt(const uint8_t *in, uint8_t *out, size_t len, const void *key, uint8_t ivec[16], block128_f block); -/* OFB. */ +// OFB. -/* CRYPTO_ofb128_encrypt encrypts (or decrypts, it's the same with OFB mode) - * |len| bytes from |in| to |out| using |block| in OFB mode. There's no - * requirement that |len| be a multiple of any value and any partial blocks are - * stored in |ivec| and |*num|, the latter must be zero before the initial - * call. */ +// CRYPTO_ofb128_encrypt encrypts (or decrypts, it's the same with OFB mode) +// |len| bytes from |in| to |out| using |block| in OFB mode. There's no +// requirement that |len| be a multiple of any value and any partial blocks are +// stored in |ivec| and |*num|, the latter must be zero before the initial +// call. void CRYPTO_ofb128_encrypt(const uint8_t *in, uint8_t *out, size_t len, const void *key, uint8_t ivec[16], unsigned *num, block128_f block); -/* CFB. */ +// CFB. -/* CRYPTO_cfb128_encrypt encrypts (or decrypts, if |enc| is zero) |len| bytes - * from |in| to |out| using |block| in CFB mode. There's no requirement that - * |len| be a multiple of any value and any partial blocks are stored in |ivec| - * and |*num|, the latter must be zero before the initial call. */ +// CRYPTO_cfb128_encrypt encrypts (or decrypts, if |enc| is zero) |len| bytes +// from |in| to |out| using |block| in CFB mode. There's no requirement that +// |len| be a multiple of any value and any partial blocks are stored in |ivec| +// and |*num|, the latter must be zero before the initial call. void CRYPTO_cfb128_encrypt(const uint8_t *in, uint8_t *out, size_t len, const void *key, uint8_t ivec[16], unsigned *num, int enc, block128_f block); -/* CRYPTO_cfb128_8_encrypt encrypts (or decrypts, if |enc| is zero) |len| bytes - * from |in| to |out| using |block| in CFB-8 mode. Prior to the first call - * |num| should be set to zero. */ +// CRYPTO_cfb128_8_encrypt encrypts (or decrypts, if |enc| is zero) |len| bytes +// from |in| to |out| using |block| in CFB-8 mode. Prior to the first call +// |num| should be set to zero. void CRYPTO_cfb128_8_encrypt(const uint8_t *in, uint8_t *out, size_t len, const void *key, uint8_t ivec[16], unsigned *num, int enc, block128_f block); -/* CRYPTO_cfb128_1_encrypt encrypts (or decrypts, if |enc| is zero) |len| bytes - * from |in| to |out| using |block| in CFB-1 mode. Prior to the first call - * |num| should be set to zero. */ +// CRYPTO_cfb128_1_encrypt encrypts (or decrypts, if |enc| is zero) |len| bytes +// from |in| to |out| using |block| in CFB-1 mode. Prior to the first call +// |num| should be set to zero. void CRYPTO_cfb128_1_encrypt(const uint8_t *in, uint8_t *out, size_t bits, const void *key, uint8_t ivec[16], unsigned *num, int enc, block128_f block); @@ -333,11 +333,11 @@ size_t CRYPTO_cts128_encrypt_block(const uint8_t *in, uint8_t *out, size_t len, block128_f block); -/* POLYVAL. - * - * POLYVAL is a polynomial authenticator that operates over a field very - * similar to the one that GHASH uses. See - * https://tools.ietf.org/html/draft-irtf-cfrg-gcmsiv-02#section-3. */ +// POLYVAL. +// +// POLYVAL is a polynomial authenticator that operates over a field very +// similar to the one that GHASH uses. See +// https://tools.ietf.org/html/draft-irtf-cfrg-gcmsiv-02#section-3. typedef union { uint64_t u[2]; @@ -345,8 +345,8 @@ typedef union { } polyval_block; struct polyval_ctx { - /* Note that the order of |S|, |H| and |Htable| is fixed by the MOVBE-based, - * x86-64, GHASH assembly. */ + // Note that the order of |S|, |H| and |Htable| is fixed by the MOVBE-based, + // x86-64, GHASH assembly. polyval_block S; u128 H; u128 Htable[16]; @@ -354,21 +354,21 @@ struct polyval_ctx { ghash_func ghash; }; -/* CRYPTO_POLYVAL_init initialises |ctx| using |key|. */ +// CRYPTO_POLYVAL_init initialises |ctx| using |key|. void CRYPTO_POLYVAL_init(struct polyval_ctx *ctx, const uint8_t key[16]); -/* CRYPTO_POLYVAL_update_blocks updates the accumulator in |ctx| given the - * blocks from |in|. Only a whole number of blocks can be processed so |in_len| - * must be a multiple of 16. */ +// CRYPTO_POLYVAL_update_blocks updates the accumulator in |ctx| given the +// blocks from |in|. Only a whole number of blocks can be processed so |in_len| +// must be a multiple of 16. void CRYPTO_POLYVAL_update_blocks(struct polyval_ctx *ctx, const uint8_t *in, size_t in_len); -/* CRYPTO_POLYVAL_finish writes the accumulator from |ctx| to |out|. */ +// CRYPTO_POLYVAL_finish writes the accumulator from |ctx| to |out|. void CRYPTO_POLYVAL_finish(const struct polyval_ctx *ctx, uint8_t out[16]); #if defined(__cplusplus) -} /* extern C */ +} // extern C #endif -#endif /* OPENSSL_HEADER_MODES_INTERNAL_H */ +#endif // OPENSSL_HEADER_MODES_INTERNAL_H |