]> git.proxmox.com Git - ceph.git/blame - ceph/src/crypto/isa-l/isa-l_crypto/mh_sha1/mh_sha1_update_base.c
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / crypto / isa-l / isa-l_crypto / mh_sha1 / mh_sha1_update_base.c
CommitLineData
7c673cae
FG
1/**********************************************************************
2 Copyright(c) 2011-2016 Intel Corporation All rights reserved.
3
4 Redistribution and use in source and binary forms, with or without
1e59de90 5 modification, are permitted provided that the following conditions
7c673cae
FG
6 are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in
11 the documentation and/or other materials provided with the
12 distribution.
13 * Neither the name of Intel Corporation nor the names of its
14 contributors may be used to endorse or promote products derived
15 from this software without specific prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28**********************************************************************/
29
30/*
31 * mh_sha1_update_base.c contains the prototype of mh_sha1_update_XXX.
32 * Default definitions are base type which generates mh_sha1_update_base.
33 * Other types are generated through different predefined macros by mh_sha1.c.
34 */
35#ifndef MH_SHA1_UPDATE_FUNCTION
36#include "mh_sha1_internal.h"
37#include <string.h>
38
39#define MH_SHA1_UPDATE_FUNCTION mh_sha1_update_base
40#define MH_SHA1_BLOCK_FUNCTION mh_sha1_block_base
41#define MH_SHA1_UPDATE_SLVER
42#endif
43
44int MH_SHA1_UPDATE_FUNCTION(struct mh_sha1_ctx *ctx, const void *buffer, uint32_t len)
45{
46
47 uint8_t *partial_block_buffer;
48 uint64_t partial_block_len;
49 uint64_t num_blocks;
50 uint32_t(*mh_sha1_segs_digests)[HASH_SEGS];
51 uint8_t *aligned_frame_buffer;
52 const uint8_t *input_data = (const uint8_t *)buffer;
53
54 if (ctx == NULL)
55 return MH_SHA1_CTX_ERROR_NULL;
56
57 if (len == 0)
58 return MH_SHA1_CTX_ERROR_NONE;
59
60 partial_block_len = ctx->total_length % MH_SHA1_BLOCK_SIZE;
61 partial_block_buffer = ctx->partial_block_buffer;
62 aligned_frame_buffer = (uint8_t *) ALIGN_64(ctx->frame_buffer);
63 mh_sha1_segs_digests = (uint32_t(*)[HASH_SEGS]) ctx->mh_sha1_interim_digests;
64
65 ctx->total_length += len;
66 // No enough input data for mh_sha1 calculation
67 if (len + partial_block_len < MH_SHA1_BLOCK_SIZE) {
68 memcpy(partial_block_buffer + partial_block_len, input_data, len);
69 return MH_SHA1_CTX_ERROR_NONE;
70 }
71 // mh_sha1 calculation for the previous partial block
72 if (partial_block_len != 0) {
73 memcpy(partial_block_buffer + partial_block_len, input_data,
74 MH_SHA1_BLOCK_SIZE - partial_block_len);
75 //do one_block process
76 MH_SHA1_BLOCK_FUNCTION(partial_block_buffer, mh_sha1_segs_digests,
77 aligned_frame_buffer, 1);
78 input_data += MH_SHA1_BLOCK_SIZE - partial_block_len;
79 len -= MH_SHA1_BLOCK_SIZE - partial_block_len;
80 memset(partial_block_buffer, 0, MH_SHA1_BLOCK_SIZE);
81 }
82 // Calculate mh_sha1 for the current blocks
83 num_blocks = len / MH_SHA1_BLOCK_SIZE;
84 if (num_blocks > 0) {
85 //do num_blocks process
86 MH_SHA1_BLOCK_FUNCTION(input_data, mh_sha1_segs_digests, aligned_frame_buffer,
87 num_blocks);
88 len -= num_blocks * MH_SHA1_BLOCK_SIZE;
89 input_data += num_blocks * MH_SHA1_BLOCK_SIZE;
90 }
91 // Store the partial block
92 if (len != 0) {
93 memcpy(partial_block_buffer, input_data, len);
94 }
95
96 return MH_SHA1_CTX_ERROR_NONE;
97
98}
99
100#ifdef MH_SHA1_UPDATE_SLVER
101struct slver {
102 uint16_t snum;
103 uint8_t ver;
104 uint8_t core;
105};
106
107 // Version info
108struct slver mh_sha1_update_base_slver_0000027a;
109struct slver mh_sha1_update_base_slver = { 0x027a, 0x00, 0x00 };
110#endif