From 16d412f4654d7eca75139c926c09ca66fe88a789 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Mon, 6 Jul 2015 15:26:26 +0200 Subject: [PATCH] Add md/shaXXX_clone() API Will be used in the SSL/TLS modules --- include/mbedtls/md2.h | 9 +++++++++ include/mbedtls/md4.h | 9 +++++++++ include/mbedtls/md5.h | 9 +++++++++ include/mbedtls/ripemd160.h | 9 +++++++++ include/mbedtls/sha1.h | 9 +++++++++ include/mbedtls/sha256.h | 9 +++++++++ include/mbedtls/sha512.h | 9 +++++++++ library/md2.c | 6 ++++++ library/md4.c | 6 ++++++ library/md5.c | 6 ++++++ library/ripemd160.c | 6 ++++++ library/sha1.c | 6 ++++++ library/sha256.c | 6 ++++++ library/sha512.c | 6 ++++++ 14 files changed, 105 insertions(+) diff --git a/include/mbedtls/md2.h b/include/mbedtls/md2.h index 8d012666d..151a8f45d 100644 --- a/include/mbedtls/md2.h +++ b/include/mbedtls/md2.h @@ -66,6 +66,15 @@ void mbedtls_md2_init( mbedtls_md2_context *ctx ); */ void mbedtls_md2_free( mbedtls_md2_context *ctx ); +/** + * \brief Clone (the state of) an MD2 context + * + * \param dst The destination context + * \param src The context to be cloned + */ +void mbedtls_md2_clone( mbedtls_md2_context *dst, + const mbedtls_md2_context *src ); + /** * \brief MD2 context setup * diff --git a/include/mbedtls/md4.h b/include/mbedtls/md4.h index 96dcc447f..fd756b91b 100644 --- a/include/mbedtls/md4.h +++ b/include/mbedtls/md4.h @@ -66,6 +66,15 @@ void mbedtls_md4_init( mbedtls_md4_context *ctx ); */ void mbedtls_md4_free( mbedtls_md4_context *ctx ); +/** + * \brief Clone (the state of) an MD4 context + * + * \param dst The destination context + * \param src The context to be cloned + */ +void mbedtls_md4_clone( mbedtls_md4_context *dst, + const mbedtls_md4_context *src ); + /** * \brief MD4 context setup * diff --git a/include/mbedtls/md5.h b/include/mbedtls/md5.h index 163780a24..40273d480 100644 --- a/include/mbedtls/md5.h +++ b/include/mbedtls/md5.h @@ -66,6 +66,15 @@ void mbedtls_md5_init( mbedtls_md5_context *ctx ); */ void mbedtls_md5_free( mbedtls_md5_context *ctx ); +/** + * \brief Clone (the state of) an MD5 context + * + * \param dst The destination context + * \param src The context to be cloned + */ +void mbedtls_md5_clone( mbedtls_md5_context *dst, + const mbedtls_md5_context *src ); + /** * \brief MD5 context setup * diff --git a/include/mbedtls/ripemd160.h b/include/mbedtls/ripemd160.h index e66c46a20..9013f208e 100644 --- a/include/mbedtls/ripemd160.h +++ b/include/mbedtls/ripemd160.h @@ -66,6 +66,15 @@ void mbedtls_ripemd160_init( mbedtls_ripemd160_context *ctx ); */ void mbedtls_ripemd160_free( mbedtls_ripemd160_context *ctx ); +/** + * \brief Clone (the state of) an RIPEMD-160 context + * + * \param dst The destination context + * \param src The context to be cloned + */ +void mbedtls_ripemd160_clone( mbedtls_ripemd160_context *dst, + const mbedtls_ripemd160_context *src ); + /** * \brief RIPEMD-160 context setup * diff --git a/include/mbedtls/sha1.h b/include/mbedtls/sha1.h index 74fb85578..e8bd65e38 100644 --- a/include/mbedtls/sha1.h +++ b/include/mbedtls/sha1.h @@ -66,6 +66,15 @@ void mbedtls_sha1_init( mbedtls_sha1_context *ctx ); */ void mbedtls_sha1_free( mbedtls_sha1_context *ctx ); +/** + * \brief Clone (the state of) a SHA-1 context + * + * \param dst The destination context + * \param src The context to be cloned + */ +void mbedtls_sha1_clone( mbedtls_sha1_context *dst, + const mbedtls_sha1_context *src ); + /** * \brief SHA-1 context setup * diff --git a/include/mbedtls/sha256.h b/include/mbedtls/sha256.h index 113c23b02..0dbc4b256 100644 --- a/include/mbedtls/sha256.h +++ b/include/mbedtls/sha256.h @@ -67,6 +67,15 @@ void mbedtls_sha256_init( mbedtls_sha256_context *ctx ); */ void mbedtls_sha256_free( mbedtls_sha256_context *ctx ); +/** + * \brief Clone (the state of) a SHA-256 context + * + * \param dst The destination context + * \param src The context to be cloned + */ +void mbedtls_sha256_clone( mbedtls_sha256_context *dst, + const mbedtls_sha256_context *src ); + /** * \brief SHA-256 context setup * diff --git a/include/mbedtls/sha512.h b/include/mbedtls/sha512.h index 6b09a485f..7e1bc1e33 100644 --- a/include/mbedtls/sha512.h +++ b/include/mbedtls/sha512.h @@ -67,6 +67,15 @@ void mbedtls_sha512_init( mbedtls_sha512_context *ctx ); */ void mbedtls_sha512_free( mbedtls_sha512_context *ctx ); +/** + * \brief Clone (the state of) a SHA-512 context + * + * \param dst The destination context + * \param src The context to be cloned + */ +void mbedtls_sha512_clone( mbedtls_sha512_context *dst, + const mbedtls_sha512_context *src ); + /** * \brief SHA-512 context setup * diff --git a/library/md2.c b/library/md2.c index 5cd024a3d..d1fea1273 100644 --- a/library/md2.c +++ b/library/md2.c @@ -97,6 +97,12 @@ void mbedtls_md2_free( mbedtls_md2_context *ctx ) mbedtls_zeroize( ctx, sizeof( mbedtls_md2_context ) ); } +void mbedtls_md2_clone( mbedtls_md2_context *dst, + const mbedtls_md2_context *src ) +{ + *dst = *src; +} + /* * MD2 context setup */ diff --git a/library/md4.c b/library/md4.c index 90623582a..b71d2c939 100644 --- a/library/md4.c +++ b/library/md4.c @@ -90,6 +90,12 @@ void mbedtls_md4_free( mbedtls_md4_context *ctx ) mbedtls_zeroize( ctx, sizeof( mbedtls_md4_context ) ); } +void mbedtls_md4_clone( mbedtls_md4_context *dst, + const mbedtls_md4_context *src ) +{ + *dst = *src; +} + /* * MD4 context setup */ diff --git a/library/md5.c b/library/md5.c index 599debc47..7c846bed0 100644 --- a/library/md5.c +++ b/library/md5.c @@ -89,6 +89,12 @@ void mbedtls_md5_free( mbedtls_md5_context *ctx ) mbedtls_zeroize( ctx, sizeof( mbedtls_md5_context ) ); } +void mbedtls_md5_clone( mbedtls_md5_context *dst, + const mbedtls_md5_context *src ) +{ + *dst = *src; +} + /* * MD5 context setup */ diff --git a/library/ripemd160.c b/library/ripemd160.c index d8a451daf..ecaeea00a 100644 --- a/library/ripemd160.c +++ b/library/ripemd160.c @@ -88,6 +88,12 @@ void mbedtls_ripemd160_free( mbedtls_ripemd160_context *ctx ) mbedtls_zeroize( ctx, sizeof( mbedtls_ripemd160_context ) ); } +void mbedtls_ripemd160_clone( mbedtls_ripemd160_context *dst, + const mbedtls_ripemd160_context *src ) +{ + *dst = *src; +} + /* * RIPEMD-160 context setup */ diff --git a/library/sha1.c b/library/sha1.c index 9a21bcb2a..7ca83508c 100644 --- a/library/sha1.c +++ b/library/sha1.c @@ -89,6 +89,12 @@ void mbedtls_sha1_free( mbedtls_sha1_context *ctx ) mbedtls_zeroize( ctx, sizeof( mbedtls_sha1_context ) ); } +void mbedtls_sha1_clone( mbedtls_sha1_context *dst, + const mbedtls_sha1_context *src ) +{ + *dst = *src; +} + /* * SHA-1 context setup */ diff --git a/library/sha256.c b/library/sha256.c index cf0b15fad..4b393d05f 100644 --- a/library/sha256.c +++ b/library/sha256.c @@ -89,6 +89,12 @@ void mbedtls_sha256_free( mbedtls_sha256_context *ctx ) mbedtls_zeroize( ctx, sizeof( mbedtls_sha256_context ) ); } +void mbedtls_sha256_clone( mbedtls_sha256_context *dst, + const mbedtls_sha256_context *src ) +{ + *dst = *src; +} + /* * SHA-256 context setup */ diff --git a/library/sha512.c b/library/sha512.c index f09b0f7fe..3daf08089 100644 --- a/library/sha512.c +++ b/library/sha512.c @@ -150,6 +150,12 @@ void mbedtls_sha512_free( mbedtls_sha512_context *ctx ) mbedtls_zeroize( ctx, sizeof( mbedtls_sha512_context ) ); } +void mbedtls_sha512_clone( mbedtls_sha512_context *dst, + const mbedtls_sha512_context *src ) +{ + *dst = *src; +} + /* * SHA-512 context setup */