1d4afb5ceSopenharmony_ci/* 2d4afb5ceSopenharmony_ci * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 3d4afb5ceSopenharmony_ci * All rights reserved. 4d4afb5ceSopenharmony_ci * 5d4afb5ceSopenharmony_ci * Redistribution and use in source and binary forms, with or without 6d4afb5ceSopenharmony_ci * modification, are permitted provided that the following conditions 7d4afb5ceSopenharmony_ci * are met: 8d4afb5ceSopenharmony_ci * 1. Redistributions of source code must retain the above copyright 9d4afb5ceSopenharmony_ci * notice, this list of conditions and the following disclaimer. 10d4afb5ceSopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright 11d4afb5ceSopenharmony_ci * notice, this list of conditions and the following disclaimer in the 12d4afb5ceSopenharmony_ci * documentation and/or other materials provided with the distribution. 13d4afb5ceSopenharmony_ci * 3. Neither the name of the project nor the names of its contributors 14d4afb5ceSopenharmony_ci * may be used to endorse or promote products derived from this software 15d4afb5ceSopenharmony_ci * without specific prior written permission. 16d4afb5ceSopenharmony_ci * 17d4afb5ceSopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 18d4afb5ceSopenharmony_ci * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19d4afb5ceSopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20d4afb5ceSopenharmony_ci * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 21d4afb5ceSopenharmony_ci * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22d4afb5ceSopenharmony_ci * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23d4afb5ceSopenharmony_ci * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24d4afb5ceSopenharmony_ci * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25d4afb5ceSopenharmony_ci * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26d4afb5ceSopenharmony_ci * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27d4afb5ceSopenharmony_ci * SUCH DAMAGE. 28d4afb5ceSopenharmony_ci */ 29d4afb5ceSopenharmony_ci/* 30d4afb5ceSopenharmony_ci * FIPS pub 180-1: Secure Hash Algorithm (SHA-1) 31d4afb5ceSopenharmony_ci * based on: http://csrc.nist.gov/fips/fip180-1.txt 32d4afb5ceSopenharmony_ci * implemented by Jun-ichiro itojun Itoh <itojun@itojun.org> 33d4afb5ceSopenharmony_ci */ 34d4afb5ceSopenharmony_ci 35d4afb5ceSopenharmony_ci#include "private-lib-core.h" 36d4afb5ceSopenharmony_ci 37d4afb5ceSopenharmony_ci#ifdef LWS_HAVE_SYS_TYPES_H 38d4afb5ceSopenharmony_ci#include <sys/types.h> 39d4afb5ceSopenharmony_ci#endif 40d4afb5ceSopenharmony_ci 41d4afb5ceSopenharmony_cistruct sha1_ctxt { 42d4afb5ceSopenharmony_ci union { 43d4afb5ceSopenharmony_ci unsigned char b8[20]; 44d4afb5ceSopenharmony_ci unsigned int b32[5]; 45d4afb5ceSopenharmony_ci } h; 46d4afb5ceSopenharmony_ci union { 47d4afb5ceSopenharmony_ci unsigned char b8[8]; 48d4afb5ceSopenharmony_ci uint64_t b64[1]; 49d4afb5ceSopenharmony_ci } c; 50d4afb5ceSopenharmony_ci union { 51d4afb5ceSopenharmony_ci unsigned char b8[64]; 52d4afb5ceSopenharmony_ci unsigned int b32[16]; 53d4afb5ceSopenharmony_ci } m; 54d4afb5ceSopenharmony_ci unsigned char count; 55d4afb5ceSopenharmony_ci}; 56d4afb5ceSopenharmony_ci 57d4afb5ceSopenharmony_ci/* sanity check */ 58d4afb5ceSopenharmony_ci#if !defined(BYTE_ORDER) || !defined(LITTLE_ENDIAN) || !defined(BIG_ENDIAN) 59d4afb5ceSopenharmony_ci# define unsupported 1 60d4afb5ceSopenharmony_ci#elif BYTE_ORDER != BIG_ENDIAN 61d4afb5ceSopenharmony_ci# if BYTE_ORDER != LITTLE_ENDIAN 62d4afb5ceSopenharmony_ci# define unsupported 1 63d4afb5ceSopenharmony_ci# endif 64d4afb5ceSopenharmony_ci#endif 65d4afb5ceSopenharmony_ci 66d4afb5ceSopenharmony_ci#ifndef unsupported 67d4afb5ceSopenharmony_ci 68d4afb5ceSopenharmony_ci/* constant table */ 69d4afb5ceSopenharmony_cistatic const unsigned int _K[] = 70d4afb5ceSopenharmony_ci { 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6 }; 71d4afb5ceSopenharmony_ci#define K(t) _K[(t) / 20] 72d4afb5ceSopenharmony_ci 73d4afb5ceSopenharmony_ci#define F0(b, c, d) (((b) & (c)) | ((~(b)) & (d))) 74d4afb5ceSopenharmony_ci#define F1(b, c, d) (((b) ^ (c)) ^ (d)) 75d4afb5ceSopenharmony_ci#define F2(b, c, d) (((b) & (c)) | ((b) & (d)) | ((c) & (d))) 76d4afb5ceSopenharmony_ci#define F3(b, c, d) (((b) ^ (c)) ^ (d)) 77d4afb5ceSopenharmony_ci 78d4afb5ceSopenharmony_ci#define S(n, x) (((x) << (n)) | ((x) >> (32 - n))) 79d4afb5ceSopenharmony_ci 80d4afb5ceSopenharmony_ci#define H(n) (ctxt->h.b32[(n)]) 81d4afb5ceSopenharmony_ci#define COUNT (ctxt->count) 82d4afb5ceSopenharmony_ci#define BCOUNT (ctxt->c.b64[0] / 8) 83d4afb5ceSopenharmony_ci#define W(n) (ctxt->m.b32[(n)]) 84d4afb5ceSopenharmony_ci 85d4afb5ceSopenharmony_ci#define PUTBYTE(x) { \ 86d4afb5ceSopenharmony_ci ctxt->m.b8[(COUNT % 64)] = (x); \ 87d4afb5ceSopenharmony_ci COUNT++; \ 88d4afb5ceSopenharmony_ci COUNT %= 64; \ 89d4afb5ceSopenharmony_ci ctxt->c.b64[0] += 8; \ 90d4afb5ceSopenharmony_ci if (COUNT % 64 == 0) \ 91d4afb5ceSopenharmony_ci sha1_step(ctxt); \ 92d4afb5ceSopenharmony_ci } 93d4afb5ceSopenharmony_ci 94d4afb5ceSopenharmony_ci#define PUTPAD(x) { \ 95d4afb5ceSopenharmony_ci ctxt->m.b8[(COUNT % 64)] = (x); \ 96d4afb5ceSopenharmony_ci COUNT++; \ 97d4afb5ceSopenharmony_ci COUNT %= 64; \ 98d4afb5ceSopenharmony_ci if (COUNT % 64 == 0) \ 99d4afb5ceSopenharmony_ci sha1_step(ctxt); \ 100d4afb5ceSopenharmony_ci } 101d4afb5ceSopenharmony_ci 102d4afb5ceSopenharmony_ci 103d4afb5ceSopenharmony_cistatic void 104d4afb5ceSopenharmony_cisha1_step(struct sha1_ctxt *ctxt) 105d4afb5ceSopenharmony_ci{ 106d4afb5ceSopenharmony_ci unsigned int a, b, c, d, e, tmp; 107d4afb5ceSopenharmony_ci size_t t, s; 108d4afb5ceSopenharmony_ci 109d4afb5ceSopenharmony_ci#if BYTE_ORDER == LITTLE_ENDIAN 110d4afb5ceSopenharmony_ci struct sha1_ctxt tctxt; 111d4afb5ceSopenharmony_ci 112d4afb5ceSopenharmony_ci memcpy(&tctxt.m.b8[0], &ctxt->m.b8[0], 64); 113d4afb5ceSopenharmony_ci ctxt->m.b8[0] = tctxt.m.b8[3]; ctxt->m.b8[1] = tctxt.m.b8[2]; 114d4afb5ceSopenharmony_ci ctxt->m.b8[2] = tctxt.m.b8[1]; ctxt->m.b8[3] = tctxt.m.b8[0]; 115d4afb5ceSopenharmony_ci ctxt->m.b8[4] = tctxt.m.b8[7]; ctxt->m.b8[5] = tctxt.m.b8[6]; 116d4afb5ceSopenharmony_ci ctxt->m.b8[6] = tctxt.m.b8[5]; ctxt->m.b8[7] = tctxt.m.b8[4]; 117d4afb5ceSopenharmony_ci ctxt->m.b8[8] = tctxt.m.b8[11]; ctxt->m.b8[9] = tctxt.m.b8[10]; 118d4afb5ceSopenharmony_ci ctxt->m.b8[10] = tctxt.m.b8[9]; ctxt->m.b8[11] = tctxt.m.b8[8]; 119d4afb5ceSopenharmony_ci ctxt->m.b8[12] = tctxt.m.b8[15]; ctxt->m.b8[13] = tctxt.m.b8[14]; 120d4afb5ceSopenharmony_ci ctxt->m.b8[14] = tctxt.m.b8[13]; ctxt->m.b8[15] = tctxt.m.b8[12]; 121d4afb5ceSopenharmony_ci ctxt->m.b8[16] = tctxt.m.b8[19]; ctxt->m.b8[17] = tctxt.m.b8[18]; 122d4afb5ceSopenharmony_ci ctxt->m.b8[18] = tctxt.m.b8[17]; ctxt->m.b8[19] = tctxt.m.b8[16]; 123d4afb5ceSopenharmony_ci ctxt->m.b8[20] = tctxt.m.b8[23]; ctxt->m.b8[21] = tctxt.m.b8[22]; 124d4afb5ceSopenharmony_ci ctxt->m.b8[22] = tctxt.m.b8[21]; ctxt->m.b8[23] = tctxt.m.b8[20]; 125d4afb5ceSopenharmony_ci ctxt->m.b8[24] = tctxt.m.b8[27]; ctxt->m.b8[25] = tctxt.m.b8[26]; 126d4afb5ceSopenharmony_ci ctxt->m.b8[26] = tctxt.m.b8[25]; ctxt->m.b8[27] = tctxt.m.b8[24]; 127d4afb5ceSopenharmony_ci ctxt->m.b8[28] = tctxt.m.b8[31]; ctxt->m.b8[29] = tctxt.m.b8[30]; 128d4afb5ceSopenharmony_ci ctxt->m.b8[30] = tctxt.m.b8[29]; ctxt->m.b8[31] = tctxt.m.b8[28]; 129d4afb5ceSopenharmony_ci ctxt->m.b8[32] = tctxt.m.b8[35]; ctxt->m.b8[33] = tctxt.m.b8[34]; 130d4afb5ceSopenharmony_ci ctxt->m.b8[34] = tctxt.m.b8[33]; ctxt->m.b8[35] = tctxt.m.b8[32]; 131d4afb5ceSopenharmony_ci ctxt->m.b8[36] = tctxt.m.b8[39]; ctxt->m.b8[37] = tctxt.m.b8[38]; 132d4afb5ceSopenharmony_ci ctxt->m.b8[38] = tctxt.m.b8[37]; ctxt->m.b8[39] = tctxt.m.b8[36]; 133d4afb5ceSopenharmony_ci ctxt->m.b8[40] = tctxt.m.b8[43]; ctxt->m.b8[41] = tctxt.m.b8[42]; 134d4afb5ceSopenharmony_ci ctxt->m.b8[42] = tctxt.m.b8[41]; ctxt->m.b8[43] = tctxt.m.b8[40]; 135d4afb5ceSopenharmony_ci ctxt->m.b8[44] = tctxt.m.b8[47]; ctxt->m.b8[45] = tctxt.m.b8[46]; 136d4afb5ceSopenharmony_ci ctxt->m.b8[46] = tctxt.m.b8[45]; ctxt->m.b8[47] = tctxt.m.b8[44]; 137d4afb5ceSopenharmony_ci ctxt->m.b8[48] = tctxt.m.b8[51]; ctxt->m.b8[49] = tctxt.m.b8[50]; 138d4afb5ceSopenharmony_ci ctxt->m.b8[50] = tctxt.m.b8[49]; ctxt->m.b8[51] = tctxt.m.b8[48]; 139d4afb5ceSopenharmony_ci ctxt->m.b8[52] = tctxt.m.b8[55]; ctxt->m.b8[53] = tctxt.m.b8[54]; 140d4afb5ceSopenharmony_ci ctxt->m.b8[54] = tctxt.m.b8[53]; ctxt->m.b8[55] = tctxt.m.b8[52]; 141d4afb5ceSopenharmony_ci ctxt->m.b8[56] = tctxt.m.b8[59]; ctxt->m.b8[57] = tctxt.m.b8[58]; 142d4afb5ceSopenharmony_ci ctxt->m.b8[58] = tctxt.m.b8[57]; ctxt->m.b8[59] = tctxt.m.b8[56]; 143d4afb5ceSopenharmony_ci ctxt->m.b8[60] = tctxt.m.b8[63]; ctxt->m.b8[61] = tctxt.m.b8[62]; 144d4afb5ceSopenharmony_ci ctxt->m.b8[62] = tctxt.m.b8[61]; ctxt->m.b8[63] = tctxt.m.b8[60]; 145d4afb5ceSopenharmony_ci#endif 146d4afb5ceSopenharmony_ci 147d4afb5ceSopenharmony_ci a = H(0); b = H(1); c = H(2); d = H(3); e = H(4); 148d4afb5ceSopenharmony_ci 149d4afb5ceSopenharmony_ci for (t = 0; t < 20; t++) { 150d4afb5ceSopenharmony_ci s = t & 0x0f; 151d4afb5ceSopenharmony_ci if (t >= 16) 152d4afb5ceSopenharmony_ci W(s) = S(1, W((s+13) & 0x0f) ^ W((s+8) & 0x0f) ^ 153d4afb5ceSopenharmony_ci W((s+2) & 0x0f) ^ W(s)); 154d4afb5ceSopenharmony_ci 155d4afb5ceSopenharmony_ci tmp = S(5, a) + F0(b, c, d) + e + W(s) + K(t); 156d4afb5ceSopenharmony_ci e = d; d = c; c = S(30, b); b = a; a = tmp; 157d4afb5ceSopenharmony_ci } 158d4afb5ceSopenharmony_ci for (t = 20; t < 40; t++) { 159d4afb5ceSopenharmony_ci s = t & 0x0f; 160d4afb5ceSopenharmony_ci W(s) = S(1, W((s+13) & 0x0f) ^ W((s+8) & 0x0f) ^ 161d4afb5ceSopenharmony_ci W((s+2) & 0x0f) ^ W(s)); 162d4afb5ceSopenharmony_ci tmp = S(5, a) + F1(b, c, d) + e + W(s) + K(t); 163d4afb5ceSopenharmony_ci e = d; d = c; c = S(30, b); b = a; a = tmp; 164d4afb5ceSopenharmony_ci } 165d4afb5ceSopenharmony_ci for (t = 40; t < 60; t++) { 166d4afb5ceSopenharmony_ci s = t & 0x0f; 167d4afb5ceSopenharmony_ci W(s) = S(1, W((s+13) & 0x0f) ^ W((s+8) & 0x0f) ^ 168d4afb5ceSopenharmony_ci W((s+2) & 0x0f) ^ W(s)); 169d4afb5ceSopenharmony_ci tmp = S(5, a) + F2(b, c, d) + e + W(s) + K(t); 170d4afb5ceSopenharmony_ci e = d; d = c; c = S(30, b); b = a; a = tmp; 171d4afb5ceSopenharmony_ci } 172d4afb5ceSopenharmony_ci for (t = 60; t < 80; t++) { 173d4afb5ceSopenharmony_ci s = t & 0x0f; 174d4afb5ceSopenharmony_ci W(s) = S(1, W((s+13) & 0x0f) ^ W((s+8) & 0x0f) ^ 175d4afb5ceSopenharmony_ci W((s+2) & 0x0f) ^ W(s)); 176d4afb5ceSopenharmony_ci tmp = S(5, a) + F3(b, c, d) + e + W(s) + K(t); 177d4afb5ceSopenharmony_ci e = d; d = c; c = S(30, b); b = a; a = tmp; 178d4afb5ceSopenharmony_ci } 179d4afb5ceSopenharmony_ci 180d4afb5ceSopenharmony_ci H(0) = H(0) + a; 181d4afb5ceSopenharmony_ci H(1) = H(1) + b; 182d4afb5ceSopenharmony_ci H(2) = H(2) + c; 183d4afb5ceSopenharmony_ci H(3) = H(3) + d; 184d4afb5ceSopenharmony_ci H(4) = H(4) + e; 185d4afb5ceSopenharmony_ci 186d4afb5ceSopenharmony_ci memset(&ctxt->m.b8[0], 0, 64); 187d4afb5ceSopenharmony_ci} 188d4afb5ceSopenharmony_ci 189d4afb5ceSopenharmony_ci/*------------------------------------------------------------*/ 190d4afb5ceSopenharmony_ci 191d4afb5ceSopenharmony_cistatic void 192d4afb5ceSopenharmony_ci_sha1_init(struct sha1_ctxt *ctxt) 193d4afb5ceSopenharmony_ci{ 194d4afb5ceSopenharmony_ci memset(ctxt, 0, sizeof(struct sha1_ctxt)); 195d4afb5ceSopenharmony_ci H(0) = 0x67452301; 196d4afb5ceSopenharmony_ci H(1) = 0xefcdab89; 197d4afb5ceSopenharmony_ci H(2) = 0x98badcfe; 198d4afb5ceSopenharmony_ci H(3) = 0x10325476; 199d4afb5ceSopenharmony_ci H(4) = 0xc3d2e1f0; 200d4afb5ceSopenharmony_ci} 201d4afb5ceSopenharmony_ci 202d4afb5ceSopenharmony_civoid 203d4afb5ceSopenharmony_cisha1_pad(struct sha1_ctxt *ctxt) 204d4afb5ceSopenharmony_ci{ 205d4afb5ceSopenharmony_ci size_t padlen; /*pad length in bytes*/ 206d4afb5ceSopenharmony_ci size_t padstart; 207d4afb5ceSopenharmony_ci 208d4afb5ceSopenharmony_ci PUTPAD(0x80); 209d4afb5ceSopenharmony_ci 210d4afb5ceSopenharmony_ci padstart = COUNT % 64; 211d4afb5ceSopenharmony_ci padlen = 64 - padstart; 212d4afb5ceSopenharmony_ci if (padlen < 8) { 213d4afb5ceSopenharmony_ci memset(&ctxt->m.b8[padstart], 0, padlen); 214d4afb5ceSopenharmony_ci COUNT = (unsigned char)(COUNT + padlen); 215d4afb5ceSopenharmony_ci COUNT %= 64; 216d4afb5ceSopenharmony_ci sha1_step(ctxt); 217d4afb5ceSopenharmony_ci padstart = COUNT % 64; /* should be 0 */ 218d4afb5ceSopenharmony_ci padlen = 64 - padstart; /* should be 64 */ 219d4afb5ceSopenharmony_ci } 220d4afb5ceSopenharmony_ci memset(&ctxt->m.b8[padstart], 0, padlen - 8); 221d4afb5ceSopenharmony_ci COUNT = (unsigned char)(COUNT + (padlen - 8)); 222d4afb5ceSopenharmony_ci COUNT %= 64; 223d4afb5ceSopenharmony_ci#if BYTE_ORDER == BIG_ENDIAN 224d4afb5ceSopenharmony_ci PUTPAD(ctxt->c.b8[0]); PUTPAD(ctxt->c.b8[1]); 225d4afb5ceSopenharmony_ci PUTPAD(ctxt->c.b8[2]); PUTPAD(ctxt->c.b8[3]); 226d4afb5ceSopenharmony_ci PUTPAD(ctxt->c.b8[4]); PUTPAD(ctxt->c.b8[5]); 227d4afb5ceSopenharmony_ci PUTPAD(ctxt->c.b8[6]); PUTPAD(ctxt->c.b8[7]); 228d4afb5ceSopenharmony_ci#else 229d4afb5ceSopenharmony_ci PUTPAD(ctxt->c.b8[7]); PUTPAD(ctxt->c.b8[6]); 230d4afb5ceSopenharmony_ci PUTPAD(ctxt->c.b8[5]); PUTPAD(ctxt->c.b8[4]); 231d4afb5ceSopenharmony_ci PUTPAD(ctxt->c.b8[3]); PUTPAD(ctxt->c.b8[2]); 232d4afb5ceSopenharmony_ci PUTPAD(ctxt->c.b8[1]); PUTPAD(ctxt->c.b8[0]); 233d4afb5ceSopenharmony_ci#endif 234d4afb5ceSopenharmony_ci} 235d4afb5ceSopenharmony_ci 236d4afb5ceSopenharmony_civoid 237d4afb5ceSopenharmony_cisha1_loop(struct sha1_ctxt *ctxt, const unsigned char *input, size_t len) 238d4afb5ceSopenharmony_ci{ 239d4afb5ceSopenharmony_ci size_t off; 240d4afb5ceSopenharmony_ci 241d4afb5ceSopenharmony_ci off = 0; 242d4afb5ceSopenharmony_ci 243d4afb5ceSopenharmony_ci while (off < len) { 244d4afb5ceSopenharmony_ci size_t gapstart = COUNT % 64, gaplen = 64 - gapstart, 245d4afb5ceSopenharmony_ci copysiz = (gaplen < len - off) ? gaplen : len - off; 246d4afb5ceSopenharmony_ci 247d4afb5ceSopenharmony_ci memcpy(&ctxt->m.b8[gapstart], &input[off], copysiz); 248d4afb5ceSopenharmony_ci COUNT = (unsigned char)(COUNT + copysiz); 249d4afb5ceSopenharmony_ci COUNT %= 64; 250d4afb5ceSopenharmony_ci ctxt->c.b64[0] += copysiz * 8; 251d4afb5ceSopenharmony_ci if (COUNT % 64 == 0) 252d4afb5ceSopenharmony_ci sha1_step(ctxt); 253d4afb5ceSopenharmony_ci off += copysiz; 254d4afb5ceSopenharmony_ci } 255d4afb5ceSopenharmony_ci} 256d4afb5ceSopenharmony_ci 257d4afb5ceSopenharmony_civoid 258d4afb5ceSopenharmony_cisha1_result(struct sha1_ctxt *ctxt, void *digest0) 259d4afb5ceSopenharmony_ci{ 260d4afb5ceSopenharmony_ci unsigned char *digest; 261d4afb5ceSopenharmony_ci 262d4afb5ceSopenharmony_ci digest = (unsigned char *)digest0; 263d4afb5ceSopenharmony_ci sha1_pad(ctxt); 264d4afb5ceSopenharmony_ci#if BYTE_ORDER == BIG_ENDIAN 265d4afb5ceSopenharmony_ci memcpy(digest, &ctxt->h.b8[0], 20); 266d4afb5ceSopenharmony_ci#else 267d4afb5ceSopenharmony_ci digest[0] = ctxt->h.b8[3]; digest[1] = ctxt->h.b8[2]; 268d4afb5ceSopenharmony_ci digest[2] = ctxt->h.b8[1]; digest[3] = ctxt->h.b8[0]; 269d4afb5ceSopenharmony_ci digest[4] = ctxt->h.b8[7]; digest[5] = ctxt->h.b8[6]; 270d4afb5ceSopenharmony_ci digest[6] = ctxt->h.b8[5]; digest[7] = ctxt->h.b8[4]; 271d4afb5ceSopenharmony_ci digest[8] = ctxt->h.b8[11]; digest[9] = ctxt->h.b8[10]; 272d4afb5ceSopenharmony_ci digest[10] = ctxt->h.b8[9]; digest[11] = ctxt->h.b8[8]; 273d4afb5ceSopenharmony_ci digest[12] = ctxt->h.b8[15]; digest[13] = ctxt->h.b8[14]; 274d4afb5ceSopenharmony_ci digest[14] = ctxt->h.b8[13]; digest[15] = ctxt->h.b8[12]; 275d4afb5ceSopenharmony_ci digest[16] = ctxt->h.b8[19]; digest[17] = ctxt->h.b8[18]; 276d4afb5ceSopenharmony_ci digest[18] = ctxt->h.b8[17]; digest[19] = ctxt->h.b8[16]; 277d4afb5ceSopenharmony_ci#endif 278d4afb5ceSopenharmony_ci} 279d4afb5ceSopenharmony_ci 280d4afb5ceSopenharmony_ci/* 281d4afb5ceSopenharmony_ci * This should look and work like the libcrypto implementation 282d4afb5ceSopenharmony_ci */ 283d4afb5ceSopenharmony_ci 284d4afb5ceSopenharmony_ciunsigned char * 285d4afb5ceSopenharmony_cilws_SHA1(const unsigned char *d, size_t n, unsigned char *md) 286d4afb5ceSopenharmony_ci{ 287d4afb5ceSopenharmony_ci struct sha1_ctxt ctx; 288d4afb5ceSopenharmony_ci 289d4afb5ceSopenharmony_ci _sha1_init(&ctx); 290d4afb5ceSopenharmony_ci sha1_loop(&ctx, d, n); 291d4afb5ceSopenharmony_ci sha1_result(&ctx, (void *)md); 292d4afb5ceSopenharmony_ci 293d4afb5ceSopenharmony_ci return md; 294d4afb5ceSopenharmony_ci} 295d4afb5ceSopenharmony_ci 296d4afb5ceSopenharmony_ci#endif /*unsupported*/ 297