1e1051a39Sopenharmony_ci/*
2e1051a39Sopenharmony_ci * Copyright 2004-2021 The OpenSSL Project Authors. All Rights Reserved.
3e1051a39Sopenharmony_ci *
4e1051a39Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License").  You may not use
5e1051a39Sopenharmony_ci * this file except in compliance with the License.  You can obtain a copy
6e1051a39Sopenharmony_ci * in the file LICENSE in the source distribution or at
7e1051a39Sopenharmony_ci * https://www.openssl.org/source/license.html
8e1051a39Sopenharmony_ci */
9e1051a39Sopenharmony_ci
10e1051a39Sopenharmony_ci/*
11e1051a39Sopenharmony_ci * SHA256 low level APIs are deprecated for public use, but still ok for
12e1051a39Sopenharmony_ci * internal use.
13e1051a39Sopenharmony_ci */
14e1051a39Sopenharmony_ci#include "internal/deprecated.h"
15e1051a39Sopenharmony_ci
16e1051a39Sopenharmony_ci#include <openssl/opensslconf.h>
17e1051a39Sopenharmony_ci
18e1051a39Sopenharmony_ci#include <stdlib.h>
19e1051a39Sopenharmony_ci#include <string.h>
20e1051a39Sopenharmony_ci
21e1051a39Sopenharmony_ci#include <openssl/crypto.h>
22e1051a39Sopenharmony_ci#include <openssl/sha.h>
23e1051a39Sopenharmony_ci#include <openssl/opensslv.h>
24e1051a39Sopenharmony_ci#include "internal/endian.h"
25e1051a39Sopenharmony_ci
26e1051a39Sopenharmony_ciint SHA224_Init(SHA256_CTX *c)
27e1051a39Sopenharmony_ci{
28e1051a39Sopenharmony_ci    memset(c, 0, sizeof(*c));
29e1051a39Sopenharmony_ci    c->h[0] = 0xc1059ed8UL;
30e1051a39Sopenharmony_ci    c->h[1] = 0x367cd507UL;
31e1051a39Sopenharmony_ci    c->h[2] = 0x3070dd17UL;
32e1051a39Sopenharmony_ci    c->h[3] = 0xf70e5939UL;
33e1051a39Sopenharmony_ci    c->h[4] = 0xffc00b31UL;
34e1051a39Sopenharmony_ci    c->h[5] = 0x68581511UL;
35e1051a39Sopenharmony_ci    c->h[6] = 0x64f98fa7UL;
36e1051a39Sopenharmony_ci    c->h[7] = 0xbefa4fa4UL;
37e1051a39Sopenharmony_ci    c->md_len = SHA224_DIGEST_LENGTH;
38e1051a39Sopenharmony_ci    return 1;
39e1051a39Sopenharmony_ci}
40e1051a39Sopenharmony_ci
41e1051a39Sopenharmony_ciint SHA256_Init(SHA256_CTX *c)
42e1051a39Sopenharmony_ci{
43e1051a39Sopenharmony_ci    memset(c, 0, sizeof(*c));
44e1051a39Sopenharmony_ci    c->h[0] = 0x6a09e667UL;
45e1051a39Sopenharmony_ci    c->h[1] = 0xbb67ae85UL;
46e1051a39Sopenharmony_ci    c->h[2] = 0x3c6ef372UL;
47e1051a39Sopenharmony_ci    c->h[3] = 0xa54ff53aUL;
48e1051a39Sopenharmony_ci    c->h[4] = 0x510e527fUL;
49e1051a39Sopenharmony_ci    c->h[5] = 0x9b05688cUL;
50e1051a39Sopenharmony_ci    c->h[6] = 0x1f83d9abUL;
51e1051a39Sopenharmony_ci    c->h[7] = 0x5be0cd19UL;
52e1051a39Sopenharmony_ci    c->md_len = SHA256_DIGEST_LENGTH;
53e1051a39Sopenharmony_ci    return 1;
54e1051a39Sopenharmony_ci}
55e1051a39Sopenharmony_ci
56e1051a39Sopenharmony_ciint SHA224_Update(SHA256_CTX *c, const void *data, size_t len)
57e1051a39Sopenharmony_ci{
58e1051a39Sopenharmony_ci    return SHA256_Update(c, data, len);
59e1051a39Sopenharmony_ci}
60e1051a39Sopenharmony_ci
61e1051a39Sopenharmony_ciint SHA224_Final(unsigned char *md, SHA256_CTX *c)
62e1051a39Sopenharmony_ci{
63e1051a39Sopenharmony_ci    return SHA256_Final(md, c);
64e1051a39Sopenharmony_ci}
65e1051a39Sopenharmony_ci
66e1051a39Sopenharmony_ci#define DATA_ORDER_IS_BIG_ENDIAN
67e1051a39Sopenharmony_ci
68e1051a39Sopenharmony_ci#define HASH_LONG               SHA_LONG
69e1051a39Sopenharmony_ci#define HASH_CTX                SHA256_CTX
70e1051a39Sopenharmony_ci#define HASH_CBLOCK             SHA_CBLOCK
71e1051a39Sopenharmony_ci
72e1051a39Sopenharmony_ci/*
73e1051a39Sopenharmony_ci * Note that FIPS180-2 discusses "Truncation of the Hash Function Output."
74e1051a39Sopenharmony_ci * default: case below covers for it. It's not clear however if it's
75e1051a39Sopenharmony_ci * permitted to truncate to amount of bytes not divisible by 4. I bet not,
76e1051a39Sopenharmony_ci * but if it is, then default: case shall be extended. For reference.
77e1051a39Sopenharmony_ci * Idea behind separate cases for pre-defined lengths is to let the
78e1051a39Sopenharmony_ci * compiler decide if it's appropriate to unroll small loops.
79e1051a39Sopenharmony_ci */
80e1051a39Sopenharmony_ci#define HASH_MAKE_STRING(c,s)   do {    \
81e1051a39Sopenharmony_ci        unsigned long ll;               \
82e1051a39Sopenharmony_ci        unsigned int  nn;               \
83e1051a39Sopenharmony_ci        switch ((c)->md_len)            \
84e1051a39Sopenharmony_ci        {   case SHA224_DIGEST_LENGTH:  \
85e1051a39Sopenharmony_ci                for (nn=0;nn<SHA224_DIGEST_LENGTH/4;nn++)       \
86e1051a39Sopenharmony_ci                {   ll=(c)->h[nn]; (void)HOST_l2c(ll,(s));   }  \
87e1051a39Sopenharmony_ci                break;                  \
88e1051a39Sopenharmony_ci            case SHA256_DIGEST_LENGTH:  \
89e1051a39Sopenharmony_ci                for (nn=0;nn<SHA256_DIGEST_LENGTH/4;nn++)       \
90e1051a39Sopenharmony_ci                {   ll=(c)->h[nn]; (void)HOST_l2c(ll,(s));   }  \
91e1051a39Sopenharmony_ci                break;                  \
92e1051a39Sopenharmony_ci            default:                    \
93e1051a39Sopenharmony_ci                if ((c)->md_len > SHA256_DIGEST_LENGTH) \
94e1051a39Sopenharmony_ci                    return 0;                           \
95e1051a39Sopenharmony_ci                for (nn=0;nn<(c)->md_len/4;nn++)                \
96e1051a39Sopenharmony_ci                {   ll=(c)->h[nn]; (void)HOST_l2c(ll,(s));   }  \
97e1051a39Sopenharmony_ci                break;                  \
98e1051a39Sopenharmony_ci        }                               \
99e1051a39Sopenharmony_ci        } while (0)
100e1051a39Sopenharmony_ci
101e1051a39Sopenharmony_ci#define HASH_UPDATE             SHA256_Update
102e1051a39Sopenharmony_ci#define HASH_TRANSFORM          SHA256_Transform
103e1051a39Sopenharmony_ci#define HASH_FINAL              SHA256_Final
104e1051a39Sopenharmony_ci#define HASH_BLOCK_DATA_ORDER   sha256_block_data_order
105e1051a39Sopenharmony_ci#ifndef SHA256_ASM
106e1051a39Sopenharmony_cistatic
107e1051a39Sopenharmony_ci#endif
108e1051a39Sopenharmony_civoid sha256_block_data_order(SHA256_CTX *ctx, const void *in, size_t num);
109e1051a39Sopenharmony_ci
110e1051a39Sopenharmony_ci#include "crypto/md32_common.h"
111e1051a39Sopenharmony_ci
112e1051a39Sopenharmony_ci#ifndef SHA256_ASM
113e1051a39Sopenharmony_cistatic const SHA_LONG K256[64] = {
114e1051a39Sopenharmony_ci    0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL,
115e1051a39Sopenharmony_ci    0x3956c25bUL, 0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL,
116e1051a39Sopenharmony_ci    0xd807aa98UL, 0x12835b01UL, 0x243185beUL, 0x550c7dc3UL,
117e1051a39Sopenharmony_ci    0x72be5d74UL, 0x80deb1feUL, 0x9bdc06a7UL, 0xc19bf174UL,
118e1051a39Sopenharmony_ci    0xe49b69c1UL, 0xefbe4786UL, 0x0fc19dc6UL, 0x240ca1ccUL,
119e1051a39Sopenharmony_ci    0x2de92c6fUL, 0x4a7484aaUL, 0x5cb0a9dcUL, 0x76f988daUL,
120e1051a39Sopenharmony_ci    0x983e5152UL, 0xa831c66dUL, 0xb00327c8UL, 0xbf597fc7UL,
121e1051a39Sopenharmony_ci    0xc6e00bf3UL, 0xd5a79147UL, 0x06ca6351UL, 0x14292967UL,
122e1051a39Sopenharmony_ci    0x27b70a85UL, 0x2e1b2138UL, 0x4d2c6dfcUL, 0x53380d13UL,
123e1051a39Sopenharmony_ci    0x650a7354UL, 0x766a0abbUL, 0x81c2c92eUL, 0x92722c85UL,
124e1051a39Sopenharmony_ci    0xa2bfe8a1UL, 0xa81a664bUL, 0xc24b8b70UL, 0xc76c51a3UL,
125e1051a39Sopenharmony_ci    0xd192e819UL, 0xd6990624UL, 0xf40e3585UL, 0x106aa070UL,
126e1051a39Sopenharmony_ci    0x19a4c116UL, 0x1e376c08UL, 0x2748774cUL, 0x34b0bcb5UL,
127e1051a39Sopenharmony_ci    0x391c0cb3UL, 0x4ed8aa4aUL, 0x5b9cca4fUL, 0x682e6ff3UL,
128e1051a39Sopenharmony_ci    0x748f82eeUL, 0x78a5636fUL, 0x84c87814UL, 0x8cc70208UL,
129e1051a39Sopenharmony_ci    0x90befffaUL, 0xa4506cebUL, 0xbef9a3f7UL, 0xc67178f2UL
130e1051a39Sopenharmony_ci};
131e1051a39Sopenharmony_ci
132e1051a39Sopenharmony_ci/*
133e1051a39Sopenharmony_ci * FIPS specification refers to right rotations, while our ROTATE macro
134e1051a39Sopenharmony_ci * is left one. This is why you might notice that rotation coefficients
135e1051a39Sopenharmony_ci * differ from those observed in FIPS document by 32-N...
136e1051a39Sopenharmony_ci */
137e1051a39Sopenharmony_ci# define Sigma0(x)       (ROTATE((x),30) ^ ROTATE((x),19) ^ ROTATE((x),10))
138e1051a39Sopenharmony_ci# define Sigma1(x)       (ROTATE((x),26) ^ ROTATE((x),21) ^ ROTATE((x),7))
139e1051a39Sopenharmony_ci# define sigma0(x)       (ROTATE((x),25) ^ ROTATE((x),14) ^ ((x)>>3))
140e1051a39Sopenharmony_ci# define sigma1(x)       (ROTATE((x),15) ^ ROTATE((x),13) ^ ((x)>>10))
141e1051a39Sopenharmony_ci
142e1051a39Sopenharmony_ci# define Ch(x,y,z)       (((x) & (y)) ^ ((~(x)) & (z)))
143e1051a39Sopenharmony_ci# define Maj(x,y,z)      (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
144e1051a39Sopenharmony_ci
145e1051a39Sopenharmony_ci# ifdef OPENSSL_SMALL_FOOTPRINT
146e1051a39Sopenharmony_ci
147e1051a39Sopenharmony_cistatic void sha256_block_data_order(SHA256_CTX *ctx, const void *in,
148e1051a39Sopenharmony_ci                                    size_t num)
149e1051a39Sopenharmony_ci{
150e1051a39Sopenharmony_ci    unsigned MD32_REG_T a, b, c, d, e, f, g, h, s0, s1, T1, T2;
151e1051a39Sopenharmony_ci    SHA_LONG X[16], l;
152e1051a39Sopenharmony_ci    int i;
153e1051a39Sopenharmony_ci    const unsigned char *data = in;
154e1051a39Sopenharmony_ci
155e1051a39Sopenharmony_ci    while (num--) {
156e1051a39Sopenharmony_ci
157e1051a39Sopenharmony_ci        a = ctx->h[0];
158e1051a39Sopenharmony_ci        b = ctx->h[1];
159e1051a39Sopenharmony_ci        c = ctx->h[2];
160e1051a39Sopenharmony_ci        d = ctx->h[3];
161e1051a39Sopenharmony_ci        e = ctx->h[4];
162e1051a39Sopenharmony_ci        f = ctx->h[5];
163e1051a39Sopenharmony_ci        g = ctx->h[6];
164e1051a39Sopenharmony_ci        h = ctx->h[7];
165e1051a39Sopenharmony_ci
166e1051a39Sopenharmony_ci        for (i = 0; i < 16; i++) {
167e1051a39Sopenharmony_ci            (void)HOST_c2l(data, l);
168e1051a39Sopenharmony_ci            T1 = X[i] = l;
169e1051a39Sopenharmony_ci            T1 += h + Sigma1(e) + Ch(e, f, g) + K256[i];
170e1051a39Sopenharmony_ci            T2 = Sigma0(a) + Maj(a, b, c);
171e1051a39Sopenharmony_ci            h = g;
172e1051a39Sopenharmony_ci            g = f;
173e1051a39Sopenharmony_ci            f = e;
174e1051a39Sopenharmony_ci            e = d + T1;
175e1051a39Sopenharmony_ci            d = c;
176e1051a39Sopenharmony_ci            c = b;
177e1051a39Sopenharmony_ci            b = a;
178e1051a39Sopenharmony_ci            a = T1 + T2;
179e1051a39Sopenharmony_ci        }
180e1051a39Sopenharmony_ci
181e1051a39Sopenharmony_ci        for (; i < 64; i++) {
182e1051a39Sopenharmony_ci            s0 = X[(i + 1) & 0x0f];
183e1051a39Sopenharmony_ci            s0 = sigma0(s0);
184e1051a39Sopenharmony_ci            s1 = X[(i + 14) & 0x0f];
185e1051a39Sopenharmony_ci            s1 = sigma1(s1);
186e1051a39Sopenharmony_ci
187e1051a39Sopenharmony_ci            T1 = X[i & 0xf] += s0 + s1 + X[(i + 9) & 0xf];
188e1051a39Sopenharmony_ci            T1 += h + Sigma1(e) + Ch(e, f, g) + K256[i];
189e1051a39Sopenharmony_ci            T2 = Sigma0(a) + Maj(a, b, c);
190e1051a39Sopenharmony_ci            h = g;
191e1051a39Sopenharmony_ci            g = f;
192e1051a39Sopenharmony_ci            f = e;
193e1051a39Sopenharmony_ci            e = d + T1;
194e1051a39Sopenharmony_ci            d = c;
195e1051a39Sopenharmony_ci            c = b;
196e1051a39Sopenharmony_ci            b = a;
197e1051a39Sopenharmony_ci            a = T1 + T2;
198e1051a39Sopenharmony_ci        }
199e1051a39Sopenharmony_ci
200e1051a39Sopenharmony_ci        ctx->h[0] += a;
201e1051a39Sopenharmony_ci        ctx->h[1] += b;
202e1051a39Sopenharmony_ci        ctx->h[2] += c;
203e1051a39Sopenharmony_ci        ctx->h[3] += d;
204e1051a39Sopenharmony_ci        ctx->h[4] += e;
205e1051a39Sopenharmony_ci        ctx->h[5] += f;
206e1051a39Sopenharmony_ci        ctx->h[6] += g;
207e1051a39Sopenharmony_ci        ctx->h[7] += h;
208e1051a39Sopenharmony_ci
209e1051a39Sopenharmony_ci    }
210e1051a39Sopenharmony_ci}
211e1051a39Sopenharmony_ci
212e1051a39Sopenharmony_ci# else
213e1051a39Sopenharmony_ci
214e1051a39Sopenharmony_ci#  define ROUND_00_15(i,a,b,c,d,e,f,g,h)          do {    \
215e1051a39Sopenharmony_ci        T1 += h + Sigma1(e) + Ch(e,f,g) + K256[i];      \
216e1051a39Sopenharmony_ci        h = Sigma0(a) + Maj(a,b,c);                     \
217e1051a39Sopenharmony_ci        d += T1;        h += T1;                } while (0)
218e1051a39Sopenharmony_ci
219e1051a39Sopenharmony_ci#  define ROUND_16_63(i,a,b,c,d,e,f,g,h,X)        do {    \
220e1051a39Sopenharmony_ci        s0 = X[(i+1)&0x0f];     s0 = sigma0(s0);        \
221e1051a39Sopenharmony_ci        s1 = X[(i+14)&0x0f];    s1 = sigma1(s1);        \
222e1051a39Sopenharmony_ci        T1 = X[(i)&0x0f] += s0 + s1 + X[(i+9)&0x0f];    \
223e1051a39Sopenharmony_ci        ROUND_00_15(i,a,b,c,d,e,f,g,h);         } while (0)
224e1051a39Sopenharmony_ci
225e1051a39Sopenharmony_cistatic void sha256_block_data_order(SHA256_CTX *ctx, const void *in,
226e1051a39Sopenharmony_ci                                    size_t num)
227e1051a39Sopenharmony_ci{
228e1051a39Sopenharmony_ci    unsigned MD32_REG_T a, b, c, d, e, f, g, h, s0, s1, T1;
229e1051a39Sopenharmony_ci    SHA_LONG X[16];
230e1051a39Sopenharmony_ci    int i;
231e1051a39Sopenharmony_ci    const unsigned char *data = in;
232e1051a39Sopenharmony_ci    DECLARE_IS_ENDIAN;
233e1051a39Sopenharmony_ci
234e1051a39Sopenharmony_ci    while (num--) {
235e1051a39Sopenharmony_ci
236e1051a39Sopenharmony_ci        a = ctx->h[0];
237e1051a39Sopenharmony_ci        b = ctx->h[1];
238e1051a39Sopenharmony_ci        c = ctx->h[2];
239e1051a39Sopenharmony_ci        d = ctx->h[3];
240e1051a39Sopenharmony_ci        e = ctx->h[4];
241e1051a39Sopenharmony_ci        f = ctx->h[5];
242e1051a39Sopenharmony_ci        g = ctx->h[6];
243e1051a39Sopenharmony_ci        h = ctx->h[7];
244e1051a39Sopenharmony_ci
245e1051a39Sopenharmony_ci        if (!IS_LITTLE_ENDIAN && sizeof(SHA_LONG) == 4
246e1051a39Sopenharmony_ci            && ((size_t)in % 4) == 0) {
247e1051a39Sopenharmony_ci            const SHA_LONG *W = (const SHA_LONG *)data;
248e1051a39Sopenharmony_ci
249e1051a39Sopenharmony_ci            T1 = X[0] = W[0];
250e1051a39Sopenharmony_ci            ROUND_00_15(0, a, b, c, d, e, f, g, h);
251e1051a39Sopenharmony_ci            T1 = X[1] = W[1];
252e1051a39Sopenharmony_ci            ROUND_00_15(1, h, a, b, c, d, e, f, g);
253e1051a39Sopenharmony_ci            T1 = X[2] = W[2];
254e1051a39Sopenharmony_ci            ROUND_00_15(2, g, h, a, b, c, d, e, f);
255e1051a39Sopenharmony_ci            T1 = X[3] = W[3];
256e1051a39Sopenharmony_ci            ROUND_00_15(3, f, g, h, a, b, c, d, e);
257e1051a39Sopenharmony_ci            T1 = X[4] = W[4];
258e1051a39Sopenharmony_ci            ROUND_00_15(4, e, f, g, h, a, b, c, d);
259e1051a39Sopenharmony_ci            T1 = X[5] = W[5];
260e1051a39Sopenharmony_ci            ROUND_00_15(5, d, e, f, g, h, a, b, c);
261e1051a39Sopenharmony_ci            T1 = X[6] = W[6];
262e1051a39Sopenharmony_ci            ROUND_00_15(6, c, d, e, f, g, h, a, b);
263e1051a39Sopenharmony_ci            T1 = X[7] = W[7];
264e1051a39Sopenharmony_ci            ROUND_00_15(7, b, c, d, e, f, g, h, a);
265e1051a39Sopenharmony_ci            T1 = X[8] = W[8];
266e1051a39Sopenharmony_ci            ROUND_00_15(8, a, b, c, d, e, f, g, h);
267e1051a39Sopenharmony_ci            T1 = X[9] = W[9];
268e1051a39Sopenharmony_ci            ROUND_00_15(9, h, a, b, c, d, e, f, g);
269e1051a39Sopenharmony_ci            T1 = X[10] = W[10];
270e1051a39Sopenharmony_ci            ROUND_00_15(10, g, h, a, b, c, d, e, f);
271e1051a39Sopenharmony_ci            T1 = X[11] = W[11];
272e1051a39Sopenharmony_ci            ROUND_00_15(11, f, g, h, a, b, c, d, e);
273e1051a39Sopenharmony_ci            T1 = X[12] = W[12];
274e1051a39Sopenharmony_ci            ROUND_00_15(12, e, f, g, h, a, b, c, d);
275e1051a39Sopenharmony_ci            T1 = X[13] = W[13];
276e1051a39Sopenharmony_ci            ROUND_00_15(13, d, e, f, g, h, a, b, c);
277e1051a39Sopenharmony_ci            T1 = X[14] = W[14];
278e1051a39Sopenharmony_ci            ROUND_00_15(14, c, d, e, f, g, h, a, b);
279e1051a39Sopenharmony_ci            T1 = X[15] = W[15];
280e1051a39Sopenharmony_ci            ROUND_00_15(15, b, c, d, e, f, g, h, a);
281e1051a39Sopenharmony_ci
282e1051a39Sopenharmony_ci            data += SHA256_CBLOCK;
283e1051a39Sopenharmony_ci        } else {
284e1051a39Sopenharmony_ci            SHA_LONG l;
285e1051a39Sopenharmony_ci
286e1051a39Sopenharmony_ci            (void)HOST_c2l(data, l);
287e1051a39Sopenharmony_ci            T1 = X[0] = l;
288e1051a39Sopenharmony_ci            ROUND_00_15(0, a, b, c, d, e, f, g, h);
289e1051a39Sopenharmony_ci            (void)HOST_c2l(data, l);
290e1051a39Sopenharmony_ci            T1 = X[1] = l;
291e1051a39Sopenharmony_ci            ROUND_00_15(1, h, a, b, c, d, e, f, g);
292e1051a39Sopenharmony_ci            (void)HOST_c2l(data, l);
293e1051a39Sopenharmony_ci            T1 = X[2] = l;
294e1051a39Sopenharmony_ci            ROUND_00_15(2, g, h, a, b, c, d, e, f);
295e1051a39Sopenharmony_ci            (void)HOST_c2l(data, l);
296e1051a39Sopenharmony_ci            T1 = X[3] = l;
297e1051a39Sopenharmony_ci            ROUND_00_15(3, f, g, h, a, b, c, d, e);
298e1051a39Sopenharmony_ci            (void)HOST_c2l(data, l);
299e1051a39Sopenharmony_ci            T1 = X[4] = l;
300e1051a39Sopenharmony_ci            ROUND_00_15(4, e, f, g, h, a, b, c, d);
301e1051a39Sopenharmony_ci            (void)HOST_c2l(data, l);
302e1051a39Sopenharmony_ci            T1 = X[5] = l;
303e1051a39Sopenharmony_ci            ROUND_00_15(5, d, e, f, g, h, a, b, c);
304e1051a39Sopenharmony_ci            (void)HOST_c2l(data, l);
305e1051a39Sopenharmony_ci            T1 = X[6] = l;
306e1051a39Sopenharmony_ci            ROUND_00_15(6, c, d, e, f, g, h, a, b);
307e1051a39Sopenharmony_ci            (void)HOST_c2l(data, l);
308e1051a39Sopenharmony_ci            T1 = X[7] = l;
309e1051a39Sopenharmony_ci            ROUND_00_15(7, b, c, d, e, f, g, h, a);
310e1051a39Sopenharmony_ci            (void)HOST_c2l(data, l);
311e1051a39Sopenharmony_ci            T1 = X[8] = l;
312e1051a39Sopenharmony_ci            ROUND_00_15(8, a, b, c, d, e, f, g, h);
313e1051a39Sopenharmony_ci            (void)HOST_c2l(data, l);
314e1051a39Sopenharmony_ci            T1 = X[9] = l;
315e1051a39Sopenharmony_ci            ROUND_00_15(9, h, a, b, c, d, e, f, g);
316e1051a39Sopenharmony_ci            (void)HOST_c2l(data, l);
317e1051a39Sopenharmony_ci            T1 = X[10] = l;
318e1051a39Sopenharmony_ci            ROUND_00_15(10, g, h, a, b, c, d, e, f);
319e1051a39Sopenharmony_ci            (void)HOST_c2l(data, l);
320e1051a39Sopenharmony_ci            T1 = X[11] = l;
321e1051a39Sopenharmony_ci            ROUND_00_15(11, f, g, h, a, b, c, d, e);
322e1051a39Sopenharmony_ci            (void)HOST_c2l(data, l);
323e1051a39Sopenharmony_ci            T1 = X[12] = l;
324e1051a39Sopenharmony_ci            ROUND_00_15(12, e, f, g, h, a, b, c, d);
325e1051a39Sopenharmony_ci            (void)HOST_c2l(data, l);
326e1051a39Sopenharmony_ci            T1 = X[13] = l;
327e1051a39Sopenharmony_ci            ROUND_00_15(13, d, e, f, g, h, a, b, c);
328e1051a39Sopenharmony_ci            (void)HOST_c2l(data, l);
329e1051a39Sopenharmony_ci            T1 = X[14] = l;
330e1051a39Sopenharmony_ci            ROUND_00_15(14, c, d, e, f, g, h, a, b);
331e1051a39Sopenharmony_ci            (void)HOST_c2l(data, l);
332e1051a39Sopenharmony_ci            T1 = X[15] = l;
333e1051a39Sopenharmony_ci            ROUND_00_15(15, b, c, d, e, f, g, h, a);
334e1051a39Sopenharmony_ci        }
335e1051a39Sopenharmony_ci
336e1051a39Sopenharmony_ci        for (i = 16; i < 64; i += 8) {
337e1051a39Sopenharmony_ci            ROUND_16_63(i + 0, a, b, c, d, e, f, g, h, X);
338e1051a39Sopenharmony_ci            ROUND_16_63(i + 1, h, a, b, c, d, e, f, g, X);
339e1051a39Sopenharmony_ci            ROUND_16_63(i + 2, g, h, a, b, c, d, e, f, X);
340e1051a39Sopenharmony_ci            ROUND_16_63(i + 3, f, g, h, a, b, c, d, e, X);
341e1051a39Sopenharmony_ci            ROUND_16_63(i + 4, e, f, g, h, a, b, c, d, X);
342e1051a39Sopenharmony_ci            ROUND_16_63(i + 5, d, e, f, g, h, a, b, c, X);
343e1051a39Sopenharmony_ci            ROUND_16_63(i + 6, c, d, e, f, g, h, a, b, X);
344e1051a39Sopenharmony_ci            ROUND_16_63(i + 7, b, c, d, e, f, g, h, a, X);
345e1051a39Sopenharmony_ci        }
346e1051a39Sopenharmony_ci
347e1051a39Sopenharmony_ci        ctx->h[0] += a;
348e1051a39Sopenharmony_ci        ctx->h[1] += b;
349e1051a39Sopenharmony_ci        ctx->h[2] += c;
350e1051a39Sopenharmony_ci        ctx->h[3] += d;
351e1051a39Sopenharmony_ci        ctx->h[4] += e;
352e1051a39Sopenharmony_ci        ctx->h[5] += f;
353e1051a39Sopenharmony_ci        ctx->h[6] += g;
354e1051a39Sopenharmony_ci        ctx->h[7] += h;
355e1051a39Sopenharmony_ci
356e1051a39Sopenharmony_ci    }
357e1051a39Sopenharmony_ci}
358e1051a39Sopenharmony_ci
359e1051a39Sopenharmony_ci# endif
360e1051a39Sopenharmony_ci#endif                         /* SHA256_ASM */
361