71
71
* a non-zero value.
72
72
* This is currently only used by GCM and ChaCha20+Poly1305.
73
73
*/
74
- static int mbedtls_constant_time_memcmp ( const void * v1 , const void * v2 , size_t len )
74
+ static int mbedtls_constant_time_memcmp ( const void * v1 , const void * v2 ,
75
+ size_t len )
75
76
{
76
77
const unsigned char * p1 = (const unsigned char * ) v1 ;
77
78
const unsigned char * p2 = (const unsigned char * ) v2 ;
@@ -108,7 +109,8 @@ const int *mbedtls_cipher_list( void )
108
109
return ( mbedtls_cipher_supported );
109
110
}
110
111
111
- const mbedtls_cipher_info_t * mbedtls_cipher_info_from_type ( const mbedtls_cipher_type_t cipher_type )
112
+ const mbedtls_cipher_info_t * mbedtls_cipher_info_from_type (
113
+ const mbedtls_cipher_type_t cipher_type )
112
114
{
113
115
const mbedtls_cipher_definition_t * def ;
114
116
@@ -119,7 +121,8 @@ const mbedtls_cipher_info_t *mbedtls_cipher_info_from_type( const mbedtls_cipher
119
121
return ( NULL );
120
122
}
121
123
122
- const mbedtls_cipher_info_t * mbedtls_cipher_info_from_string ( const char * cipher_name )
124
+ const mbedtls_cipher_info_t * mbedtls_cipher_info_from_string (
125
+ const char * cipher_name )
123
126
{
124
127
const mbedtls_cipher_definition_t * def ;
125
128
@@ -133,9 +136,10 @@ const mbedtls_cipher_info_t *mbedtls_cipher_info_from_string( const char *cipher
133
136
return ( NULL );
134
137
}
135
138
136
- const mbedtls_cipher_info_t * mbedtls_cipher_info_from_values ( const mbedtls_cipher_id_t cipher_id ,
137
- int key_bitlen ,
138
- const mbedtls_cipher_mode_t mode )
139
+ const mbedtls_cipher_info_t * mbedtls_cipher_info_from_values (
140
+ const mbedtls_cipher_id_t cipher_id ,
141
+ int key_bitlen ,
142
+ const mbedtls_cipher_mode_t mode )
139
143
{
140
144
const mbedtls_cipher_definition_t * def ;
141
145
@@ -173,7 +177,8 @@ void mbedtls_cipher_free( mbedtls_cipher_context_t *ctx )
173
177
mbedtls_platform_zeroize ( ctx , sizeof (mbedtls_cipher_context_t ) );
174
178
}
175
179
176
- int mbedtls_cipher_setup ( mbedtls_cipher_context_t * ctx , const mbedtls_cipher_info_t * cipher_info )
180
+ int mbedtls_cipher_setup ( mbedtls_cipher_context_t * ctx ,
181
+ const mbedtls_cipher_info_t * cipher_info )
177
182
{
178
183
if ( NULL == cipher_info || NULL == ctx )
179
184
return ( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
@@ -199,8 +204,10 @@ int mbedtls_cipher_setup( mbedtls_cipher_context_t *ctx, const mbedtls_cipher_in
199
204
return ( 0 );
200
205
}
201
206
202
- int mbedtls_cipher_setkey ( mbedtls_cipher_context_t * ctx , const unsigned char * key ,
203
- int key_bitlen , const mbedtls_operation_t operation )
207
+ int mbedtls_cipher_setkey ( mbedtls_cipher_context_t * ctx ,
208
+ const unsigned char * key ,
209
+ int key_bitlen ,
210
+ const mbedtls_operation_t operation )
204
211
{
205
212
if ( NULL == ctx || NULL == ctx -> cipher_info )
206
213
return ( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
@@ -223,12 +230,13 @@ int mbedtls_cipher_setkey( mbedtls_cipher_context_t *ctx, const unsigned char *k
223
230
MBEDTLS_MODE_CTR == ctx -> cipher_info -> mode )
224
231
{
225
232
return ctx -> cipher_info -> base -> setkey_enc_func ( ctx -> cipher_ctx , key ,
226
- ctx -> key_bitlen );
233
+ ctx -> key_bitlen );
227
234
}
228
235
229
236
if ( MBEDTLS_DECRYPT == operation )
230
237
return ctx -> cipher_info -> base -> setkey_dec_func ( ctx -> cipher_ctx , key ,
231
- ctx -> key_bitlen );
238
+ ctx -> key_bitlen );
239
+
232
240
233
241
return ( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
234
242
}
@@ -830,7 +838,8 @@ int mbedtls_cipher_finish( mbedtls_cipher_context_t *ctx,
830
838
}
831
839
832
840
#if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING )
833
- int mbedtls_cipher_set_padding_mode ( mbedtls_cipher_context_t * ctx , mbedtls_cipher_padding_t mode )
841
+ int mbedtls_cipher_set_padding_mode ( mbedtls_cipher_context_t * ctx ,
842
+ mbedtls_cipher_padding_t mode )
834
843
{
835
844
if ( NULL == ctx ||
836
845
MBEDTLS_MODE_CBC != ctx -> cipher_info -> mode )
@@ -889,7 +898,8 @@ int mbedtls_cipher_write_tag( mbedtls_cipher_context_t *ctx,
889
898
890
899
#if defined(MBEDTLS_GCM_C )
891
900
if ( MBEDTLS_MODE_GCM == ctx -> cipher_info -> mode )
892
- return mbedtls_gcm_finish ( (mbedtls_gcm_context * ) ctx -> cipher_ctx , tag , tag_len );
901
+ return ( mbedtls_gcm_finish ( (mbedtls_gcm_context * ) ctx -> cipher_ctx ,
902
+ tag , tag_len ) );
893
903
#endif
894
904
895
905
#if defined(MBEDTLS_CHACHAPOLY_C )
@@ -899,8 +909,8 @@ int mbedtls_cipher_write_tag( mbedtls_cipher_context_t *ctx,
899
909
if ( tag_len != 16U )
900
910
return ( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
901
911
902
- return mbedtls_chachapoly_finish ( ( mbedtls_chachapoly_context * ) ctx -> cipher_ctx ,
903
- tag );
912
+ return ( mbedtls_chachapoly_finish (
913
+ ( mbedtls_chachapoly_context * ) ctx -> cipher_ctx , tag ) );
904
914
}
905
915
#endif
906
916
@@ -925,8 +935,9 @@ int mbedtls_cipher_check_tag( mbedtls_cipher_context_t *ctx,
925
935
if ( tag_len > sizeof ( check_tag ) )
926
936
return ( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
927
937
928
- if ( 0 != ( ret = mbedtls_gcm_finish ( (mbedtls_gcm_context * ) ctx -> cipher_ctx ,
929
- check_tag , tag_len ) ) )
938
+ if ( 0 != ( ret = mbedtls_gcm_finish (
939
+ (mbedtls_gcm_context * ) ctx -> cipher_ctx ,
940
+ check_tag , tag_len ) ) )
930
941
{
931
942
return ( ret );
932
943
}
@@ -946,8 +957,8 @@ int mbedtls_cipher_check_tag( mbedtls_cipher_context_t *ctx,
946
957
if ( tag_len != sizeof ( check_tag ) )
947
958
return ( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
948
959
949
- ret = mbedtls_chachapoly_finish ( ( mbedtls_chachapoly_context * ) ctx -> cipher_ctx ,
950
- check_tag );
960
+ ret = mbedtls_chachapoly_finish (
961
+ ( mbedtls_chachapoly_context * ) ctx -> cipher_ctx , check_tag );
951
962
if ( ret != 0 )
952
963
{
953
964
return ( ret );
@@ -982,10 +993,12 @@ int mbedtls_cipher_crypt( mbedtls_cipher_context_t *ctx,
982
993
if ( ( ret = mbedtls_cipher_reset ( ctx ) ) != 0 )
983
994
return ( ret );
984
995
985
- if ( ( ret = mbedtls_cipher_update ( ctx , input , ilen , output , olen ) ) != 0 )
996
+ if ( ( ret = mbedtls_cipher_update ( ctx , input , ilen ,
997
+ output , olen ) ) != 0 )
986
998
return ( ret );
987
999
988
- if ( ( ret = mbedtls_cipher_finish ( ctx , output + * olen , & finish_olen ) ) != 0 )
1000
+ if ( ( ret = mbedtls_cipher_finish ( ctx , output + * olen ,
1001
+ & finish_olen ) ) != 0 )
989
1002
return ( ret );
990
1003
991
1004
* olen += finish_olen ;
@@ -1008,9 +1021,9 @@ int mbedtls_cipher_auth_encrypt( mbedtls_cipher_context_t *ctx,
1008
1021
if ( MBEDTLS_MODE_GCM == ctx -> cipher_info -> mode )
1009
1022
{
1010
1023
* olen = ilen ;
1011
- return ( mbedtls_gcm_crypt_and_tag ( ctx -> cipher_ctx , MBEDTLS_GCM_ENCRYPT , ilen ,
1012
- iv , iv_len , ad , ad_len , input , output ,
1013
- tag_len , tag ) );
1024
+ return ( mbedtls_gcm_crypt_and_tag ( ctx -> cipher_ctx , MBEDTLS_GCM_ENCRYPT ,
1025
+ ilen , iv , iv_len , ad , ad_len ,
1026
+ input , output , tag_len , tag ) );
1014
1027
}
1015
1028
#endif /* MBEDTLS_GCM_C */
1016
1029
#if defined(MBEDTLS_CCM_C )
0 commit comments