/src/barebox/include/digest.h
Line | Count | Source |
1 | | /* SPDX-License-Identifier: GPL-2.0-only */ |
2 | | /* |
3 | | * (C) Copyright 2008-2010 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> |
4 | | */ |
5 | | |
6 | | #ifndef __DIGEST_H__ |
7 | | #define __DIGEST_H__ |
8 | | |
9 | | #include <linux/list.h> |
10 | | #include <errno.h> |
11 | | |
12 | | struct digest; |
13 | | |
14 | | enum hash_algo { |
15 | | HASH_ALGO_MD4, |
16 | | HASH_ALGO_MD5, |
17 | | HASH_ALGO_SHA1, |
18 | | HASH_ALGO_RIPE_MD_160, |
19 | | HASH_ALGO_SHA256, |
20 | | HASH_ALGO_SHA384, |
21 | | HASH_ALGO_SHA512, |
22 | | HASH_ALGO_SHA224, |
23 | | HASH_ALGO_RIPE_MD_128, |
24 | | HASH_ALGO_RIPE_MD_256, |
25 | | HASH_ALGO_RIPE_MD_320, |
26 | | HASH_ALGO_WP_256, |
27 | | HASH_ALGO_WP_384, |
28 | | HASH_ALGO_WP_512, |
29 | | HASH_ALGO_TGR_128, |
30 | | HASH_ALGO_TGR_160, |
31 | | HASH_ALGO_TGR_192, |
32 | | HASH_ALGO_SM3_256, |
33 | | /* |
34 | | * The above are exported from the Kernel as |
35 | | * /usr/include/linux/hash_info.h and thus have a fixed number, do not |
36 | | * change it. Below are barebox specific, subject to renumbering. |
37 | | */ |
38 | | HASH_ALGO_CRC32, |
39 | | HASH_ALGO__LAST |
40 | | }; |
41 | | |
42 | | struct crypto_alg { |
43 | | const char *name; |
44 | | const char *driver_name; |
45 | | int priority; |
46 | 0 | #define DIGEST_ALGO_NEED_KEY (1 << 0) |
47 | | unsigned int flags; |
48 | | enum hash_algo algo; |
49 | | }; |
50 | | |
51 | | struct digest_algo { |
52 | | struct crypto_alg base; |
53 | | |
54 | | int (*alloc)(struct digest *d); |
55 | | void (*free)(struct digest *d); |
56 | | int (*init)(struct digest *d); |
57 | | int (*update)(struct digest *d, const void *data, unsigned long len); |
58 | | int (*final)(struct digest *d, unsigned char *md); |
59 | | int (*digest)(struct digest *d, const void *data, |
60 | | unsigned int len, u8 *out); |
61 | | int (*set_key)(struct digest *d, const unsigned char *key, unsigned int len); |
62 | | int (*verify)(struct digest *d, const unsigned char *md); |
63 | | |
64 | | unsigned int length; |
65 | | unsigned int ctx_length; |
66 | | |
67 | | struct list_head list; |
68 | | }; |
69 | | |
70 | | struct digest { |
71 | | struct digest_algo *algo; |
72 | | void *ctx; |
73 | | unsigned int length; |
74 | | }; |
75 | | |
76 | | /* |
77 | | * digest functions |
78 | | */ |
79 | | #if defined(CONFIG_DIGEST) || defined(__PBL__) |
80 | | int digest_algo_register(struct digest_algo *d); |
81 | | void digest_algo_unregister(struct digest_algo *d); |
82 | | void digest_algo_prints(const char *prefix); |
83 | | |
84 | | struct digest *digest_alloc(const char *name); |
85 | | struct digest *digest_alloc_by_algo(enum hash_algo); |
86 | | void digest_free(struct digest *d); |
87 | | |
88 | | int digest_file_window(struct digest *d, const char *filename, |
89 | | unsigned char *hash, |
90 | | const unsigned char *sig, |
91 | | loff_t start, loff_t size); |
92 | | int digest_file(struct digest *d, const char *filename, |
93 | | unsigned char *hash, |
94 | | const unsigned char *sig); |
95 | | int digest_file_by_name(const char *algo, const char *filename, |
96 | | unsigned char *hash, |
97 | | const unsigned char *sig); |
98 | | #else |
99 | | static inline struct digest *digest_alloc(const char *name) |
100 | | { |
101 | | return NULL; |
102 | | } |
103 | | |
104 | | static inline struct digest *digest_alloc_by_algo(enum hash_algo algo) |
105 | | { |
106 | | return NULL; |
107 | | } |
108 | | |
109 | | static inline void digest_free(struct digest *d) |
110 | | { |
111 | | } |
112 | | #endif |
113 | | |
114 | | static inline int digest_init(struct digest *d) |
115 | 2.08k | { |
116 | 2.08k | return d->algo->init(d); |
117 | 2.08k | } Unexecuted instantiation: state.c:digest_init backend_format_raw.c:digest_init Line | Count | Source | 115 | 92 | { | 116 | 92 | return d->algo->init(d); | 117 | 92 | } |
Unexecuted instantiation: parser.c:digest_init Line | Count | Source | 115 | 549 | { | 116 | 549 | return d->algo->init(d); | 117 | 549 | } |
Line | Count | Source | 115 | 1.29k | { | 116 | 1.29k | return d->algo->init(d); | 117 | 1.29k | } |
Unexecuted instantiation: hashsum.c:digest_init Unexecuted instantiation: jwt.c:digest_init Unexecuted instantiation: password.c:digest_init Line | Count | Source | 115 | 153 | { | 116 | 153 | return d->algo->init(d); | 117 | 153 | } |
Unexecuted instantiation: md5.c:digest_init Unexecuted instantiation: sha1.c:digest_init Unexecuted instantiation: sha2.c:digest_init Unexecuted instantiation: sha4.c:digest_init Unexecuted instantiation: pbkdf2.c:digest_init Unexecuted instantiation: rsa.c:digest_init Unexecuted instantiation: public-keys.c:digest_init Unexecuted instantiation: snakeoil_rsa4096.pem.c:digest_init Unexecuted instantiation: sha.c:digest_init |
118 | | |
119 | | static inline int digest_update(struct digest *d, const void *data, |
120 | | unsigned long len) |
121 | 4.78k | { |
122 | 4.78k | return d->algo->update(d, data, len); |
123 | 4.78k | } Unexecuted instantiation: state.c:digest_update backend_format_raw.c:digest_update Line | Count | Source | 121 | 61 | { | 122 | 61 | return d->algo->update(d, data, len); | 123 | 61 | } |
Unexecuted instantiation: parser.c:digest_update image-fit.c:digest_update Line | Count | Source | 121 | 3.15k | { | 122 | 3.15k | return d->algo->update(d, data, len); | 123 | 3.15k | } |
Line | Count | Source | 121 | 1.29k | { | 122 | 1.29k | return d->algo->update(d, data, len); | 123 | 1.29k | } |
Unexecuted instantiation: hashsum.c:digest_update Unexecuted instantiation: jwt.c:digest_update Unexecuted instantiation: password.c:digest_update Line | Count | Source | 121 | 275 | { | 122 | 275 | return d->algo->update(d, data, len); | 123 | 275 | } |
Unexecuted instantiation: md5.c:digest_update Unexecuted instantiation: sha1.c:digest_update Unexecuted instantiation: sha2.c:digest_update Unexecuted instantiation: sha4.c:digest_update Unexecuted instantiation: pbkdf2.c:digest_update Unexecuted instantiation: rsa.c:digest_update Unexecuted instantiation: public-keys.c:digest_update Unexecuted instantiation: snakeoil_rsa4096.pem.c:digest_update Unexecuted instantiation: sha.c:digest_update |
124 | | |
125 | | static inline int digest_final(struct digest *d, unsigned char *md) |
126 | 1.94k | { |
127 | 1.94k | return d->algo->final(d, md); |
128 | 1.94k | } Unexecuted instantiation: state.c:digest_final Unexecuted instantiation: backend_format_raw.c:digest_final Unexecuted instantiation: parser.c:digest_final Line | Count | Source | 126 | 409 | { | 127 | 409 | return d->algo->final(d, md); | 128 | 409 | } |
Line | Count | Source | 126 | 1.41k | { | 127 | 1.41k | return d->algo->final(d, md); | 128 | 1.41k | } |
Unexecuted instantiation: hashsum.c:digest_final Unexecuted instantiation: jwt.c:digest_final Unexecuted instantiation: password.c:digest_final Line | Count | Source | 126 | 122 | { | 127 | 122 | return d->algo->final(d, md); | 128 | 122 | } |
Unexecuted instantiation: md5.c:digest_final Unexecuted instantiation: sha1.c:digest_final Unexecuted instantiation: sha2.c:digest_final Unexecuted instantiation: sha4.c:digest_final Unexecuted instantiation: pbkdf2.c:digest_final Unexecuted instantiation: rsa.c:digest_final Unexecuted instantiation: public-keys.c:digest_final Unexecuted instantiation: snakeoil_rsa4096.pem.c:digest_final Unexecuted instantiation: sha.c:digest_final |
129 | | |
130 | | static inline int digest_digest(struct digest *d, const void *data, |
131 | | unsigned int len, u8 *md) |
132 | 1.29k | { |
133 | 1.29k | return d->algo->digest(d, data, len, md); |
134 | 1.29k | } Unexecuted instantiation: state.c:digest_digest Unexecuted instantiation: backend_format_raw.c:digest_digest Unexecuted instantiation: parser.c:digest_digest Unexecuted instantiation: image-fit.c:digest_digest Unexecuted instantiation: digest.c:digest_digest Unexecuted instantiation: hashsum.c:digest_digest Line | Count | Source | 132 | 1.29k | { | 133 | 1.29k | return d->algo->digest(d, data, len, md); | 134 | 1.29k | } |
Unexecuted instantiation: password.c:digest_digest Unexecuted instantiation: hmac.c:digest_digest Unexecuted instantiation: md5.c:digest_digest Unexecuted instantiation: sha1.c:digest_digest Unexecuted instantiation: sha2.c:digest_digest Unexecuted instantiation: sha4.c:digest_digest Unexecuted instantiation: pbkdf2.c:digest_digest Unexecuted instantiation: rsa.c:digest_digest Unexecuted instantiation: public-keys.c:digest_digest Unexecuted instantiation: snakeoil_rsa4096.pem.c:digest_digest Unexecuted instantiation: sha.c:digest_digest |
135 | | |
136 | | static inline int digest_verify(struct digest *d, const unsigned char *md) |
137 | 122 | { |
138 | 122 | return d->algo->verify(d, md); |
139 | 122 | } Unexecuted instantiation: state.c:digest_verify backend_format_raw.c:digest_verify Line | Count | Source | 137 | 61 | { | 138 | 61 | return d->algo->verify(d, md); | 139 | 61 | } |
Unexecuted instantiation: parser.c:digest_verify image-fit.c:digest_verify Line | Count | Source | 137 | 61 | { | 138 | 61 | return d->algo->verify(d, md); | 139 | 61 | } |
Unexecuted instantiation: digest.c:digest_verify Unexecuted instantiation: hashsum.c:digest_verify Unexecuted instantiation: jwt.c:digest_verify Unexecuted instantiation: password.c:digest_verify Unexecuted instantiation: hmac.c:digest_verify Unexecuted instantiation: md5.c:digest_verify Unexecuted instantiation: sha1.c:digest_verify Unexecuted instantiation: sha2.c:digest_verify Unexecuted instantiation: sha4.c:digest_verify Unexecuted instantiation: pbkdf2.c:digest_verify Unexecuted instantiation: rsa.c:digest_verify Unexecuted instantiation: public-keys.c:digest_verify Unexecuted instantiation: snakeoil_rsa4096.pem.c:digest_verify Unexecuted instantiation: sha.c:digest_verify |
140 | | |
141 | | static inline int digest_length(struct digest *d) |
142 | 3.57k | { |
143 | 3.57k | return d->length ? d->length : d->algo->length; |
144 | 3.57k | } Unexecuted instantiation: state.c:digest_length backend_format_raw.c:digest_length Line | Count | Source | 142 | 93 | { | 143 | 93 | return d->length ? d->length : d->algo->length; | 144 | 93 | } |
Unexecuted instantiation: parser.c:digest_length image-fit.c:digest_length Line | Count | Source | 142 | 480 | { | 143 | 480 | return d->length ? d->length : d->algo->length; | 144 | 480 | } |
Line | Count | Source | 142 | 122 | { | 143 | 122 | return d->length ? d->length : d->algo->length; | 144 | 122 | } |
Unexecuted instantiation: hashsum.c:digest_length Line | Count | Source | 142 | 1.29k | { | 143 | 1.29k | return d->length ? d->length : d->algo->length; | 144 | 1.29k | } |
Unexecuted instantiation: password.c:digest_length Line | Count | Source | 142 | 122 | { | 143 | 122 | return d->length ? d->length : d->algo->length; | 144 | 122 | } |
Unexecuted instantiation: md5.c:digest_length Unexecuted instantiation: sha1.c:digest_length Unexecuted instantiation: sha2.c:digest_length Unexecuted instantiation: sha4.c:digest_length Unexecuted instantiation: pbkdf2.c:digest_length Line | Count | Source | 142 | 1.47k | { | 143 | 1.47k | return d->length ? d->length : d->algo->length; | 144 | 1.47k | } |
Unexecuted instantiation: public-keys.c:digest_length Unexecuted instantiation: snakeoil_rsa4096.pem.c:digest_length Unexecuted instantiation: sha.c:digest_length |
145 | | |
146 | | static inline int digest_set_key(struct digest *d, const unsigned char *key, |
147 | | unsigned int len) |
148 | 92 | { |
149 | 92 | if (!d->algo->set_key) |
150 | 0 | return -ENOTSUPP; |
151 | 92 | return d->algo->set_key(d, key, len); |
152 | 92 | } Unexecuted instantiation: state.c:digest_set_key backend_format_raw.c:digest_set_key Line | Count | Source | 148 | 92 | { | 149 | 92 | if (!d->algo->set_key) | 150 | 0 | return -ENOTSUPP; | 151 | 92 | return d->algo->set_key(d, key, len); | 152 | 92 | } |
Unexecuted instantiation: parser.c:digest_set_key Unexecuted instantiation: image-fit.c:digest_set_key Unexecuted instantiation: digest.c:digest_set_key Unexecuted instantiation: hashsum.c:digest_set_key Unexecuted instantiation: jwt.c:digest_set_key Unexecuted instantiation: password.c:digest_set_key Unexecuted instantiation: hmac.c:digest_set_key Unexecuted instantiation: md5.c:digest_set_key Unexecuted instantiation: sha1.c:digest_set_key Unexecuted instantiation: sha2.c:digest_set_key Unexecuted instantiation: sha4.c:digest_set_key Unexecuted instantiation: pbkdf2.c:digest_set_key Unexecuted instantiation: rsa.c:digest_set_key Unexecuted instantiation: public-keys.c:digest_set_key Unexecuted instantiation: snakeoil_rsa4096.pem.c:digest_set_key Unexecuted instantiation: sha.c:digest_set_key |
153 | | |
154 | | static inline int digest_is_flags(struct digest *d, unsigned int flags) |
155 | 0 | { |
156 | 0 | return d->algo->base.flags & flags; |
157 | 0 | } Unexecuted instantiation: state.c:digest_is_flags Unexecuted instantiation: backend_format_raw.c:digest_is_flags Unexecuted instantiation: parser.c:digest_is_flags Unexecuted instantiation: image-fit.c:digest_is_flags Unexecuted instantiation: digest.c:digest_is_flags Unexecuted instantiation: hashsum.c:digest_is_flags Unexecuted instantiation: jwt.c:digest_is_flags Unexecuted instantiation: password.c:digest_is_flags Unexecuted instantiation: hmac.c:digest_is_flags Unexecuted instantiation: md5.c:digest_is_flags Unexecuted instantiation: sha1.c:digest_is_flags Unexecuted instantiation: sha2.c:digest_is_flags Unexecuted instantiation: sha4.c:digest_is_flags Unexecuted instantiation: pbkdf2.c:digest_is_flags Unexecuted instantiation: rsa.c:digest_is_flags Unexecuted instantiation: public-keys.c:digest_is_flags Unexecuted instantiation: snakeoil_rsa4096.pem.c:digest_is_flags Unexecuted instantiation: sha.c:digest_is_flags |
158 | | |
159 | | static inline const char *digest_name(struct digest *d) |
160 | 0 | { |
161 | 0 | return d->algo->base.name; |
162 | 0 | } Unexecuted instantiation: state.c:digest_name Unexecuted instantiation: backend_format_raw.c:digest_name Unexecuted instantiation: parser.c:digest_name Unexecuted instantiation: image-fit.c:digest_name Unexecuted instantiation: digest.c:digest_name Unexecuted instantiation: hashsum.c:digest_name Unexecuted instantiation: jwt.c:digest_name Unexecuted instantiation: password.c:digest_name Unexecuted instantiation: hmac.c:digest_name Unexecuted instantiation: md5.c:digest_name Unexecuted instantiation: sha1.c:digest_name Unexecuted instantiation: sha2.c:digest_name Unexecuted instantiation: sha4.c:digest_name Unexecuted instantiation: pbkdf2.c:digest_name Unexecuted instantiation: rsa.c:digest_name Unexecuted instantiation: public-keys.c:digest_name Unexecuted instantiation: snakeoil_rsa4096.pem.c:digest_name Unexecuted instantiation: sha.c:digest_name |
163 | | |
164 | | static inline enum hash_algo digest_algo(struct digest *d) |
165 | 0 | { |
166 | 0 | return d->algo->base.algo; |
167 | 0 | } Unexecuted instantiation: state.c:digest_algo Unexecuted instantiation: backend_format_raw.c:digest_algo Unexecuted instantiation: parser.c:digest_algo Unexecuted instantiation: image-fit.c:digest_algo Unexecuted instantiation: digest.c:digest_algo Unexecuted instantiation: hashsum.c:digest_algo Unexecuted instantiation: jwt.c:digest_algo Unexecuted instantiation: password.c:digest_algo Unexecuted instantiation: hmac.c:digest_algo Unexecuted instantiation: md5.c:digest_algo Unexecuted instantiation: sha1.c:digest_algo Unexecuted instantiation: sha2.c:digest_algo Unexecuted instantiation: sha4.c:digest_algo Unexecuted instantiation: pbkdf2.c:digest_algo Unexecuted instantiation: rsa.c:digest_algo Unexecuted instantiation: public-keys.c:digest_algo Unexecuted instantiation: snakeoil_rsa4096.pem.c:digest_algo Unexecuted instantiation: sha.c:digest_algo |
168 | | |
169 | | static inline void* digest_ctx(struct digest *d) |
170 | 12.3k | { |
171 | 12.3k | return d->ctx; |
172 | 12.3k | } Unexecuted instantiation: state.c:digest_ctx Unexecuted instantiation: backend_format_raw.c:digest_ctx Unexecuted instantiation: parser.c:digest_ctx Unexecuted instantiation: image-fit.c:digest_ctx Unexecuted instantiation: digest.c:digest_ctx Unexecuted instantiation: hashsum.c:digest_ctx Unexecuted instantiation: jwt.c:digest_ctx Unexecuted instantiation: password.c:digest_ctx Unexecuted instantiation: hmac.c:digest_ctx Unexecuted instantiation: md5.c:digest_ctx Line | Count | Source | 170 | 3.33k | { | 171 | 3.33k | return d->ctx; | 172 | 3.33k | } |
Line | Count | Source | 170 | 9.00k | { | 171 | 9.00k | return d->ctx; | 172 | 9.00k | } |
Unexecuted instantiation: sha4.c:digest_ctx Unexecuted instantiation: pbkdf2.c:digest_ctx Unexecuted instantiation: rsa.c:digest_ctx Unexecuted instantiation: public-keys.c:digest_ctx Unexecuted instantiation: snakeoil_rsa4096.pem.c:digest_ctx Unexecuted instantiation: sha.c:digest_ctx |
173 | | |
174 | | #endif /* __SH_ST_DEVICES_H__ */ |