diff options
author | Stephan Mueller <smueller@chronox.de> | 2014-11-11 23:30:42 -0500 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2014-11-13 09:31:43 -0500 |
commit | 47ca5be9eb066befe284f4e03fc11f21b8321ddc (patch) | |
tree | c1282e9fd6df8a30b89b2c62fe7b826c6182a611 /include/linux/crypto.h | |
parent | 16e61030aecb250766cf175141fc91d441361c43 (diff) |
crypto: doc - HASH API documentation
The API function calls exported by the kernel crypto API for
message digests to be used by consumers are documented.
Signed-off-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'include/linux/crypto.h')
-rw-r--r-- | include/linux/crypto.h | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/include/linux/crypto.h b/include/linux/crypto.h index 0f95a07aa4df..208a63290b23 100644 --- a/include/linux/crypto.h +++ b/include/linux/crypto.h | |||
@@ -2082,6 +2082,13 @@ static inline void crypto_cipher_decrypt_one(struct crypto_cipher *tfm, | |||
2082 | dst, src); | 2082 | dst, src); |
2083 | } | 2083 | } |
2084 | 2084 | ||
2085 | /** | ||
2086 | * DOC: Synchronous Message Digest API | ||
2087 | * | ||
2088 | * The synchronous message digest API is used with the ciphers of type | ||
2089 | * CRYPTO_ALG_TYPE_HASH (listed as type "hash" in /proc/crypto) | ||
2090 | */ | ||
2091 | |||
2085 | static inline struct crypto_hash *__crypto_hash_cast(struct crypto_tfm *tfm) | 2092 | static inline struct crypto_hash *__crypto_hash_cast(struct crypto_tfm *tfm) |
2086 | { | 2093 | { |
2087 | return (struct crypto_hash *)tfm; | 2094 | return (struct crypto_hash *)tfm; |
@@ -2094,6 +2101,20 @@ static inline struct crypto_hash *crypto_hash_cast(struct crypto_tfm *tfm) | |||
2094 | return __crypto_hash_cast(tfm); | 2101 | return __crypto_hash_cast(tfm); |
2095 | } | 2102 | } |
2096 | 2103 | ||
2104 | /** | ||
2105 | * crypto_alloc_hash() - allocate synchronous message digest handle | ||
2106 | * @alg_name: is the cra_name / name or cra_driver_name / driver name of the | ||
2107 | * message digest cipher | ||
2108 | * @type: specifies the type of the cipher | ||
2109 | * @mask: specifies the mask for the cipher | ||
2110 | * | ||
2111 | * Allocate a cipher handle for a message digest. The returned struct | ||
2112 | * crypto_hash is the cipher handle that is required for any subsequent | ||
2113 | * API invocation for that message digest. | ||
2114 | * | ||
2115 | * Return: allocated cipher handle in case of success; IS_ERR() is true in case | ||
2116 | * of an error, PTR_ERR() returns the error code. | ||
2117 | */ | ||
2097 | static inline struct crypto_hash *crypto_alloc_hash(const char *alg_name, | 2118 | static inline struct crypto_hash *crypto_alloc_hash(const char *alg_name, |
2098 | u32 type, u32 mask) | 2119 | u32 type, u32 mask) |
2099 | { | 2120 | { |
@@ -2110,11 +2131,25 @@ static inline struct crypto_tfm *crypto_hash_tfm(struct crypto_hash *tfm) | |||
2110 | return &tfm->base; | 2131 | return &tfm->base; |
2111 | } | 2132 | } |
2112 | 2133 | ||
2134 | /** | ||
2135 | * crypto_free_hash() - zeroize and free message digest handle | ||
2136 | * @tfm: cipher handle to be freed | ||
2137 | */ | ||
2113 | static inline void crypto_free_hash(struct crypto_hash *tfm) | 2138 | static inline void crypto_free_hash(struct crypto_hash *tfm) |
2114 | { | 2139 | { |
2115 | crypto_free_tfm(crypto_hash_tfm(tfm)); | 2140 | crypto_free_tfm(crypto_hash_tfm(tfm)); |
2116 | } | 2141 | } |
2117 | 2142 | ||
2143 | /** | ||
2144 | * crypto_has_hash() - Search for the availability of a message digest | ||
2145 | * @alg_name: is the cra_name / name or cra_driver_name / driver name of the | ||
2146 | * message digest cipher | ||
2147 | * @type: specifies the type of the cipher | ||
2148 | * @mask: specifies the mask for the cipher | ||
2149 | * | ||
2150 | * Return: true when the message digest cipher is known to the kernel crypto | ||
2151 | * API; false otherwise | ||
2152 | */ | ||
2118 | static inline int crypto_has_hash(const char *alg_name, u32 type, u32 mask) | 2153 | static inline int crypto_has_hash(const char *alg_name, u32 type, u32 mask) |
2119 | { | 2154 | { |
2120 | type &= ~CRYPTO_ALG_TYPE_MASK; | 2155 | type &= ~CRYPTO_ALG_TYPE_MASK; |
@@ -2130,6 +2165,15 @@ static inline struct hash_tfm *crypto_hash_crt(struct crypto_hash *tfm) | |||
2130 | return &crypto_hash_tfm(tfm)->crt_hash; | 2165 | return &crypto_hash_tfm(tfm)->crt_hash; |
2131 | } | 2166 | } |
2132 | 2167 | ||
2168 | /** | ||
2169 | * crypto_hash_blocksize() - obtain block size for message digest | ||
2170 | * @tfm: cipher handle | ||
2171 | * | ||
2172 | * The block size for the message digest cipher referenced with the cipher | ||
2173 | * handle is returned. | ||
2174 | * | ||
2175 | * Return: block size of cipher | ||
2176 | */ | ||
2133 | static inline unsigned int crypto_hash_blocksize(struct crypto_hash *tfm) | 2177 | static inline unsigned int crypto_hash_blocksize(struct crypto_hash *tfm) |
2134 | { | 2178 | { |
2135 | return crypto_tfm_alg_blocksize(crypto_hash_tfm(tfm)); | 2179 | return crypto_tfm_alg_blocksize(crypto_hash_tfm(tfm)); |
@@ -2140,6 +2184,15 @@ static inline unsigned int crypto_hash_alignmask(struct crypto_hash *tfm) | |||
2140 | return crypto_tfm_alg_alignmask(crypto_hash_tfm(tfm)); | 2184 | return crypto_tfm_alg_alignmask(crypto_hash_tfm(tfm)); |
2141 | } | 2185 | } |
2142 | 2186 | ||
2187 | /** | ||
2188 | * crypto_hash_digestsize() - obtain message digest size | ||
2189 | * @tfm: cipher handle | ||
2190 | * | ||
2191 | * The size for the message digest created by the message digest cipher | ||
2192 | * referenced with the cipher handle is returned. | ||
2193 | * | ||
2194 | * Return: message digest size | ||
2195 | */ | ||
2143 | static inline unsigned int crypto_hash_digestsize(struct crypto_hash *tfm) | 2196 | static inline unsigned int crypto_hash_digestsize(struct crypto_hash *tfm) |
2144 | { | 2197 | { |
2145 | return crypto_hash_crt(tfm)->digestsize; | 2198 | return crypto_hash_crt(tfm)->digestsize; |
@@ -2160,11 +2213,38 @@ static inline void crypto_hash_clear_flags(struct crypto_hash *tfm, u32 flags) | |||
2160 | crypto_tfm_clear_flags(crypto_hash_tfm(tfm), flags); | 2213 | crypto_tfm_clear_flags(crypto_hash_tfm(tfm), flags); |
2161 | } | 2214 | } |
2162 | 2215 | ||
2216 | /** | ||
2217 | * crypto_hash_init() - (re)initialize message digest handle | ||
2218 | * @desc: cipher request handle that to be filled by caller -- | ||
2219 | * desc.tfm is filled with the hash cipher handle; | ||
2220 | * desc.flags is filled with either CRYPTO_TFM_REQ_MAY_SLEEP or 0. | ||
2221 | * | ||
2222 | * The call (re-)initializes the message digest referenced by the hash cipher | ||
2223 | * request handle. Any potentially existing state created by previous | ||
2224 | * operations is discarded. | ||
2225 | * | ||
2226 | * Return: 0 if the message digest initialization was successful; < 0 if an | ||
2227 | * error occurred | ||
2228 | */ | ||
2163 | static inline int crypto_hash_init(struct hash_desc *desc) | 2229 | static inline int crypto_hash_init(struct hash_desc *desc) |
2164 | { | 2230 | { |
2165 | return crypto_hash_crt(desc->tfm)->init(desc); | 2231 | return crypto_hash_crt(desc->tfm)->init(desc); |
2166 | } | 2232 | } |
2167 | 2233 | ||
2234 | /** | ||
2235 | * crypto_hash_update() - add data to message digest for processing | ||
2236 | * @desc: cipher request handle | ||
2237 | * @sg: scatter / gather list pointing to the data to be added to the message | ||
2238 | * digest | ||
2239 | * @nbytes: number of bytes to be processed from @sg | ||
2240 | * | ||
2241 | * Updates the message digest state of the cipher handle pointed to by the | ||
2242 | * hash cipher request handle with the input data pointed to by the | ||
2243 | * scatter/gather list. | ||
2244 | * | ||
2245 | * Return: 0 if the message digest update was successful; < 0 if an error | ||
2246 | * occurred | ||
2247 | */ | ||
2168 | static inline int crypto_hash_update(struct hash_desc *desc, | 2248 | static inline int crypto_hash_update(struct hash_desc *desc, |
2169 | struct scatterlist *sg, | 2249 | struct scatterlist *sg, |
2170 | unsigned int nbytes) | 2250 | unsigned int nbytes) |
@@ -2172,11 +2252,39 @@ static inline int crypto_hash_update(struct hash_desc *desc, | |||
2172 | return crypto_hash_crt(desc->tfm)->update(desc, sg, nbytes); | 2252 | return crypto_hash_crt(desc->tfm)->update(desc, sg, nbytes); |
2173 | } | 2253 | } |
2174 | 2254 | ||
2255 | /** | ||
2256 | * crypto_hash_final() - calculate message digest | ||
2257 | * @desc: cipher request handle | ||
2258 | * @out: message digest output buffer -- The caller must ensure that the out | ||
2259 | * buffer has a sufficient size (e.g. by using the crypto_hash_digestsize | ||
2260 | * function). | ||
2261 | * | ||
2262 | * Finalize the message digest operation and create the message digest | ||
2263 | * based on all data added to the cipher handle. The message digest is placed | ||
2264 | * into the output buffer. | ||
2265 | * | ||
2266 | * Return: 0 if the message digest creation was successful; < 0 if an error | ||
2267 | * occurred | ||
2268 | */ | ||
2175 | static inline int crypto_hash_final(struct hash_desc *desc, u8 *out) | 2269 | static inline int crypto_hash_final(struct hash_desc *desc, u8 *out) |
2176 | { | 2270 | { |
2177 | return crypto_hash_crt(desc->tfm)->final(desc, out); | 2271 | return crypto_hash_crt(desc->tfm)->final(desc, out); |
2178 | } | 2272 | } |
2179 | 2273 | ||
2274 | /** | ||
2275 | * crypto_hash_digest() - calculate message digest for a buffer | ||
2276 | * @desc: see crypto_hash_final() | ||
2277 | * @sg: see crypto_hash_update() | ||
2278 | * @nbytes: see crypto_hash_update() | ||
2279 | * @out: see crypto_hash_final() | ||
2280 | * | ||
2281 | * This function is a "short-hand" for the function calls of crypto_hash_init, | ||
2282 | * crypto_hash_update and crypto_hash_final. The parameters have the same | ||
2283 | * meaning as discussed for those separate three functions. | ||
2284 | * | ||
2285 | * Return: 0 if the message digest creation was successful; < 0 if an error | ||
2286 | * occurred | ||
2287 | */ | ||
2180 | static inline int crypto_hash_digest(struct hash_desc *desc, | 2288 | static inline int crypto_hash_digest(struct hash_desc *desc, |
2181 | struct scatterlist *sg, | 2289 | struct scatterlist *sg, |
2182 | unsigned int nbytes, u8 *out) | 2290 | unsigned int nbytes, u8 *out) |
@@ -2184,6 +2292,17 @@ static inline int crypto_hash_digest(struct hash_desc *desc, | |||
2184 | return crypto_hash_crt(desc->tfm)->digest(desc, sg, nbytes, out); | 2292 | return crypto_hash_crt(desc->tfm)->digest(desc, sg, nbytes, out); |
2185 | } | 2293 | } |
2186 | 2294 | ||
2295 | /** | ||
2296 | * crypto_hash_setkey() - set key for message digest | ||
2297 | * @hash: cipher handle | ||
2298 | * @key: buffer holding the key | ||
2299 | * @keylen: length of the key in bytes | ||
2300 | * | ||
2301 | * The caller provided key is set for the message digest cipher. The cipher | ||
2302 | * handle must point to a keyed hash in order for this function to succeed. | ||
2303 | * | ||
2304 | * Return: 0 if the setting of the key was successful; < 0 if an error occurred | ||
2305 | */ | ||
2187 | static inline int crypto_hash_setkey(struct crypto_hash *hash, | 2306 | static inline int crypto_hash_setkey(struct crypto_hash *hash, |
2188 | const u8 *key, unsigned int keylen) | 2307 | const u8 *key, unsigned int keylen) |
2189 | { | 2308 | { |