You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2019/04/16 16:50:07 UTC
[mynewt-core] branch master updated: mbedtls;
add a routine to add AAD data incrementally.
This is an automated email from the ASF dual-hosted git repository.
marko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
The following commit(s) were added to refs/heads/master by this push:
new f2ed758 mbedtls; add a routine to add AAD data incrementally.
new ed4fa52 Merge pull request #1752 from mkiiskila/mbedtls_gcm_update_aad
f2ed758 is described below
commit f2ed758343651745404507f76c3022cf518fbf6f
Author: Marko Kiiskila <ma...@apache.org>
AuthorDate: Wed Apr 10 09:29:38 2019 +0300
mbedtls; add a routine to add AAD data incrementally.
---
crypto/mbedtls/include/mbedtls/gcm.h | 24 ++++++++++++++++++++++++
crypto/mbedtls/src/gcm.c | 35 ++++++++++++++++++++++++++++++++++-
2 files changed, 58 insertions(+), 1 deletion(-)
diff --git a/crypto/mbedtls/include/mbedtls/gcm.h b/crypto/mbedtls/include/mbedtls/gcm.h
index af0017f..363496c 100644
--- a/crypto/mbedtls/include/mbedtls/gcm.h
+++ b/crypto/mbedtls/include/mbedtls/gcm.h
@@ -235,6 +235,30 @@ int mbedtls_gcm_starts( mbedtls_gcm_context *ctx,
/**
* \brief This function feeds an input buffer into an ongoing GCM
+ * encryption or decryption operation as additional data.
+ * This needs to be called before starting enc/dec
+ * operations.
+ *
+ * ` The function expects input to be a multiple of 16
+ * Bytes. Only the last call before mbedtls_gcm_update() or
+ * mbedtls_gcm_finish() can be less than 16 Bytes.
+ *
+ *
+ * \param ctx The GCM context.
+ * \param length The length of the input data. This must be a multiple of
+ * 16 except in the last call before mbedtls_gcm_finish().
+ * \param input The buffer holding the input ADD.
+ *
+ * \return \c 0 on success.
+ * \return #MBEDTLS_ERR_GCM_BAD_INPUT on failure.
+ */
+int mbedtls_gcm_update_add( mbedtls_gcm_context *ctx,
+ size_t length,
+ const unsigned char *input );
+
+
+/**
+ * \brief This function feeds an input buffer into an ongoing GCM
* encryption or decryption operation.
*
* ` The function expects input to be a multiple of 16
diff --git a/crypto/mbedtls/src/gcm.c b/crypto/mbedtls/src/gcm.c
index 75e650f..e7adeac 100644
--- a/crypto/mbedtls/src/gcm.c
+++ b/crypto/mbedtls/src/gcm.c
@@ -360,7 +360,7 @@ int mbedtls_gcm_starts( mbedtls_gcm_context *ctx,
{
return( ret );
}
-
+/*
ctx->add_len = add_len;
p = add;
while( add_len > 0 )
@@ -377,6 +377,39 @@ int mbedtls_gcm_starts( mbedtls_gcm_context *ctx,
}
return( 0 );
+*/
+ return mbedtls_gcm_update_add( ctx, add_len, add );
+}
+
+int mbedtls_gcm_update_add( mbedtls_gcm_context *ctx,
+ size_t add_len,
+ const unsigned char *add )
+{
+ const unsigned char *p;
+ size_t i;
+ size_t use_len;
+
+ if ( ctx->add_len & 15 )
+ {
+ return( MBEDTLS_ERR_GCM_BAD_INPUT );
+ }
+ ctx->add_len += add_len;
+ p = add;
+
+ while (add_len > 0)
+ {
+ use_len = ( add_len < 16 ) ? add_len : 16;
+
+ for( i = 0; i < use_len; i++ ) {
+ ctx->buf[i] ^= p[i];
+ }
+ gcm_mult( ctx, ctx->buf, ctx->buf );
+
+ add_len -= use_len;
+ p += use_len;
+ }
+
+ return( 0 );
}
int mbedtls_gcm_update( mbedtls_gcm_context *ctx,