Change cipher prototypes for GCM
diff --git a/include/polarssl/cipher.h b/include/polarssl/cipher.h
index 67ca28c..ef037be 100644
--- a/include/polarssl/cipher.h
+++ b/include/polarssl/cipher.h
@@ -320,7 +320,7 @@
* \param ctx cipher's context. Must have been initialised.
*
* \return size of the cipher's IV, or 0 if ctx has not been
- * initialised.
+ * initialised or accepts IV of various sizes.
*/
static inline int cipher_get_iv_size( const cipher_context_t *ctx )
{
@@ -432,11 +432,18 @@
*
* \param ctx generic cipher context
* \param iv IV to use or NONCE_COUNTER in the case of a CTR-mode cipher
+ * \param iv_len IV length for ciphers with variable-size IV,
+ * Discared by ciphers with fixed-size IV.
+ * \param ad Additional data for AEAD ciphers, or discarded.
+ * May be NULL only if ad_len is 0.
+ * \param ad_len Length of ad for AEAD ciphers, or discarded.
*
* \returns 0 on success, POLARSSL_ERR_CIPHER_BAD_INPUT_DATA
* if parameter verification fails.
*/
-int cipher_reset( cipher_context_t *ctx, const unsigned char *iv );
+int cipher_reset( cipher_context_t *ctx,
+ const unsigned char *iv, size_t iv_len,
+ const unsigned char *ad, size_t ad_len );
/**
* \brief Generic cipher update function. Encrypts/decrypts
@@ -471,8 +478,13 @@
* the last block, and written to the output buffer.
*
* \param ctx Generic cipher context
- * \param output buffer to write data to. Needs block_size data available.
+ * \param output buffer to write data to. Needs block_size available.
* \param olen length of the data written to the output buffer.
+ * \param tag Ignore by non-AEAD ciphers. For AEAD ciphers:
+ * - on encryption: buffer to write the tag;
+ * - on decryption: tag to verify.
+ * May be NULL if tag_len is zero.
+ * \param tag_len Length of the tag to write/check for AEAD ciphers.
*
* \returns 0 on success, POLARSSL_ERR_CIPHER_BAD_INPUT_DATA if
* parameter verification fails,
@@ -481,7 +493,9 @@
* POLARSSL_ERR_CIPHER_INVALID_PADDING on invalid padding
* while decrypting or a cipher specific error code.
*/
-int cipher_finish( cipher_context_t *ctx, unsigned char *output, size_t *olen);
+int cipher_finish( cipher_context_t *ctx,
+ unsigned char *output, size_t *olen,
+ unsigned char *tag, size_t tag_len );
/**
* \brief Checkup routine
diff --git a/include/polarssl/gcm.h b/include/polarssl/gcm.h
index 2bed342..dc058dc 100644
--- a/include/polarssl/gcm.h
+++ b/include/polarssl/gcm.h
@@ -146,7 +146,7 @@
* \param mode GCM_ENCRYPT or GCM_DECRYPT
* \param iv initialization vector
* \param iv_len length of IV
- * \param add additional data
+ * \param add additional data (or NULL if length is 0)
* \param add_len length of additional data
*
* \return 0 if successful
@@ -182,14 +182,14 @@
/**
* \brief Generic GCM finalisation function. Wraps up the GCM stream
- * and generated the tag. The tag can have a maximum length of
+ * and generates the tag. The tag can have a maximum length of
* 16 bytes.
*
* \param ctx GCM context
- * \param tag buffer for holding the tag
+ * \param tag buffer for holding the tag (may be NULL if tag_len is 0)
* \param tag_len length of the tag to generate
*
- * \return 0 if successful or POLARSSL_ERR_GCM_BAD_INPUT
+ * \return 0 if successful or POLARSSL_ERR_GCM_BAD_INPUT
*/
int gcm_finish( gcm_context *ctx,
unsigned char *tag,