mbed TLS v1.3.21
gcm.h
Go to the documentation of this file.
1 
24 #ifndef POLARSSL_GCM_H
25 #define POLARSSL_GCM_H
26 
27 #include "cipher.h"
28 
29 #if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
30 #include <basetsd.h>
31 typedef UINT32 uint32_t;
32 typedef UINT64 uint64_t;
33 #else
34 #include <stdint.h>
35 #endif
36 
37 #define GCM_ENCRYPT 1
38 #define GCM_DECRYPT 0
39 
40 #define POLARSSL_ERR_GCM_AUTH_FAILED -0x0012
41 #define POLARSSL_ERR_GCM_BAD_INPUT -0x0014
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
50 typedef struct {
52  uint64_t HL[16];
53  uint64_t HH[16];
54  uint64_t len;
55  uint64_t add_len;
56  unsigned char base_ectr[16];
57  unsigned char y[16];
58  unsigned char buf[16];
59  int mode;
60 }
62 
73 int gcm_init( gcm_context *ctx, cipher_id_t cipher, const unsigned char *key,
74  unsigned int keysize );
75 
99  int mode,
100  size_t length,
101  const unsigned char *iv,
102  size_t iv_len,
103  const unsigned char *add,
104  size_t add_len,
105  const unsigned char *input,
106  unsigned char *output,
107  size_t tag_len,
108  unsigned char *tag );
109 
131 int gcm_auth_decrypt( gcm_context *ctx,
132  size_t length,
133  const unsigned char *iv,
134  size_t iv_len,
135  const unsigned char *add,
136  size_t add_len,
137  const unsigned char *tag,
138  size_t tag_len,
139  const unsigned char *input,
140  unsigned char *output );
141 
154 int gcm_starts( gcm_context *ctx,
155  int mode,
156  const unsigned char *iv,
157  size_t iv_len,
158  const unsigned char *add,
159  size_t add_len );
160 
178 int gcm_update( gcm_context *ctx,
179  size_t length,
180  const unsigned char *input,
181  unsigned char *output );
182 
194 int gcm_finish( gcm_context *ctx,
195  unsigned char *tag,
196  size_t tag_len );
197 
203 void gcm_free( gcm_context *ctx );
204 
210 int gcm_self_test( int verbose );
211 
212 #ifdef __cplusplus
213 }
214 #endif
215 
216 #endif /* gcm.h */
int gcm_auth_decrypt(gcm_context *ctx, size_t length, const unsigned char *iv, size_t iv_len, const unsigned char *add, size_t add_len, const unsigned char *tag, size_t tag_len, const unsigned char *input, unsigned char *output)
GCM buffer authenticated decryption using a block cipher.
uint64_t len
Definition: gcm.h:54
Generic cipher context.
Definition: cipher.h:264
int gcm_self_test(int verbose)
Checkup routine.
int gcm_crypt_and_tag(gcm_context *ctx, int mode, size_t length, const unsigned char *iv, size_t iv_len, const unsigned char *add, size_t add_len, const unsigned char *input, unsigned char *output, size_t tag_len, unsigned char *tag)
GCM buffer encryption/decryption using a block cipher.
int mode
Definition: gcm.h:59
GCM context structure.
Definition: gcm.h:50
int gcm_init(gcm_context *ctx, cipher_id_t cipher, const unsigned char *key, unsigned int keysize)
GCM initialization (encryption)
Generic cipher wrapper.
cipher_id_t
Definition: cipher.h:69
int gcm_update(gcm_context *ctx, size_t length, const unsigned char *input, unsigned char *output)
Generic GCM update function.
void gcm_free(gcm_context *ctx)
Free a GCM context and underlying cipher sub-context.
int gcm_starts(gcm_context *ctx, int mode, const unsigned char *iv, size_t iv_len, const unsigned char *add, size_t add_len)
Generic GCM stream start function.
int gcm_finish(gcm_context *ctx, unsigned char *tag, size_t tag_len)
Generic GCM finalisation function.
cipher_context_t cipher_ctx
Definition: gcm.h:51
uint64_t add_len
Definition: gcm.h:55