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 // limitations under the License.
14 #ifndef _ESP_TLS_CRYPTO_H
15 #define _ESP_TLS_CRYPTO_H
16 
17 #include <stddef.h>
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 /**
24  * @brief Calculate sha1 sum
25  * esp-tls abstraction for crypto sha1 API, calculates the sha1 sum(digest) of
26  * the data provided in input which is of ilen size and returns
27  * a 20 char sha1 sum
28  * @param[in]   input   Input array
29  * @param[in]   ilen    Length of Input array
30  * @param[out]  output  calculated sha1 sum
31  *
32  * @return
33  * mbedtls stack:-
34  *              - MBEDTLS_ERR_SHA1_BAD_INPUT_DATA   on BAD INPUT.
35  *              -  0 on success.
36  * wolfssl stack:-
37  *              - -1    on failure.
38  *              -  0    on success.
39  */
40 int esp_crypto_sha1(const unsigned char *input,
41                     size_t ilen,
42                     unsigned char output[20]);
43 
44 /**
45  * @brief Do Base64 encode of the src data
46  *
47  * @param[in]   dst   destination buffer
48  * @param[in]   dlen  length of destination buffer
49  * @param[out]  olen  number of bytes written
50  * @param[in]   src   src buffer to be encoded
51  * @param[in]   slen  src buffer len
52  *
53  * @return
54  * mbedtls stack:-
55  *               - MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL  if buffer is of insufficient size.
56  *               -  0   if successful.
57  * wolfssl stack:-
58  *               - <0   on failure.
59  *               -  0   if succcessful.
60  */
61 int esp_crypto_base64_encode(unsigned char *dst, size_t dlen,
62                              size_t *olen, const unsigned char *src,
63                              size_t slen);
64 
65 #ifdef __cplusplus
66 }
67 #endif
68 #endif /* _ESP_TLS_CRYPTO_H */
69