nagendra modadugu | 793cf59 | 2019-10-09 14:07:05 -0700 | [diff] [blame] | 1 | // Copyright 2016 Google Inc. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | #include "cryptoc/sha224.h" |
| 15 | #include "cryptoc/sha256.h" |
| 16 | |
| 17 | #include <string.h> |
| 18 | #include <stdint.h> |
| 19 | |
| 20 | static const HASH_VTAB SHA224_VTAB = { |
| 21 | SHA224_init, |
| 22 | SHA256_update, |
| 23 | SHA256_final, |
| 24 | SHA224_hash, |
| 25 | SHA224_DIGEST_SIZE, |
| 26 | #ifdef SHA512_SUPPORT |
| 27 | SHA224_BLOCK_SIZE, |
| 28 | #endif |
| 29 | }; |
| 30 | |
| 31 | void SHA224_init(LITE_SHA224_CTX* ctx) { |
| 32 | ctx->f = &SHA224_VTAB; |
| 33 | ctx->state[0] = 0xc1059ed8; |
| 34 | ctx->state[1] = 0x367cd507; |
| 35 | ctx->state[2] = 0x3070dd17; |
| 36 | ctx->state[3] = 0xf70e5939; |
| 37 | ctx->state[4] = 0xffc00b31; |
| 38 | ctx->state[5] = 0x68581511; |
| 39 | ctx->state[6] = 0x64f98fa7; |
| 40 | ctx->state[7] = 0xbefa4fa4; |
| 41 | ctx->count = 0; |
| 42 | } |
| 43 | |
| 44 | /* Convenience function */ |
| 45 | const uint8_t* SHA224_hash(const void* data, size_t len, |
| 46 | uint8_t* digest) { |
| 47 | LITE_SHA224_CTX ctx; |
| 48 | SHA224_init(&ctx); |
| 49 | SHA224_update(&ctx, data, len); |
| 50 | memcpy(digest, SHA224_final(&ctx), SHA224_DIGEST_SIZE); |
| 51 | return digest; |
| 52 | } |