1 // Copyright 2020 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13
14 #include <stdio.h>
15 #include <string.h>
16 #include "mbedtls/md5.h"
17 #include "mbedtls/platform_util.h"
18
19 #if defined(MBEDTLS_MD5_ALT)
20 #include "md/esp_md.h"
21
esp_md5_finish_ret(mbedtls_md5_context * ctx,unsigned char output[16])22 int esp_md5_finish_ret( mbedtls_md5_context *ctx, unsigned char output[16] )
23 {
24 esp_rom_md5_final(output, ctx);
25
26 return 0;
27 }
28
esp_md5_update_ret(mbedtls_md5_context * ctx,const unsigned char * input,size_t ilen)29 int esp_md5_update_ret( mbedtls_md5_context *ctx, const unsigned char *input, size_t ilen )
30 {
31 esp_rom_md5_update(ctx, input, ilen);
32
33 return 0;
34 }
35
esp_md5_init_ret(mbedtls_md5_context * ctx)36 int esp_md5_init_ret( mbedtls_md5_context *ctx )
37 {
38 esp_rom_md5_init(ctx);
39
40 return 0;
41 }
42
esp_md5_finish(mbedtls_md5_context * ctx,unsigned char output[16])43 void esp_md5_finish( mbedtls_md5_context *ctx, unsigned char output[16] )
44 {
45 esp_md5_finish_ret(ctx, output);
46 }
47
esp_md5_update(mbedtls_md5_context * ctx,const unsigned char * input,size_t ilen)48 void esp_md5_update( mbedtls_md5_context *ctx, const unsigned char *input, size_t ilen )
49 {
50 esp_md5_update_ret(ctx, input, ilen);
51 }
52
esp_md5_init(mbedtls_md5_context * ctx)53 void esp_md5_init( mbedtls_md5_context *ctx )
54 {
55 esp_md5_init_ret(ctx);
56 }
57
esp_md5_free(mbedtls_md5_context * ctx)58 void esp_md5_free( mbedtls_md5_context *ctx )
59 {
60 if (ctx == NULL) {
61 return;
62 }
63
64 mbedtls_platform_zeroize( ctx, sizeof( mbedtls_md5_context ) );
65 }
66
esp_md5_process(mbedtls_md5_context * ctx,const unsigned char data[64])67 int esp_md5_process( mbedtls_md5_context *ctx, const unsigned char data[64] )
68 {
69 esp_md5_update_ret(ctx, data, 64);
70
71 return 0;
72 }
73
esp_md5_clone(mbedtls_md5_context * dst,const mbedtls_md5_context * src)74 void esp_md5_clone( mbedtls_md5_context *dst, const mbedtls_md5_context *src )
75 {
76 *dst = *src;
77 }
78 #endif
79