• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright 2014-2022 The GmSSL Project. All Rights Reserved.
3  *
4  *  Licensed under the Apache License, Version 2.0 (the License); you may
5  *  not use this file except in compliance with the License.
6  *
7  *  http://www.apache.org/licenses/LICENSE-2.0
8  */
9 
10 
11 #ifndef GMSSL_GCM_H
12 #define GMSSL_GCM_H
13 
14 
15 #include <stdlib.h>
16 #include <stdint.h>
17 #include <string.h>
18 #include <gmssl/gf128.h>
19 #include <gmssl/block_cipher.h>
20 
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #define GCM_IV_MIN_SIZE		1
27 #define GCM_IV_MAX_SIZE		((uint64_t)(1 << (64-3)))
28 #define GCM_IV_DEFAULT_BITS	96
29 #define GCM_IV_DEFAULT_SIZE	12
30 
31 #define GCM_MIN_AAD_SIZE	0
32 #define GCM_MAX_AAD_SIZE	((uint64_t)(1 << (64-3)))
33 
34 #define GCM_MIN_PLAINTEXT_SIZE	0
35 #define GCM_MAX_PLAINTEXT_SIZE	((((uint64_t)1 << 39) - 256) >> 3)
36 
37 
38 #define GHASH_SIZE		(16)
39 
40 
41 #define GCM_IS_LITTLE_ENDIAN 1
42 
43 
44 void ghash(const uint8_t h[16], const uint8_t *aad, size_t aadlen,
45 	const uint8_t *c, size_t clen, uint8_t out[16]);
46 
47 int gcm_encrypt(const BLOCK_CIPHER_KEY *key, const uint8_t *iv, size_t ivlen,
48 	const uint8_t *aad, size_t aadlen, const uint8_t *in, size_t inlen,
49 	uint8_t *out, size_t taglen, uint8_t *tag);
50 
51 int gcm_decrypt(const BLOCK_CIPHER_KEY *key, const uint8_t *iv, size_t ivlen,
52 	const uint8_t *aad, size_t aadlen, const uint8_t *in, size_t inlen,
53 	const uint8_t *tag, size_t taglen, uint8_t *out);
54 
55 
56 #ifdef __cplusplus
57 }
58 #endif
59 #endif
60