| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- /* AES-128-GCM (NIST SP 800-38D) for the TLS 1.2 client: 96-bit nonces,
- * 16-byte tags. The block cipher is wpa_crypto.c's AES-128; GHASH uses
- * Shoup's 4-bit tables. Same streaming shape as the ChaCha20-Poly1305
- * AEAD in tls_chacha20.h, so the record pump can decrypt a record in
- * chunks straight from the TCP stream. Pure freestanding C with host
- * vectors (make test-crypto). */
- #ifndef TLS_GCM_H
- #define TLS_GCM_H
- struct gcm_key {
- unsigned int rk[44]; /* AES-128 round keys */
- unsigned int hl[16][4]; /* GHASH 4-bit table: hl[i] = i*H */
- };
- struct gcm_ctx {
- const struct gcm_key *k;
- unsigned int y[4]; /* GHASH accumulator, big-endian words */
- unsigned char ctr[16]; /* current counter block */
- unsigned char ks[16]; /* key stream of ctr */
- unsigned char ej0[16]; /* E_K(J0), XORed into the tag */
- unsigned char part[16]; /* partial GHASH block */
- unsigned int ks_pos, part_len;
- unsigned int aad_len, ct_len;
- };
- void gcm_setkey(struct gcm_key *k, const unsigned char key[16]);
- /* Decryption, streamed: open_update may be called any number of times. */
- void gcm_open_init(struct gcm_ctx *c, const struct gcm_key *k,
- const unsigned char nonce[12],
- const unsigned char *aad, unsigned int aad_len);
- void gcm_open_update(struct gcm_ctx *c, unsigned char *out,
- const unsigned char *in, unsigned int len);
- void gcm_open_tag(struct gcm_ctx *c, unsigned char tag[16]);
- /* One-shot seal: ct[0..len-1] (may alias pt) and the 16-byte tag. */
- void gcm_seal(const struct gcm_key *k, const unsigned char nonce[12],
- const unsigned char *aad, unsigned int aad_len,
- const unsigned char *pt, unsigned int len,
- unsigned char *ct, unsigned char tag[16]);
- #endif
|