diff --git a/include/crypto/cipher.h b/include/crypto/cipher.h index fe79c3c27e2..bec6f74bebb 100644 --- a/include/crypto/cipher.h +++ b/include/crypto/cipher.h @@ -268,4 +268,26 @@ static inline int cipher_ccm_op(struct cipher_ctx *ctx, return ctx->ops.ccm_crypt_hndlr(ctx, pkt, nonce); } +/* + * @brief Perform Galois/Counter Mode (GCM) crypto operation + * + * @param[in] ctx Pointer to the crypto context of this op. + * @param[in/out] pkt Structure holding the input/output, Associated + * Data (AD) and auth tag buffer pointers. + * @param[in] nonce Nonce for the operation. Same nonce value should not + * be reused across multiple operations (within a + * session context) for security. + * + * @return 0 on success, negative errno code on fail. + */ +static inline int cipher_gcm_op(struct cipher_ctx *ctx, + struct cipher_aead_pkt *pkt, u8_t *nonce) +{ + __ASSERT(ctx->ops.cipher_mode == CRYPTO_CIPHER_MODE_GCM, "GCM mode " + "session invoking a different mode handler"); + + pkt->pkt->ctx = ctx; + return ctx->ops.gcm_crypt_hndlr(ctx, pkt, nonce); +} + #endif /* ZEPHYR_INCLUDE_CRYPTO_CIPHER_H_ */ diff --git a/include/crypto/cipher_structs.h b/include/crypto/cipher_structs.h index 47bcd416664..022da0c49ad 100644 --- a/include/crypto/cipher_structs.h +++ b/include/crypto/cipher_structs.h @@ -38,6 +38,7 @@ enum cipher_mode { CRYPTO_CIPHER_MODE_CBC = 2, CRYPTO_CIPHER_MODE_CTR = 3, CRYPTO_CIPHER_MODE_CCM = 4, + CRYPTO_CIPHER_MODE_GCM = 5, }; /* Forward declarations */ @@ -59,6 +60,9 @@ typedef int (*ctr_op_t)(struct cipher_ctx *ctx, struct cipher_pkt *pkt, typedef int (*ccm_op_t)(struct cipher_ctx *ctx, struct cipher_aead_pkt *pkt, u8_t *nonce); +typedef int (*gcm_op_t)(struct cipher_ctx *ctx, struct cipher_aead_pkt *pkt, + u8_t *nonce); + struct cipher_ops { enum cipher_mode cipher_mode; @@ -68,6 +72,7 @@ struct cipher_ops { cbc_op_t cbc_crypt_hndlr; ctr_op_t ctr_crypt_hndlr; ccm_op_t ccm_crypt_hndlr; + gcm_op_t gcm_crypt_hndlr; }; }; @@ -83,6 +88,11 @@ struct ctr_params { u32_t ctr_len; }; +struct gcm_params { + u16_t tag_len; + u16_t nonce_len; +}; + /* Structure encoding session parameters. Refer to comments for individual * fields to know the contract in terms of who fills what and when w.r.t * begin_session() call. @@ -132,6 +142,7 @@ struct cipher_ctx { union { struct ccm_params ccm_info; struct ctr_params ctr_info; + struct gcm_params gcm_info; } mode_params; /* Cryptographic keylength in bytes. To be populated by the app