aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/crypto.h
diff options
context:
space:
mode:
authorStephan Mueller <smueller@chronox.de>2014-11-11 23:30:06 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2014-11-13 09:31:43 -0500
commit16e61030aecb250766cf175141fc91d441361c43 (patch)
tree19fe46fa30667d8d8e8d8e24da4a40b3309422dc /include/linux/crypto.h
parent58284f0d6c4a974d2d89446f3b3cbc51420432ea (diff)
crypto: doc - CIPHER API documentation
The API function calls exported by the kernel crypto API for signle block ciphers 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.h89
1 files changed, 89 insertions, 0 deletions
diff --git a/include/linux/crypto.h b/include/linux/crypto.h
index c9ebe456dc9e..0f95a07aa4df 100644
--- a/include/linux/crypto.h
+++ b/include/linux/crypto.h
@@ -1900,6 +1900,23 @@ static inline void crypto_blkcipher_get_iv(struct crypto_blkcipher *tfm,
1900 memcpy(dst, crypto_blkcipher_crt(tfm)->iv, len); 1900 memcpy(dst, crypto_blkcipher_crt(tfm)->iv, len);
1901} 1901}
1902 1902
1903/**
1904 * DOC: Single Block Cipher API
1905 *
1906 * The single block cipher API is used with the ciphers of type
1907 * CRYPTO_ALG_TYPE_CIPHER (listed as type "cipher" in /proc/crypto).
1908 *
1909 * Using the single block cipher API calls, operations with the basic cipher
1910 * primitive can be implemented. These cipher primitives exclude any block
1911 * chaining operations including IV handling.
1912 *
1913 * The purpose of this single block cipher API is to support the implementation
1914 * of templates or other concepts that only need to perform the cipher operation
1915 * on one block at a time. Templates invoke the underlying cipher primitive
1916 * block-wise and process either the input or the output data of these cipher
1917 * operations.
1918 */
1919
1903static inline struct crypto_cipher *__crypto_cipher_cast(struct crypto_tfm *tfm) 1920static inline struct crypto_cipher *__crypto_cipher_cast(struct crypto_tfm *tfm)
1904{ 1921{
1905 return (struct crypto_cipher *)tfm; 1922 return (struct crypto_cipher *)tfm;
@@ -1911,6 +1928,20 @@ static inline struct crypto_cipher *crypto_cipher_cast(struct crypto_tfm *tfm)
1911 return __crypto_cipher_cast(tfm); 1928 return __crypto_cipher_cast(tfm);
1912} 1929}
1913 1930
1931/**
1932 * crypto_alloc_cipher() - allocate single block cipher handle
1933 * @alg_name: is the cra_name / name or cra_driver_name / driver name of the
1934 * single block cipher
1935 * @type: specifies the type of the cipher
1936 * @mask: specifies the mask for the cipher
1937 *
1938 * Allocate a cipher handle for a single block cipher. The returned struct
1939 * crypto_cipher is the cipher handle that is required for any subsequent API
1940 * invocation for that single block cipher.
1941 *
1942 * Return: allocated cipher handle in case of success; IS_ERR() is true in case
1943 * of an error, PTR_ERR() returns the error code.
1944 */
1914static inline struct crypto_cipher *crypto_alloc_cipher(const char *alg_name, 1945static inline struct crypto_cipher *crypto_alloc_cipher(const char *alg_name,
1915 u32 type, u32 mask) 1946 u32 type, u32 mask)
1916{ 1947{
@@ -1926,11 +1957,25 @@ static inline struct crypto_tfm *crypto_cipher_tfm(struct crypto_cipher *tfm)
1926 return &tfm->base; 1957 return &tfm->base;
1927} 1958}
1928 1959
1960/**
1961 * crypto_free_cipher() - zeroize and free the single block cipher handle
1962 * @tfm: cipher handle to be freed
1963 */
1929static inline void crypto_free_cipher(struct crypto_cipher *tfm) 1964static inline void crypto_free_cipher(struct crypto_cipher *tfm)
1930{ 1965{
1931 crypto_free_tfm(crypto_cipher_tfm(tfm)); 1966 crypto_free_tfm(crypto_cipher_tfm(tfm));
1932} 1967}
1933 1968
1969/**
1970 * crypto_has_cipher() - Search for the availability of a single block cipher
1971 * @alg_name: is the cra_name / name or cra_driver_name / driver name of the
1972 * single block cipher
1973 * @type: specifies the type of the cipher
1974 * @mask: specifies the mask for the cipher
1975 *
1976 * Return: true when the single block cipher is known to the kernel crypto API;
1977 * false otherwise
1978 */
1934static inline int crypto_has_cipher(const char *alg_name, u32 type, u32 mask) 1979static inline int crypto_has_cipher(const char *alg_name, u32 type, u32 mask)
1935{ 1980{
1936 type &= ~CRYPTO_ALG_TYPE_MASK; 1981 type &= ~CRYPTO_ALG_TYPE_MASK;
@@ -1945,6 +1990,16 @@ static inline struct cipher_tfm *crypto_cipher_crt(struct crypto_cipher *tfm)
1945 return &crypto_cipher_tfm(tfm)->crt_cipher; 1990 return &crypto_cipher_tfm(tfm)->crt_cipher;
1946} 1991}
1947 1992
1993/**
1994 * crypto_cipher_blocksize() - obtain block size for cipher
1995 * @tfm: cipher handle
1996 *
1997 * The block size for the single block cipher referenced with the cipher handle
1998 * tfm is returned. The caller may use that information to allocate appropriate
1999 * memory for the data returned by the encryption or decryption operation
2000 *
2001 * Return: block size of cipher
2002 */
1948static inline unsigned int crypto_cipher_blocksize(struct crypto_cipher *tfm) 2003static inline unsigned int crypto_cipher_blocksize(struct crypto_cipher *tfm)
1949{ 2004{
1950 return crypto_tfm_alg_blocksize(crypto_cipher_tfm(tfm)); 2005 return crypto_tfm_alg_blocksize(crypto_cipher_tfm(tfm));
@@ -1972,6 +2027,22 @@ static inline void crypto_cipher_clear_flags(struct crypto_cipher *tfm,
1972 crypto_tfm_clear_flags(crypto_cipher_tfm(tfm), flags); 2027 crypto_tfm_clear_flags(crypto_cipher_tfm(tfm), flags);
1973} 2028}
1974 2029
2030/**
2031 * crypto_cipher_setkey() - set key for cipher
2032 * @tfm: cipher handle
2033 * @key: buffer holding the key
2034 * @keylen: length of the key in bytes
2035 *
2036 * The caller provided key is set for the single block cipher referenced by the
2037 * cipher handle.
2038 *
2039 * Note, the key length determines the cipher type. Many block ciphers implement
2040 * different cipher modes depending on the key size, such as AES-128 vs AES-192
2041 * vs. AES-256. When providing a 16 byte key for an AES cipher handle, AES-128
2042 * is performed.
2043 *
2044 * Return: 0 if the setting of the key was successful; < 0 if an error occurred
2045 */
1975static inline int crypto_cipher_setkey(struct crypto_cipher *tfm, 2046static inline int crypto_cipher_setkey(struct crypto_cipher *tfm,
1976 const u8 *key, unsigned int keylen) 2047 const u8 *key, unsigned int keylen)
1977{ 2048{
@@ -1979,6 +2050,15 @@ static inline int crypto_cipher_setkey(struct crypto_cipher *tfm,
1979 key, keylen); 2050 key, keylen);
1980} 2051}
1981 2052
2053/**
2054 * crypto_cipher_encrypt_one() - encrypt one block of plaintext
2055 * @tfm: cipher handle
2056 * @dst: points to the buffer that will be filled with the ciphertext
2057 * @src: buffer holding the plaintext to be encrypted
2058 *
2059 * Invoke the encryption operation of one block. The caller must ensure that
2060 * the plaintext and ciphertext buffers are at least one block in size.
2061 */
1982static inline void crypto_cipher_encrypt_one(struct crypto_cipher *tfm, 2062static inline void crypto_cipher_encrypt_one(struct crypto_cipher *tfm,
1983 u8 *dst, const u8 *src) 2063 u8 *dst, const u8 *src)
1984{ 2064{
@@ -1986,6 +2066,15 @@ static inline void crypto_cipher_encrypt_one(struct crypto_cipher *tfm,
1986 dst, src); 2066 dst, src);
1987} 2067}
1988 2068
2069/**
2070 * crypto_cipher_decrypt_one() - decrypt one block of ciphertext
2071 * @tfm: cipher handle
2072 * @dst: points to the buffer that will be filled with the plaintext
2073 * @src: buffer holding the ciphertext to be decrypted
2074 *
2075 * Invoke the decryption operation of one block. The caller must ensure that
2076 * the plaintext and ciphertext buffers are at least one block in size.
2077 */
1989static inline void crypto_cipher_decrypt_one(struct crypto_cipher *tfm, 2078static inline void crypto_cipher_decrypt_one(struct crypto_cipher *tfm,
1990 u8 *dst, const u8 *src) 2079 u8 *dst, const u8 *src)
1991{ 2080{