Contiki-NG
sha256.h
Go to the documentation of this file.
1 /*
2  * Original file:
3  * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
4  * All rights reserved.
5  *
6  * Port to Contiki:
7  * Copyright (c) 2013, ADVANSEE - http://www.advansee.com/
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * 3. Neither the name of the copyright holder nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
32  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
34  * OF THE POSSIBILITY OF SUCH DAMAGE.
35  */
36 /**
37  * \addtogroup cc2538-crypto
38  * @{
39  *
40  * \defgroup cc2538-sha256 cc2538 SHA-256
41  *
42  * Driver for the cc2538 SHA-256 mode of the security core
43  * @{
44  *
45  * \file
46  * Header file for the cc2538 SHA-256 driver
47  */
48 #ifndef SHA256_H_
49 #define SHA256_H_
50 
51 #include "contiki.h"
52 #include "dev/crypto.h"
53 
54 #include <stdint.h>
55 /*---------------------------------------------------------------------------*/
56 /** \name SHA-256 structures
57  * @{
58  */
59 typedef struct {
60  uint64_t length;
61  uint32_t state[8];
62  uint32_t curlen;
63  uint8_t buf[64];
64  uint8_t new_digest;
65  uint8_t final_digest;
66 } sha256_state_t;
67 /** @} */
68 /*---------------------------------------------------------------------------*/
69 /** \name SHA-256 functions
70  * @{
71  */
72 
73 /** \brief Initializes the hash state
74  * \param state Pointer to hash state to initialize
75  * \return \c CRYPTO_SUCCESS if successful, or CRYPTO/SHA256 error code
76  */
77 uint8_t sha256_init(sha256_state_t *state);
78 
79 /** \brief Processes a block of memory through the hash
80  * \param state Pointer to hash state
81  * \param data Pointer to the data to hash
82  * \param len Length of the data to hash in bytes (octets)
83  * \return \c CRYPTO_SUCCESS if successful, or CRYPTO/SHA256 error code
84  * \note This function must be called only after \c sha256_init().
85  */
86 uint8_t sha256_process(sha256_state_t *state, const void *data, uint32_t len);
87 
88 /** \brief Terminates hash session to get the digest
89  * \param state Pointer to hash state
90  * \param hash Pointer to hash
91  * \return \c CRYPTO_SUCCESS if successful, or CRYPTO/SHA256 error code
92  * \note This function must be called only after \c sha256_process().
93  */
94 uint8_t sha256_done(sha256_state_t *state, void *hash);
95 
96 /** @} */
97 
98 #endif /* SHA256_H_ */
99 
100 /**
101  * @}
102  * @}
103  */
Header file for the cc2538 AES/SHA cryptoprocessor driver.
uint8_t sha256_init(sha256_state_t *state)
Initializes the hash state.
Definition: sha256.c:229
uint8_t sha256_process(sha256_state_t *state, const void *data, uint32_t len)
Processes a block of memory through the hash.
Definition: sha256.c:243
uint8_t sha256_done(sha256_state_t *state, void *hash)
Terminates hash session to get the digest.
Definition: sha256.c:320