Prototype implementation of IKE key exchange via NTRU encryption
[strongswan.git] / src / libstrongswan / plugins / ntru / ntru_crypto / ntru_crypto_sha2.h
1 /******************************************************************************
2 * NTRU Cryptography Reference Source Code
3 * Copyright (c) 2009-2013, by Security Innovation, Inc. All rights reserved.
4 *
5 * ntru_crypto_crypto_sha2.h is a component of ntru-crypto.
6 *
7 * Copyright (C) 2009-2013 Security Innovation
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 *
23 *****************************************************************************/
24
25 /******************************************************************************
26 *
27 * File: ntru_crypto_sha2.h
28 *
29 * Contents: Definitions and declarations for the SHA-256 implementation.
30 *
31 *****************************************************************************/
32
33 #ifndef NTRU_CRYPTO_SHA2_H
34 #define NTRU_CRYPTO_SHA2_H
35
36
37 #include "ntru_crypto_platform.h"
38 #include "ntru_crypto_sha.h"
39
40
41 /*************************
42 * structure definitions *
43 *************************/
44
45 /* SHA-256 context structure */
46
47 typedef struct {
48 uint32_t state[8]; /* chaining state */
49 uint32_t num_bits_hashed[2]; /* number of bits hashed */
50 uint8_t unhashed[64]; /* input data not yet hashed */
51 uint32_t unhashed_len; /* number of bytes of unhashed input data */
52 } NTRU_CRYPTO_SHA2_CTX;
53
54
55 /*************************
56 * function declarations *
57 *************************/
58
59 /* ntru_crypto_sha2()
60 *
61 * This routine provides all operations for a SHA-256 hash,
62 * and the use of SHA-256 for DSA signing and key generation.
63 * It may be used to initialize, update, or complete a message digest,
64 * or any combination of those actions, as determined by the SHA_INIT flag,
65 * the in_len parameter, and the SHA_FINISH flag, respectively.
66 *
67 * When in_len == 0 (no data to hash), the parameter, in, may be NULL.
68 * When the SHA_FINISH flag is not set, the parameter, md, may be NULL.
69 *
70 * Initialization may be standard or use a specified initialization vector,
71 * and is indicated by setting the SHA_INIT flag.
72 * Setting init = NULL specifies standard initialization. Otherwise, init
73 * points to the array of eight alternate initialization 32-bit words.
74 *
75 * The hash operation can be updated with any number of input bytes, including
76 * zero.
77 *
78 * The hash operation can be completed with normal padding or with zero
79 * padding as required for parts of DSA parameter generation, and is indicated
80 * by setting the SHA_FINISH flag. Using zero padding, indicated by setting
81 * the SHA_ZERO_PAD flag, never creates an extra input block because the
82 * bit count is not included in the hashed data.
83 *
84 * Returns SHA_OK on success.
85 * Returns SHA_FAIL with corrupted context.
86 * Returns SHA_BAD_PARAMETER if inappropriate NULL pointers are passed.
87 * Returns SHA_OVERFLOW if more than 2^64 - 1 bytes are hashed.
88 */
89
90 extern uint32_t
91 ntru_crypto_sha2(
92 NTRU_CRYPTO_HASH_ALGID algid, /* in - hash algorithm ID */
93 NTRU_CRYPTO_SHA2_CTX *c, /* in/out - pointer to SHA-2 context */
94 uint32_t const *init, /* in - pointer to alternate */
95 /* initialization - may be NULL */
96 uint8_t const *in, /* in - pointer to input data -
97 may be NULL if in_len == 0 */
98 uint32_t in_len, /* in - number of input data bytes */
99 uint32_t flags, /* in - INIT, FINISH, zero-pad flags */
100 uint8_t *md); /* out - address for message digest -
101 may be NULL if not FINISH */
102
103
104 #endif /* NTRU_CRYPTO_SHA2_H */