VirtualBox

source: vbox/trunk/src/libs/openssl-3.1.3/crypto/sha/sha1_one.c@ 101211

Last change on this file since 101211 was 101211, checked in by vboxsync, 17 months ago

openssl-3.1.3: Applied and adjusted our OpenSSL changes to 3.1.2. bugref:10527

File size: 2.1 KB
Line 
1/*
2 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10/*
11 * SHA-1 low level APIs are deprecated for public use, but still ok for
12 * internal use.
13 */
14#include "internal/deprecated.h"
15
16#include <stdio.h>
17#include <string.h>
18#include <openssl/crypto.h>
19#include <openssl/sha.h>
20#include <openssl/evp.h>
21#include "crypto/sha.h"
22
23unsigned char *ossl_sha1(const unsigned char *d, size_t n, unsigned char *md)
24{
25 SHA_CTX c;
26 static unsigned char m[SHA_DIGEST_LENGTH];
27
28 if (md == NULL)
29 md = m;
30 if (!SHA1_Init(&c))
31 return NULL;
32 SHA1_Update(&c, d, n);
33 SHA1_Final(md, &c);
34 OPENSSL_cleanse(&c, sizeof(c));
35 return md;
36}
37
38unsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md)
39{
40 static unsigned char m[SHA_DIGEST_LENGTH];
41
42 if (md == NULL)
43 md = m;
44 return EVP_Q_digest(NULL, "SHA1", NULL, d, n, md, NULL) ? md : NULL;
45}
46
47unsigned char *SHA224(const unsigned char *d, size_t n, unsigned char *md)
48{
49 static unsigned char m[SHA224_DIGEST_LENGTH];
50
51 if (md == NULL)
52 md = m;
53 return EVP_Q_digest(NULL, "SHA224", NULL, d, n, md, NULL) ? md : NULL;
54}
55
56unsigned char *SHA256(const unsigned char *d, size_t n, unsigned char *md)
57{
58 static unsigned char m[SHA256_DIGEST_LENGTH];
59
60 if (md == NULL)
61 md = m;
62 return EVP_Q_digest(NULL, "SHA256", NULL, d, n, md, NULL) ? md : NULL;
63}
64
65unsigned char *SHA384(const unsigned char *d, size_t n, unsigned char *md)
66{
67 static unsigned char m[SHA384_DIGEST_LENGTH];
68
69 if (md == NULL)
70 md = m;
71 return EVP_Q_digest(NULL, "SHA384", NULL, d, n, md, NULL) ? md : NULL;
72}
73
74unsigned char *SHA512(const unsigned char *d, size_t n, unsigned char *md)
75{
76 static unsigned char m[SHA512_DIGEST_LENGTH];
77
78 if (md == NULL)
79 md = m;
80 return EVP_Q_digest(NULL, "SHA512", NULL, d, n, md, NULL) ? md : NULL;
81}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette