blob: 3ce72d0c6ed0fc7824df990486caaf1918c49dc2 [file] [log] [blame]
nagendra modaduguc0fe8362016-12-08 14:43:06 -08001// 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/sha384.h"
15
16#include <stdint.h>
17#include <string.h>
18
19#include "cryptoc/sha512.h"
20
21#ifndef SHA512_SUPPORT
22#error "-DSHA512_SUPPORT must be specified to enable SHA-384/512"
23#endif
24
25static const HASH_VTAB SHA384_VTAB = {
26 SHA384_init,
27 SHA512_update,
28 SHA512_final,
29 SHA384_hash,
30 SHA384_DIGEST_SIZE
31};
32
33void SHA384_init(LITE_SHA384_CTX* ctx) {
34 ctx->f = &SHA384_VTAB;
35 ctx->state[0] = 0xcbbb9d5dc1059ed8ll;
36 ctx->state[1] = 0x629a292a367cd507ll;
37 ctx->state[2] = 0x9159015a3070dd17ll;
38 ctx->state[3] = 0x152fecd8f70e5939ll;
39 ctx->state[4] = 0x67332667ffc00b31ll;
40 ctx->state[5] = 0x8eb44a8768581511ll;
41 ctx->state[6] = 0xdb0c2e0d64f98fa7ll;
42 ctx->state[7] = 0x47b5481dbefa4fa4ll;
43 ctx->count = 0;
44}
45
46void SHA384_update(LITE_SHA384_CTX* ctx, const void* data, size_t len) {
47 SHA512_update(ctx, data, len);
48}
49
50const uint8_t* SHA384_final(LITE_SHA384_CTX* ctx) {
51 return SHA512_final(ctx);
52}
53
54const uint8_t* SHA384_hash(const void* data, size_t len, uint8_t* digest) {
55 LITE_SHA384_CTX ctx;
56 SHA384_init(&ctx);
57 SHA384_update(&ctx, data, len);
58 memcpy(digest, SHA384_final(&ctx), SHA384_DIGEST_SIZE);
59 return digest;
60}