|
SharkSSL C/C++ Reference
TLS, cryptography, certificates, and PSA integration
|
AES-GCM.
Data Structures | |
| struct | SharkSslAesGcmCtx |
| AesGcmCtx. More... | |
Typedefs | |
| typedef struct SharkSslAesGcmCtx | SharkSslAesGcmCtx |
| AesGcmCtx. More... | |
Functions | |
| SHARKSSL_API SHARKSSL_AES_API_STATUS | SharkSslAesGcmCtx_constructor (SharkSslAesGcmCtx *ctx, const U8 *key, U8 keyLen) |
| Initialize. More... | |
| SHARKSSL_API int | SharkSslAesGcmCtx_encrypt (SharkSslAesGcmCtx *ctx, const U8 vect[12], U8 tagout[16], const U8 *auth, U16 authlen, const U8 *input, U8 *output, U32 len) |
| Encrypt and authenticate one complete message. More... | |
| SHARKSSL_API int | SharkSslAesGcmCtx_decrypt (SharkSslAesGcmCtx *ctx, const U8 vect[12], U8 tagin[16], const U8 *auth, U16 authlen, U8 *input, U8 *output, U32 len) |
| Decrypt and authenticate one complete message. More... | |
| typedef struct SharkSslAesGcmCtx SharkSslAesGcmCtx |
AesGcmCtx.
| SHARKSSL_AES_API_STATUS SharkSslAesGcmCtx_constructor | ( | SharkSslAesGcmCtx * | ctx, |
| const U8 * | key, | ||
| U8 | keyLen | ||
| ) |
Initialize.
The caller owns the context.
| ctx | Uninitialized data of size sizeof(SharkSslAesGcmCtx). |
| key | the encryption/decryption key |
| keyLen | 'key' length |
The key length is in bytes: 16, 24, or 32, subject to the enabled algorithms/backend. Clear the context with its destructor after use.
| SHARKSSL_API int SharkSslAesGcmCtx_decrypt | ( | SharkSslAesGcmCtx * | ctx, |
| const U8 | vect[12], | ||
| U8 | tagin[16], | ||
| const U8 * | auth, | ||
| U16 | authlen, | ||
| U8 * | input, | ||
| U8 * | output, | ||
| U32 | len | ||
| ) |
Decrypt and authenticate one complete message.
| ctx | context initialized by SharkSslAesGcmCtx_constructor. |
| vect | the same IV as used in SharkSslAesGcmCtx_encrypt. |
| tagin | required 16-byte expected tag from the matching encryption call. The native and PSA implementations read it without modification. |
| auth | the same auth as used in SharkSslAesGcmCtx_encrypt or NULL if not used. |
| authlen | the length of the 'auth' parameter. |
| input | the data to be decrypted. |
| output | the decrypted plaintext. This buffer may be the same as input. On authentication failure, its contents are invalid and may be modified. Discard them; in-place decryption may also destroy the ciphertext. |
| len | ciphertext length in bytes. Keep it below 2^29 with the common native implementation, matching the encryption restriction. |
| int SharkSslAesGcmCtx_encrypt | ( | SharkSslAesGcmCtx * | ctx, |
| const U8 | vect[12], | ||
| U8 | tagout[16], | ||
| const U8 * | auth, | ||
| U16 | authlen, | ||
| const U8 * | input, | ||
| U8 * | output, | ||
| U32 | len | ||
| ) |
Encrypt and authenticate one complete message.
Each call authenticates one complete message and writes its tag.
| ctx | initialized context, retained for reuse with distinct nonces. |
| vect | required 12-byte nonce. Never reuse a nonce with the same key. |
| tagout | required 16-byte output tag; overwritten, not accumulated. |
| auth | optional additional authenticated data (AAD). These bytes are authenticated but not encrypted; NULL requires authlen=0. |
| authlen | AAD length in bytes. |
| input | plaintext bytes, borrowed for this call. |
| output | writable ciphertext buffer of at least len bytes. Exact in-place operation is supported. |
| len | plaintext length in bytes. Keep it below 2^29 when using the common native implementation, whose GCM bit-length field is 32 bits. |
Each call starts a separate GCM message. To store a large object in chunks, assign a distinct nonce to every chunk under this key and keep each chunk's nonce, AAD, and tag for decryption. A previous tag is not input to the next call. Authenticate chunk order/identity in the AAD when the application must detect rearrangement or substitution.
It does not continue a previous GCM message or accumulate the previous tag. Use a distinct 12-byte nonce for every encrypted message under a key, including separately stored chunks; do not reuse a nonce across calls.