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