iPXE
gcm.h
Go to the documentation of this file.
1#ifndef _IPXE_GCM_H
2#define _IPXE_GCM_H
3
4/** @file
5 *
6 * Galois/Counter Mode (GCM)
7 *
8 */
9
10FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11FILE_SECBOOT ( PERMITTED );
12
13#include <stdint.h>
14#include <ipxe/crypto.h>
15
16/** A GCM counter */
18 /** Initialisation vector */
20 /** Counter value */
22} __attribute__ (( packed ));
23
24/** A GCM length pair */
26 /** Additional data length */
28 /** Data length */
30} __attribute__ (( packed ));
31
32/** A GCM block */
33union gcm_block {
34 /** Raw bytes */
35 uint8_t byte[16];
36 /** Raw words */
38 /** Raw dwords */
40 /** Counter */
42 /** Lengths */
44} __attribute__ (( packed ));
45
46/** GCM context */
48 /** Accumulated hash (X) */
50 /** Accumulated lengths */
52 /** Counter (Y) */
54 /** Hash key (H) */
56 /** Processing flags */
57 unsigned int flags;
58};
59
60/** A GCM mode context */
61#define gcm_context_t( ctxsize ) \
62 struct { \
63 struct gcm_context gcm; \
64 uint8_t raw[ (ctxsize) - \
65 sizeof ( struct gcm_context ) ]; \
66 }
67
68extern int gcm_setkey ( struct cipher_algorithm *cipher, void *ctx,
69 const void *key, size_t keylen );
70extern int gcm_setiv ( struct cipher_algorithm *cipher, void *ctx,
71 const void *iv, size_t ivlen );
72extern void gcm_encrypt ( struct cipher_algorithm *cipher, void *ctx,
73 const void *src, void *dst, size_t len );
74extern void gcm_decrypt ( struct cipher_algorithm *cipher, void *ctx,
75 const void *src, void *dst, size_t len );
76extern void gcm_auth ( struct cipher_algorithm *cipher, void *ctx,
77 void *auth );
78
79/**
80 * Create a GCM mode of behaviour of an existing cipher
81 *
82 * @v _cbc_name Name for the new CBC cipher
83 * @v _cbc_cipher New cipher algorithm
84 * @v _raw_cipher Underlying cipher algorithm
85 * @v _raw_context Context structure for the underlying cipher
86 * @v _blocksize Cipher block size
87 */
88#define GCM_CIPHER( _gcm_name, _gcm_cipher, _raw_cipher, _raw_context, \
89 _blocksize ) \
90static_assert ( _blocksize == sizeof ( union gcm_block ) ); \
91struct cipher_algorithm _gcm_cipher = { \
92 .name = #_gcm_name, \
93 .ctxsize = ( sizeof ( struct gcm_context ) + \
94 sizeof ( _raw_context ) ), \
95 .blocksize = 1, \
96 .alignsize = sizeof ( union gcm_block ), \
97 .authsize = sizeof ( union gcm_block ), \
98 .confidential = 1, \
99 .setkey = gcm_setkey, \
100 .setiv = gcm_setiv, \
101 .encrypt = gcm_encrypt, \
102 .decrypt = gcm_decrypt, \
103 .auth = gcm_auth, \
104 .priv = &_raw_cipher, \
105};
106
107#endif /* _IPXE_GCM_H */
struct golan_eq_context ctx
Definition CIB_PRM.h:0
union @162305117151260234136356364136041353210355154177 key
unsigned short uint16_t
Definition stdint.h:11
unsigned int uint32_t
Definition stdint.h:12
unsigned long long uint64_t
Definition stdint.h:13
unsigned char uint8_t
Definition stdint.h:10
static const void * src
Definition string.h:48
ring len
Length.
Definition dwmac.h:226
int gcm_setiv(struct cipher_algorithm *cipher, void *ctx, const void *iv, size_t ivlen)
Set initialisation vector.
Definition gcm.c:457
void gcm_decrypt(struct cipher_algorithm *cipher, void *ctx, const void *src, void *dst, size_t len)
Decrypt data.
Definition gcm.c:524
void gcm_auth(struct cipher_algorithm *cipher, void *ctx, void *auth)
Generate authentication tag.
Definition gcm.c:540
void gcm_encrypt(struct cipher_algorithm *cipher, void *ctx, const void *src, void *dst, size_t len)
Encrypt data.
Definition gcm.c:506
int gcm_setkey(struct cipher_algorithm *cipher, void *ctx, const void *key, size_t keylen)
Set key.
Definition gcm.c:418
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:921
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:951
#define __attribute__(x)
Definition compiler.h:10
Cryptographic API.
A cipher algorithm.
Definition crypto.h:58
GCM context.
Definition gcm.h:47
union gcm_block key
Hash key (H).
Definition gcm.h:55
union gcm_block ctr
Counter (Y).
Definition gcm.h:53
union gcm_block hash
Accumulated hash (X).
Definition gcm.h:49
unsigned int flags
Processing flags.
Definition gcm.h:57
union gcm_block len
Accumulated lengths.
Definition gcm.h:51
A GCM counter.
Definition gcm.h:17
uint8_t iv[12]
Initialisation vector.
Definition gcm.h:19
uint32_t value
Counter value.
Definition gcm.h:21
A GCM length pair.
Definition gcm.h:25
uint64_t data
Data length.
Definition gcm.h:29
uint64_t add
Additional data length.
Definition gcm.h:27
A GCM block.
Definition gcm.h:33
struct gcm_counter ctr
Counter.
Definition gcm.h:41
uint32_t dword[4]
Raw dwords.
Definition gcm.h:39
struct gcm_lengths len
Lengths.
Definition gcm.h:43
uint16_t word[8]
Raw words.
Definition gcm.h:37
u8 iv[16]
Initialization vector.
Definition wpa.h:33