| 1 | /*- |
| 2 | * Copyright 2005-2016 Colin Percival |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 24 | * SUCH DAMAGE. |
| 25 | */ |
| 26 | |
| 27 | #ifndef _SHA256_H_ |
| 28 | #define _SHA256_H_cxx . . $ `lib/alg-sha256.h:28:9`! |
| 29 | |
| 30 | #include "crypt-port.h"cxx . . $ `<file>/lib/crypt-port.h`/ |
| 31 | |
| 32 | #include <stddef.h> |
| 33 | #include <stdint.h> |
| 34 | |
| 35 | /* |
| 36 | * Use #defines in order to avoid namespace collisions with anyone else's |
| 37 | * SHA256 code (e.g., the code in OpenSSL). |
| 38 | */ |
| 39 | #define SHA256_Initcxx . . $ `lib/alg-sha256.h:39:9`! libcperciva_SHA256_Initcxx . . $ `lib/crypt-port.h:400:9`! |
| 40 | #define SHA256_Updatecxx . . $ `lib/alg-sha256.h:40:9`! libcperciva_SHA256_Updatecxx . . $ `lib/crypt-port.h:401:9`! |
| 41 | #define SHA256_Finalcxx . . $ `lib/alg-sha256.h:41:9`! libcperciva_SHA256_Finalcxx . . $ `lib/crypt-port.h:402:9`! |
| 42 | #define SHA256_Bufcxx . . $ `lib/alg-sha256.h:42:9`! libcperciva_SHA256_Bufcxx . . $ `lib/crypt-port.h:403:9`! |
| 43 | #define SHA256_CTXcxx . . $ `lib/alg-sha256.h:43:9`! libcperciva_SHA256_CTX |
| 44 | #define HMAC_SHA256_Initcxx . . $ `lib/alg-sha256.h:44:9`! libcperciva_HMAC_SHA256_Initcxx . . $ `lib/crypt-port.h:392:9`! |
| 45 | #define HMAC_SHA256_Updatecxx . . $ `lib/alg-sha256.h:45:9`! libcperciva_HMAC_SHA256_Updatecxx . . $ `lib/crypt-port.h:393:9`! |
| 46 | #define HMAC_SHA256_Finalcxx . . $ `lib/alg-sha256.h:46:9`! libcperciva_HMAC_SHA256_Finalcxx . . $ `lib/crypt-port.h:394:9`! |
| 47 | #define HMAC_SHA256_Bufcxx . . $ `lib/alg-sha256.h:47:9`! libcperciva_HMAC_SHA256_Bufcxx . . $ `lib/crypt-port.h:395:9`! |
| 48 | #define HMAC_SHA256_CTXcxx . . $ `lib/alg-sha256.h:48:9`! libcperciva_HMAC_SHA256_CTX |
| 49 | |
| 50 | /* Context structure for SHA256 operations. */ |
| 51 | typedef structcxx . . $ $anonymous_type_ab29d8db97f036de_0# { |
| 52 | uint32_tcxx . . $ uint32_t# statecxx . . $ $anonymous_type_ab29d8db97f036de_0#state.[8]; |
| 53 | uint64_tcxx . . $ uint64_t# countcxx . . $ $anonymous_type_ab29d8db97f036de_0#count.; |
| 54 | uint8_tcxx . . $ uint8_t# bufcxx . . $ $anonymous_type_ab29d8db97f036de_0#buf.[64]; |
| 55 | } SHA256_CTXcxx . . $ `lib/alg-sha256.h:43:9`!; |
| 56 | |
| 57 | /** |
| 58 | * SHA256_Init(ctx): |
| 59 | * Initialize the SHA256 context ${ctx}. |
| 60 | */ |
| 61 | extern void SHA256_Initcxx . . $ `lib/alg-sha256.h:39:9`!(SHA256_CTXcxx . . $ `lib/alg-sha256.h:43:9`! *); |
| 62 | |
| 63 | /** |
| 64 | * SHA256_Update(ctx, in, len): |
| 65 | * Input ${len} bytes from ${in} into the SHA256 context ${ctx}. |
| 66 | */ |
| 67 | extern void SHA256_Updatecxx . . $ `lib/alg-sha256.h:40:9`!(SHA256_CTXcxx . . $ `lib/alg-sha256.h:43:9`! *, const void *, size_t); |
| 68 | |
| 69 | /** |
| 70 | * SHA256_Final(digest, ctx): |
| 71 | * Output the SHA256 hash of the data input to the context ${ctx} into the |
| 72 | * buffer ${digest}. |
| 73 | */ |
| 74 | extern void SHA256_Finalcxx . . $ `lib/alg-sha256.h:41:9`!(uint8_tcxx . . $ uint8_t#[32], SHA256_CTXcxx . . $ `lib/alg-sha256.h:43:9`! *); |
| 75 | |
| 76 | /** |
| 77 | * SHA256_Buf(in, len, digest): |
| 78 | * Compute the SHA256 hash of ${len} bytes from ${in} and write it to ${digest}. |
| 79 | */ |
| 80 | extern void SHA256_Bufcxx . . $ `lib/alg-sha256.h:42:9`!(const void *, size_t, uint8_tcxx . . $ uint8_t#[32]); |
| 81 | |
| 82 | /* Context structure for HMAC-SHA256 operations. */ |
| 83 | typedef structcxx . . $ $anonymous_type_ab29d8db97f036de_1# { |
| 84 | SHA256_CTXcxx . . $ `lib/alg-sha256.h:43:9`! ictxcxx . . $ $anonymous_type_ab29d8db97f036de_1#ictx.; |
| 85 | SHA256_CTXcxx . . $ `lib/alg-sha256.h:43:9`! octxcxx . . $ $anonymous_type_ab29d8db97f036de_1#octx.; |
| 86 | } HMAC_SHA256_CTXcxx . . $ `lib/alg-sha256.h:48:9`!; |
| 87 | |
| 88 | /** |
| 89 | * HMAC_SHA256_Init(ctx, K, Klen): |
| 90 | * Initialize the HMAC-SHA256 context ${ctx} with ${Klen} bytes of key from |
| 91 | * ${K}. |
| 92 | */ |
| 93 | extern void HMAC_SHA256_Initcxx . . $ `lib/alg-sha256.h:44:9`!(HMAC_SHA256_CTXcxx . . $ `lib/alg-sha256.h:48:9`! *, const void *, size_t); |
| 94 | |
| 95 | /** |
| 96 | * HMAC_SHA256_Update(ctx, in, len): |
| 97 | * Input ${len} bytes from ${in} into the HMAC-SHA256 context ${ctx}. |
| 98 | */ |
| 99 | extern void HMAC_SHA256_Updatecxx . . $ `lib/alg-sha256.h:45:9`!(HMAC_SHA256_CTXcxx . . $ `lib/alg-sha256.h:48:9`! *, const void *, size_t); |
| 100 | |
| 101 | /** |
| 102 | * HMAC_SHA256_Final(digest, ctx): |
| 103 | * Output the HMAC-SHA256 of the data input to the context ${ctx} into the |
| 104 | * buffer ${digest}. |
| 105 | */ |
| 106 | extern void HMAC_SHA256_Finalcxx . . $ `lib/alg-sha256.h:46:9`!(uint8_tcxx . . $ uint8_t#[32], HMAC_SHA256_CTXcxx . . $ `lib/alg-sha256.h:48:9`! *); |
| 107 | |
| 108 | /** |
| 109 | * HMAC_SHA256_Buf(K, Klen, in, len, digest): |
| 110 | * Compute the HMAC-SHA256 of ${len} bytes from ${in} using the key ${K} of |
| 111 | * length ${Klen}, and write the result to ${digest}. |
| 112 | */ |
| 113 | extern void HMAC_SHA256_Bufcxx . . $ `lib/alg-sha256.h:47:9`!(const void *, size_t, const void *, size_t, uint8_tcxx . . $ uint8_t#[32]); |
| 114 | |
| 115 | /** |
| 116 | * PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, c, buf, dkLen): |
| 117 | * Compute PBKDF2(passwd, salt, c, dkLen) using HMAC-SHA256 as the PRF, and |
| 118 | * write the output to buf. The value dkLen must be at most 32 * (2^32 - 1). |
| 119 | */ |
| 120 | extern void PBKDF2_SHA256cxx . . $ `lib/crypt-port.h:376:9`!(const uint8_tcxx . . $ uint8_t# *, size_t, const uint8_tcxx . . $ uint8_t# *, size_t, |
| 121 | uint64_tcxx . . $ uint64_t#, uint8_tcxx . . $ uint8_t# *, size_t); |
| 122 | |
| 123 | #endif /* !_SHA256_H_ */ |