forked from adafruit/circuitpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.c
More file actions
26 lines (22 loc) · 843 Bytes
/
__init__.c
File metadata and controls
26 lines (22 loc) · 843 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// This file is part of the CircuitPython project: https://circuitpython.org
//
// SPDX-FileCopyrightText: Copyright (c) 2022 Scott Shawcroft for Adafruit Industries
//
// SPDX-License-Identifier: MIT
#include "shared-bindings/hashlib/__init__.h"
#include "shared-module/hashlib/__init__.h"
#include "mbedtls/ssl.h"
bool common_hal_hashlib_new(hashlib_hash_obj_t *self, const char *algorithm) {
if (strcmp(algorithm, "sha1") == 0) {
self->hash_type = MBEDTLS_SSL_HASH_SHA1;
mbedtls_sha1_init(&self->sha1);
mbedtls_sha1_starts_ret(&self->sha1);
return true;
} else if (strcmp(algorithm, "sha256") == 0) {
self->hash_type = MBEDTLS_SSL_HASH_SHA256;
mbedtls_sha256_init(&self->sha256);
mbedtls_sha256_starts_ret(&self->sha256, 0);
return true;
}
return false;
}