A library for setting up Secure Socket Layer (SSL) connections and verifying remote hosts using certificates. Contains only the source files for mbed platform implementation of the library.
Dependents: HTTPClient-SSL HTTPClient-SSL HTTPClient-SSL HTTPClient-SSL
cyassl/ctaocrypt/blake2-int.h@6:cf58d49e1a86, 2015-03-23 (annotated)
- Committer:
- Mike Fiore
- Date:
- Mon Mar 23 16:51:07 2015 -0500
- Revision:
- 6:cf58d49e1a86
- Parent:
- 0:b86d15c6ba29
fix whitespace in sha512.c
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Vanger | 0:b86d15c6ba29 | 1 | /* |
Vanger | 0:b86d15c6ba29 | 2 | BLAKE2 reference source code package - reference C implementations |
Vanger | 0:b86d15c6ba29 | 3 | |
Vanger | 0:b86d15c6ba29 | 4 | Written in 2012 by Samuel Neves <sneves@dei.uc.pt> |
Vanger | 0:b86d15c6ba29 | 5 | |
Vanger | 0:b86d15c6ba29 | 6 | To the extent possible under law, the author(s) have dedicated all copyright |
Vanger | 0:b86d15c6ba29 | 7 | and related and neighboring rights to this software to the public domain |
Vanger | 0:b86d15c6ba29 | 8 | worldwide. This software is distributed without any warranty. |
Vanger | 0:b86d15c6ba29 | 9 | |
Vanger | 0:b86d15c6ba29 | 10 | You should have received a copy of the CC0 Public Domain Dedication along with |
Vanger | 0:b86d15c6ba29 | 11 | this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>. |
Vanger | 0:b86d15c6ba29 | 12 | */ |
Vanger | 0:b86d15c6ba29 | 13 | /* blake2-int.h |
Vanger | 0:b86d15c6ba29 | 14 | * |
Vanger | 0:b86d15c6ba29 | 15 | * Copyright (C) 2006-2014 wolfSSL Inc. |
Vanger | 0:b86d15c6ba29 | 16 | * |
Vanger | 0:b86d15c6ba29 | 17 | * This file is part of CyaSSL. |
Vanger | 0:b86d15c6ba29 | 18 | * |
Vanger | 0:b86d15c6ba29 | 19 | * CyaSSL is free software; you can redistribute it and/or modify |
Vanger | 0:b86d15c6ba29 | 20 | * it under the terms of the GNU General Public License as published by |
Vanger | 0:b86d15c6ba29 | 21 | * the Free Software Foundation; either version 2 of the License, or |
Vanger | 0:b86d15c6ba29 | 22 | * (at your option) any later version. |
Vanger | 0:b86d15c6ba29 | 23 | * |
Vanger | 0:b86d15c6ba29 | 24 | * CyaSSL is distributed in the hope that it will be useful, |
Vanger | 0:b86d15c6ba29 | 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
Vanger | 0:b86d15c6ba29 | 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Vanger | 0:b86d15c6ba29 | 27 | * GNU General Public License for more details. |
Vanger | 0:b86d15c6ba29 | 28 | * |
Vanger | 0:b86d15c6ba29 | 29 | * You should have received a copy of the GNU General Public License |
Vanger | 0:b86d15c6ba29 | 30 | * along with this program; if not, write to the Free Software |
Vanger | 0:b86d15c6ba29 | 31 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
Vanger | 0:b86d15c6ba29 | 32 | */ |
Vanger | 0:b86d15c6ba29 | 33 | |
Vanger | 0:b86d15c6ba29 | 34 | |
Vanger | 0:b86d15c6ba29 | 35 | |
Vanger | 0:b86d15c6ba29 | 36 | #ifndef CTAOCRYPT_BLAKE2_INT_H |
Vanger | 0:b86d15c6ba29 | 37 | #define CTAOCRYPT_BLAKE2_INT_H |
Vanger | 0:b86d15c6ba29 | 38 | |
Vanger | 0:b86d15c6ba29 | 39 | #include <cyassl/ctaocrypt/types.h> |
Vanger | 0:b86d15c6ba29 | 40 | |
Vanger | 0:b86d15c6ba29 | 41 | |
Vanger | 0:b86d15c6ba29 | 42 | #if defined(_MSC_VER) |
Vanger | 0:b86d15c6ba29 | 43 | #define ALIGN(x) __declspec(align(x)) |
Vanger | 0:b86d15c6ba29 | 44 | #elif defined(__GNUC__) |
Vanger | 0:b86d15c6ba29 | 45 | #define ALIGN(x) __attribute__((aligned(x))) |
Vanger | 0:b86d15c6ba29 | 46 | #else |
Vanger | 0:b86d15c6ba29 | 47 | #define ALIGN(x) |
Vanger | 0:b86d15c6ba29 | 48 | #endif |
Vanger | 0:b86d15c6ba29 | 49 | |
Vanger | 0:b86d15c6ba29 | 50 | |
Vanger | 0:b86d15c6ba29 | 51 | #if defined(__cplusplus) |
Vanger | 0:b86d15c6ba29 | 52 | extern "C" { |
Vanger | 0:b86d15c6ba29 | 53 | #endif |
Vanger | 0:b86d15c6ba29 | 54 | |
Vanger | 0:b86d15c6ba29 | 55 | enum blake2s_constant |
Vanger | 0:b86d15c6ba29 | 56 | { |
Vanger | 0:b86d15c6ba29 | 57 | BLAKE2S_BLOCKBYTES = 64, |
Vanger | 0:b86d15c6ba29 | 58 | BLAKE2S_OUTBYTES = 32, |
Vanger | 0:b86d15c6ba29 | 59 | BLAKE2S_KEYBYTES = 32, |
Vanger | 0:b86d15c6ba29 | 60 | BLAKE2S_SALTBYTES = 8, |
Vanger | 0:b86d15c6ba29 | 61 | BLAKE2S_PERSONALBYTES = 8 |
Vanger | 0:b86d15c6ba29 | 62 | }; |
Vanger | 0:b86d15c6ba29 | 63 | |
Vanger | 0:b86d15c6ba29 | 64 | enum blake2b_constant |
Vanger | 0:b86d15c6ba29 | 65 | { |
Vanger | 0:b86d15c6ba29 | 66 | BLAKE2B_BLOCKBYTES = 128, |
Vanger | 0:b86d15c6ba29 | 67 | BLAKE2B_OUTBYTES = 64, |
Vanger | 0:b86d15c6ba29 | 68 | BLAKE2B_KEYBYTES = 64, |
Vanger | 0:b86d15c6ba29 | 69 | BLAKE2B_SALTBYTES = 16, |
Vanger | 0:b86d15c6ba29 | 70 | BLAKE2B_PERSONALBYTES = 16 |
Vanger | 0:b86d15c6ba29 | 71 | }; |
Vanger | 0:b86d15c6ba29 | 72 | |
Vanger | 0:b86d15c6ba29 | 73 | #pragma pack(push, 1) |
Vanger | 0:b86d15c6ba29 | 74 | typedef struct __blake2s_param |
Vanger | 0:b86d15c6ba29 | 75 | { |
Vanger | 0:b86d15c6ba29 | 76 | byte digest_length; /* 1 */ |
Vanger | 0:b86d15c6ba29 | 77 | byte key_length; /* 2 */ |
Vanger | 0:b86d15c6ba29 | 78 | byte fanout; /* 3 */ |
Vanger | 0:b86d15c6ba29 | 79 | byte depth; /* 4 */ |
Vanger | 0:b86d15c6ba29 | 80 | word32 leaf_length; /* 8 */ |
Vanger | 0:b86d15c6ba29 | 81 | byte node_offset[6];/* 14 */ |
Vanger | 0:b86d15c6ba29 | 82 | byte node_depth; /* 15 */ |
Vanger | 0:b86d15c6ba29 | 83 | byte inner_length; /* 16 */ |
Vanger | 0:b86d15c6ba29 | 84 | /* byte reserved[0]; */ |
Vanger | 0:b86d15c6ba29 | 85 | byte salt[BLAKE2B_SALTBYTES]; /* 24 */ |
Vanger | 0:b86d15c6ba29 | 86 | byte personal[BLAKE2S_PERSONALBYTES]; /* 32 */ |
Vanger | 0:b86d15c6ba29 | 87 | } blake2s_param; |
Vanger | 0:b86d15c6ba29 | 88 | |
Vanger | 0:b86d15c6ba29 | 89 | ALIGN( 64 ) typedef struct __blake2s_state |
Vanger | 0:b86d15c6ba29 | 90 | { |
Vanger | 0:b86d15c6ba29 | 91 | word32 h[8]; |
Vanger | 0:b86d15c6ba29 | 92 | word32 t[2]; |
Vanger | 0:b86d15c6ba29 | 93 | word32 f[2]; |
Vanger | 0:b86d15c6ba29 | 94 | byte buf[2 * BLAKE2S_BLOCKBYTES]; |
Vanger | 0:b86d15c6ba29 | 95 | word64 buflen; |
Vanger | 0:b86d15c6ba29 | 96 | byte last_node; |
Vanger | 0:b86d15c6ba29 | 97 | } blake2s_state ; |
Vanger | 0:b86d15c6ba29 | 98 | |
Vanger | 0:b86d15c6ba29 | 99 | typedef struct __blake2b_param |
Vanger | 0:b86d15c6ba29 | 100 | { |
Vanger | 0:b86d15c6ba29 | 101 | byte digest_length; /* 1 */ |
Vanger | 0:b86d15c6ba29 | 102 | byte key_length; /* 2 */ |
Vanger | 0:b86d15c6ba29 | 103 | byte fanout; /* 3 */ |
Vanger | 0:b86d15c6ba29 | 104 | byte depth; /* 4 */ |
Vanger | 0:b86d15c6ba29 | 105 | word32 leaf_length; /* 8 */ |
Vanger | 0:b86d15c6ba29 | 106 | word64 node_offset; /* 16 */ |
Vanger | 0:b86d15c6ba29 | 107 | byte node_depth; /* 17 */ |
Vanger | 0:b86d15c6ba29 | 108 | byte inner_length; /* 18 */ |
Vanger | 0:b86d15c6ba29 | 109 | byte reserved[14]; /* 32 */ |
Vanger | 0:b86d15c6ba29 | 110 | byte salt[BLAKE2B_SALTBYTES]; /* 48 */ |
Vanger | 0:b86d15c6ba29 | 111 | byte personal[BLAKE2B_PERSONALBYTES]; /* 64 */ |
Vanger | 0:b86d15c6ba29 | 112 | } blake2b_param; |
Vanger | 0:b86d15c6ba29 | 113 | |
Vanger | 0:b86d15c6ba29 | 114 | ALIGN( 64 ) typedef struct __blake2b_state |
Vanger | 0:b86d15c6ba29 | 115 | { |
Vanger | 0:b86d15c6ba29 | 116 | word64 h[8]; |
Vanger | 0:b86d15c6ba29 | 117 | word64 t[2]; |
Vanger | 0:b86d15c6ba29 | 118 | word64 f[2]; |
Vanger | 0:b86d15c6ba29 | 119 | byte buf[2 * BLAKE2B_BLOCKBYTES]; |
Vanger | 0:b86d15c6ba29 | 120 | word64 buflen; |
Vanger | 0:b86d15c6ba29 | 121 | byte last_node; |
Vanger | 0:b86d15c6ba29 | 122 | } blake2b_state; |
Vanger | 0:b86d15c6ba29 | 123 | |
Vanger | 0:b86d15c6ba29 | 124 | typedef struct __blake2sp_state |
Vanger | 0:b86d15c6ba29 | 125 | { |
Vanger | 0:b86d15c6ba29 | 126 | blake2s_state S[8][1]; |
Vanger | 0:b86d15c6ba29 | 127 | blake2s_state R[1]; |
Vanger | 0:b86d15c6ba29 | 128 | byte buf[8 * BLAKE2S_BLOCKBYTES]; |
Vanger | 0:b86d15c6ba29 | 129 | word64 buflen; |
Vanger | 0:b86d15c6ba29 | 130 | } blake2sp_state; |
Vanger | 0:b86d15c6ba29 | 131 | |
Vanger | 0:b86d15c6ba29 | 132 | typedef struct __blake2bp_state |
Vanger | 0:b86d15c6ba29 | 133 | { |
Vanger | 0:b86d15c6ba29 | 134 | blake2b_state S[4][1]; |
Vanger | 0:b86d15c6ba29 | 135 | blake2b_state R[1]; |
Vanger | 0:b86d15c6ba29 | 136 | byte buf[4 * BLAKE2B_BLOCKBYTES]; |
Vanger | 0:b86d15c6ba29 | 137 | word64 buflen; |
Vanger | 0:b86d15c6ba29 | 138 | } blake2bp_state; |
Vanger | 0:b86d15c6ba29 | 139 | #pragma pack(pop) |
Vanger | 0:b86d15c6ba29 | 140 | |
Vanger | 0:b86d15c6ba29 | 141 | /* Streaming API */ |
Vanger | 0:b86d15c6ba29 | 142 | int blake2s_init( blake2s_state *S, const byte outlen ); |
Vanger | 0:b86d15c6ba29 | 143 | int blake2s_init_key( blake2s_state *S, const byte outlen, const void *key, const byte keylen ); |
Vanger | 0:b86d15c6ba29 | 144 | int blake2s_init_param( blake2s_state *S, const blake2s_param *P ); |
Vanger | 0:b86d15c6ba29 | 145 | int blake2s_update( blake2s_state *S, const byte *in, word64 inlen ); |
Vanger | 0:b86d15c6ba29 | 146 | int blake2s_final( blake2s_state *S, byte *out, byte outlen ); |
Vanger | 0:b86d15c6ba29 | 147 | |
Vanger | 0:b86d15c6ba29 | 148 | int blake2b_init( blake2b_state *S, const byte outlen ); |
Vanger | 0:b86d15c6ba29 | 149 | int blake2b_init_key( blake2b_state *S, const byte outlen, const void *key, const byte keylen ); |
Vanger | 0:b86d15c6ba29 | 150 | int blake2b_init_param( blake2b_state *S, const blake2b_param *P ); |
Vanger | 0:b86d15c6ba29 | 151 | int blake2b_update( blake2b_state *S, const byte *in, word64 inlen ); |
Vanger | 0:b86d15c6ba29 | 152 | int blake2b_final( blake2b_state *S, byte *out, byte outlen ); |
Vanger | 0:b86d15c6ba29 | 153 | |
Vanger | 0:b86d15c6ba29 | 154 | int blake2sp_init( blake2sp_state *S, const byte outlen ); |
Vanger | 0:b86d15c6ba29 | 155 | int blake2sp_init_key( blake2sp_state *S, const byte outlen, const void *key, const byte keylen ); |
Vanger | 0:b86d15c6ba29 | 156 | int blake2sp_update( blake2sp_state *S, const byte *in, word64 inlen ); |
Vanger | 0:b86d15c6ba29 | 157 | int blake2sp_final( blake2sp_state *S, byte *out, byte outlen ); |
Vanger | 0:b86d15c6ba29 | 158 | |
Vanger | 0:b86d15c6ba29 | 159 | int blake2bp_init( blake2bp_state *S, const byte outlen ); |
Vanger | 0:b86d15c6ba29 | 160 | int blake2bp_init_key( blake2bp_state *S, const byte outlen, const void *key, const byte keylen ); |
Vanger | 0:b86d15c6ba29 | 161 | int blake2bp_update( blake2bp_state *S, const byte *in, word64 inlen ); |
Vanger | 0:b86d15c6ba29 | 162 | int blake2bp_final( blake2bp_state *S, byte *out, byte outlen ); |
Vanger | 0:b86d15c6ba29 | 163 | |
Vanger | 0:b86d15c6ba29 | 164 | /* Simple API */ |
Vanger | 0:b86d15c6ba29 | 165 | int blake2s( byte *out, const void *in, const void *key, const byte outlen, const word64 inlen, byte keylen ); |
Vanger | 0:b86d15c6ba29 | 166 | int blake2b( byte *out, const void *in, const void *key, const byte outlen, const word64 inlen, byte keylen ); |
Vanger | 0:b86d15c6ba29 | 167 | |
Vanger | 0:b86d15c6ba29 | 168 | int blake2sp( byte *out, const void *in, const void *key, const byte outlen, const word64 inlen, byte keylen ); |
Vanger | 0:b86d15c6ba29 | 169 | int blake2bp( byte *out, const void *in, const void *key, const byte outlen, const word64 inlen, byte keylen ); |
Vanger | 0:b86d15c6ba29 | 170 | |
Vanger | 0:b86d15c6ba29 | 171 | static inline int blake2( byte *out, const void *in, const void *key, const byte outlen, const word64 inlen, byte keylen ) |
Vanger | 0:b86d15c6ba29 | 172 | { |
Vanger | 0:b86d15c6ba29 | 173 | return blake2b( out, in, key, outlen, inlen, keylen ); |
Vanger | 0:b86d15c6ba29 | 174 | } |
Vanger | 0:b86d15c6ba29 | 175 | |
Vanger | 0:b86d15c6ba29 | 176 | |
Vanger | 0:b86d15c6ba29 | 177 | |
Vanger | 0:b86d15c6ba29 | 178 | #if defined(__cplusplus) |
Vanger | 0:b86d15c6ba29 | 179 | } |
Vanger | 0:b86d15c6ba29 | 180 | #endif |
Vanger | 0:b86d15c6ba29 | 181 | |
Vanger | 0:b86d15c6ba29 | 182 | #endif /* CTAOCRYPT_BLAKE2_INT_H */ |
Vanger | 0:b86d15c6ba29 | 183 |