xref: /freebsd/sys/crypto/openssl/ossl_sha1.c (revision ec0ea6efa1ad229d75c394c1a9b9cac33af2b1d3)
1 /*
2  * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the OpenSSL license (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 #include <sys/cdefs.h>
11 __FBSDID("$FreeBSD$");
12 
13 #include <sys/libkern.h>
14 #include <sys/malloc.h>
15 
16 #include <opencrypto/cryptodev.h>
17 #include <opencrypto/xform_auth.h>
18 
19 #include <crypto/openssl/ossl.h>
20 #include <crypto/openssl/ossl_sha.h>
21 
22 /* sha1-x86_64.S */
23 void sha1_block_data_order(SHA_CTX *c, const void *p, size_t len);
24 
25 /* From crypto/sha/sha_local.h */
26 #define DATA_ORDER_IS_BIG_ENDIAN
27 
28 #define HASH_LONG               SHA_LONG
29 #define HASH_CTX                SHA_CTX
30 #define HASH_CBLOCK             SHA_CBLOCK
31 #define HASH_MAKE_STRING(c,s)   do {    \
32         unsigned long ll;               \
33         ll=(c)->h0; (void)HOST_l2c(ll,(s));     \
34         ll=(c)->h1; (void)HOST_l2c(ll,(s));     \
35         ll=(c)->h2; (void)HOST_l2c(ll,(s));     \
36         ll=(c)->h3; (void)HOST_l2c(ll,(s));     \
37         ll=(c)->h4; (void)HOST_l2c(ll,(s));     \
38         } while (0)
39 
40 #define HASH_UPDATE                     ossl_sha1_update
41 #define HASH_FINAL                      ossl_sha1_final
42 #define HASH_INIT                       ossl_sha1_init
43 #define HASH_BLOCK_DATA_ORDER           sha1_block_data_order
44 
45 #define INIT_DATA_h0 0x67452301UL
46 #define INIT_DATA_h1 0xefcdab89UL
47 #define INIT_DATA_h2 0x98badcfeUL
48 #define INIT_DATA_h3 0x10325476UL
49 #define INIT_DATA_h4 0xc3d2e1f0UL
50 
51 static void
52 HASH_INIT(void *c_)
53 {
54     SHA_CTX *c = c_;
55     memset(c, 0, sizeof(*c));
56     c->h0 = INIT_DATA_h0;
57     c->h1 = INIT_DATA_h1;
58     c->h2 = INIT_DATA_h2;
59     c->h3 = INIT_DATA_h3;
60     c->h4 = INIT_DATA_h4;
61 }
62 
63 #include "ossl_hash.h"
64 
65 struct auth_hash ossl_hash_sha1 = {
66 	.type = CRYPTO_SHA1,
67 	.name = "OpenSSL-SHA1",
68 	.hashsize = SHA1_HASH_LEN,
69 	.ctxsize = sizeof(SHA_CTX),
70 	.blocksize = SHA1_BLOCK_LEN,
71 	.Init = HASH_INIT,
72 	.Update = HASH_UPDATE,
73 	.Final = HASH_FINAL,
74 };
75 
76 _Static_assert(sizeof(SHA_CTX) <= sizeof(struct ossl_hash_context),
77     "ossl_hash_context too small");
78