hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/include/crypto/sha.h
....@@ -112,4 +112,56 @@
112112
113113 extern int crypto_sha512_finup(struct shash_desc *desc, const u8 *data,
114114 unsigned int len, u8 *hash);
115
+
116
+/*
117
+ * An implementation of SHA-1's compression function. Don't use in new code!
118
+ * You shouldn't be using SHA-1, and even if you *have* to use SHA-1, this isn't
119
+ * the correct way to hash something with SHA-1 (use crypto_shash instead).
120
+ */
121
+#define SHA1_DIGEST_WORDS (SHA1_DIGEST_SIZE / 4)
122
+#define SHA1_WORKSPACE_WORDS 16
123
+void sha1_init(__u32 *buf);
124
+void sha1_transform(__u32 *digest, const char *data, __u32 *W);
125
+
126
+/*
127
+ * Stand-alone implementation of the SHA256 algorithm. It is designed to
128
+ * have as little dependencies as possible so it can be used in the
129
+ * kexec_file purgatory. In other cases you should generally use the
130
+ * hash APIs from include/crypto/hash.h. Especially when hashing large
131
+ * amounts of data as those APIs may be hw-accelerated.
132
+ *
133
+ * For details see lib/crypto/sha256.c
134
+ */
135
+
136
+static inline void sha256_init(struct sha256_state *sctx)
137
+{
138
+ sctx->state[0] = SHA256_H0;
139
+ sctx->state[1] = SHA256_H1;
140
+ sctx->state[2] = SHA256_H2;
141
+ sctx->state[3] = SHA256_H3;
142
+ sctx->state[4] = SHA256_H4;
143
+ sctx->state[5] = SHA256_H5;
144
+ sctx->state[6] = SHA256_H6;
145
+ sctx->state[7] = SHA256_H7;
146
+ sctx->count = 0;
147
+}
148
+void sha256_update(struct sha256_state *sctx, const u8 *data, unsigned int len);
149
+void sha256_final(struct sha256_state *sctx, u8 *out);
150
+void sha256(const u8 *data, unsigned int len, u8 *out);
151
+
152
+static inline void sha224_init(struct sha256_state *sctx)
153
+{
154
+ sctx->state[0] = SHA224_H0;
155
+ sctx->state[1] = SHA224_H1;
156
+ sctx->state[2] = SHA224_H2;
157
+ sctx->state[3] = SHA224_H3;
158
+ sctx->state[4] = SHA224_H4;
159
+ sctx->state[5] = SHA224_H5;
160
+ sctx->state[6] = SHA224_H6;
161
+ sctx->state[7] = SHA224_H7;
162
+ sctx->count = 0;
163
+}
164
+void sha224_update(struct sha256_state *sctx, const u8 *data, unsigned int len);
165
+void sha224_final(struct sha256_state *sctx, u8 *out);
166
+
115167 #endif