MeterLogger
sha256.h
Go to the documentation of this file.
1 /**
2  * Copyright (c) 2000-2001 Aaron D. Gifford
3  * Copyright (c) 2013-2014 Pavol Rusnak
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * 3. Neither the name of the copyright holder nor the names of contributors
15  * may be used to endorse or promote products derived from this software
16  * without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  */
30 
31 #ifndef __SHA2_H__
32 #define __SHA2_H__
33 
34 #include <esp8266.h>
35 #include <stdint.h>
36 #include "crypto/crypto.h"
37 
38 #define SHA256_BLOCK_LENGTH 64
39 #define SHA256_DIGEST_LENGTH 32
40 #define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1)
41 
42 typedef struct {
43  uint32_t state[8];
44  uint64_t bitcount;
45  uint8_t buffer[SHA256_BLOCK_LENGTH];
46 } sha256_ctx_t;
47 
49 ICACHE_FLASH_ATTR void sha256_update(sha256_ctx_t *context, uint8_t *data, size_t len);
50 ICACHE_FLASH_ATTR void sha256_final(sha256_ctx_t *context, uint8_t digest[SHA256_DIGEST_LENGTH]);
52 ICACHE_FLASH_ATTR void sha256_raw(uint8_t* data, size_t len, uint8_t digest[SHA256_DIGEST_LENGTH]);
53 ICACHE_FLASH_ATTR char* sha256_data(uint8_t* data, size_t len, char digest[SHA256_DIGEST_STRING_LENGTH]);
54 
55 #endif
ICACHE_FLASH_ATTR void sha256_final(sha256_ctx_t *context, uint8_t digest[SHA256_DIGEST_LENGTH])
Definition: sha256.c:334
ICACHE_FLASH_ATTR void sha256_raw(uint8_t *data, size_t len, uint8_t digest[SHA256_DIGEST_LENGTH])
Definition: sha256.c:421
#define SHA256_DIGEST_STRING_LENGTH
Definition: sha256.h:40
#define SHA256_BLOCK_LENGTH
Definition: sha256.h:38
uint64_t bitcount
Definition: sha256.h:44
#define ICACHE_FLASH_ATTR
Definition: c_types.h:99
ICACHE_FLASH_ATTR void sha256_update(sha256_ctx_t *context, uint8_t *data, size_t len)
Definition: sha256.c:288
static state_t * state
Definition: aes.c:67
ICACHE_FLASH_ATTR char * sha256_end(sha256_ctx_t *context, char buffer[SHA256_DIGEST_STRING_LENGTH])
Definition: sha256.c:399
ICACHE_FLASH_ATTR char * sha256_data(uint8_t *data, size_t len, char digest[SHA256_DIGEST_STRING_LENGTH])
Definition: sha256.c:430
ICACHE_FLASH_ATTR void sha256_init(sha256_ctx_t *context)
Definition: sha256.c:196
#define SHA256_DIGEST_LENGTH
Definition: sha256.h:39