v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
sha-256.h
Go to the documentation of this file.
1// Copyright 2022 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Copyright 2013 Google Inc.
6//
7// Licensed under the Apache License, Version 2.0 (the "License");
8// you may not use this file except in compliance with the License.
9// You may obtain a copy of the License at
10//
11// http://www.apache.org/licenses/LICENSE-2.0
12//
13// Unless required by applicable law or agreed to in writing, software
14// distributed under the License is distributed on an "AS IS" BASIS,
15// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16// See the License for the specific language governing permissions and
17// limitations under the License.
18// ========================================================================
19//
20// This code originates from the Omaha installer for Windows:
21// https://github.com/google/omaha
22// The following changes were made:
23// - Combined the hash-internal.h and sha256.h headers together to form
24// this one.
25// - Eliminated conditional definitions related to LITE_EMULATED_64BIT_OPS
26// - Eliminated `extern "C"` definitions as these aren't exported
27// - Eliminated `SHA512_SUPPORT` as we only support SHA256
28// - Eliminated generic `HASH_` definitions as unnecessary
29// - Moved the hashing functions into `namespace v8::internal`
30//
31// This is intended simply to provide a minimal-impact SHA256 hash utility
32// to support the stack trace source hash functionality.
33
34#ifndef V8_UTILS_SHA_256_H_
35#define V8_UTILS_SHA_256_H_
36
37#include <stddef.h>
38#include <stdint.h>
39
40#define LITE_LShiftU64(a, b) ((a) << (b))
41#define LITE_RShiftU64(a, b) ((a) >> (b))
42
43const size_t kSizeOfSha256Digest = 32;
45
46namespace v8 {
47namespace internal {
48
49typedef struct HASH_VTAB {
50 void (*const init)(struct HASH_CTX*);
51 void (*const update)(struct HASH_CTX*, const void*, size_t);
52 const uint8_t* (*const final)(struct HASH_CTX*);
53 const uint8_t* (*const hash)(const void*, size_t, uint8_t*);
54 unsigned int size;
56
57typedef struct HASH_CTX {
58 const HASH_VTAB* f;
59 uint64_t count;
60 uint8_t buf[64];
61 uint32_t state[8]; // upto SHA2-256
63
65
67void SHA256_update(LITE_SHA256_CTX* ctx, const void* data, size_t len);
68const uint8_t* SHA256_final(LITE_SHA256_CTX* ctx);
69
70// Convenience method. Returns digest address.
71const uint8_t* SHA256_hash(const void* data, size_t len, uint8_t* digest);
72
73} // namespace internal
74} // namespace v8
75
76#endif // V8_UTILS_SHA_256_H_
const uint8_t * SHA256_final(LITE_SHA256_CTX *ctx)
Definition sha-256.cc:138
HASH_CTX LITE_SHA256_CTX
Definition sha-256.h:64
struct v8::internal::HASH_VTAB HASH_VTAB
void SHA256_init(LITE_SHA256_CTX *ctx)
Definition sha-256.cc:110
const uint8_t * SHA256_hash(const void *data, size_t len, uint8_t *digest)
Definition sha-256.cc:167
void SHA256_update(LITE_SHA256_CTX *ctx, const void *data, size_t len)
Definition sha-256.cc:123
struct v8::internal::HASH_CTX HASH_CTX
const size_t kSizeOfFormattedSha256Digest
Definition sha-256.h:44
const size_t kSizeOfSha256Digest
Definition sha-256.h:43
const HASH_VTAB * f
Definition sha-256.h:58
uint8_t buf[64]
Definition sha-256.h:60
const uint8_t *(*const hash)(const void *, size_t, uint8_t *)
Definition sha-256.h:53
unsigned int size
Definition sha-256.h:54
void(*const init)(struct HASH_CTX *)
Definition sha-256.h:50