diff --git a/Makefile b/Makefile index 2be8825..d66ef26 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,13 @@ -KBUILD_CFLAGS += -I$(src) +# +# Since version 1.6 the asynchronous mode has been +# disabled by default. To re-enable it uncomment the +# corresponding CFLAG. +# +CRYPTODEV_CFLAGS ?= #-DENABLE_ASYNC +KBUILD_CFLAGS += -I$(src) $(CRYPTODEV_CFLAGS) KERNEL_DIR = /lib/modules/$(shell uname -r)/build -VERSION = 1.5 +VERSION = 1.6 +PREFIX = cryptodev-objs = ioctl.o main.o cryptlib.o authenc.o zc.o util.o @@ -12,18 +19,20 @@ build: version.h version.h: Makefile @echo "#define VERSION \"$(VERSION)\"" > version.h -install: +install: modules_install + +modules_install: make -C $(KERNEL_DIR) SUBDIRS=`pwd` modules_install - @echo "Installing cryptodev.h in /usr/include/crypto ..." - @install -D crypto/cryptodev.h /usr/include/crypto/cryptodev.h + @echo "Installing cryptodev.h in $(PREFIX)/usr/include/crypto ..." + @install -D crypto/cryptodev.h $(PREFIX)/usr/include/crypto/cryptodev.h clean: make -C $(KERNEL_DIR) SUBDIRS=`pwd` clean rm -f $(hostprogs) *~ - KERNEL_DIR=$(KERNEL_DIR) make -C tests clean + CFLAGS=$(CRYPTODEV_CFLAGS) KERNEL_DIR=$(KERNEL_DIR) make -C tests clean check: - KERNEL_DIR=$(KERNEL_DIR) make -C tests check + CFLAGS=$(CRYPTODEV_CFLAGS) KERNEL_DIR=$(KERNEL_DIR) make -C tests check FILEBASE = cryptodev-linux-$(VERSION) TMPDIR ?= /tmp diff --git a/NEWS b/NEWS index 138c797..bd1b666 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,16 @@ +Version 1.6 (released 2013-03-20) + +* Added modules_install target in Makefile + +* Added SHA224. Patch by Yashpal Dutta. + +* Asynchronous operations will not be scheduled if zero +copy is disabled. + +* Asynchronous operations are disabled by default, unless +-DENABLE_ASYNC is enabled on Makefile. + + Version 1.5 (released 2012-08-04) * Fixes in AEAD support. Patches by Jaren Johnston. diff --git a/README b/README index 2c18a87..1176e70 100644 --- a/README +++ b/README @@ -4,7 +4,7 @@ from userspace, thus enabling re-use of a hardware implementation of a cipher. For questions and suggestions please use the mailing lists at: -http://home.gna.org/cryptodev-linux/lists.html +http://cryptodev-linux.org/lists.html === How to combine with cryptographic libraries === diff --git a/crypto/cryptodev.h b/crypto/cryptodev.h index 00193a4..a2f11b1 100644 --- a/crypto/cryptodev.h +++ b/crypto/cryptodev.h @@ -45,9 +45,11 @@ enum cryptodev_crypto_op_t { CRYPTO_CAMELLIA_CBC = 101, CRYPTO_RIPEMD160, + CRYPTO_SHA2_224, CRYPTO_SHA2_256, CRYPTO_SHA2_384, CRYPTO_SHA2_512, + CRYPTO_SHA2_224_HMAC, CRYPTO_ALGORITHM_ALL, /* Keep updated - see below */ }; @@ -278,11 +280,13 @@ enum cryptodev_crk_op_t { */ #define CRIOGET_NOT_NEEDED 1 -/* additional ioctls for asynchronous operation */ -#define CIOCASYNCCRYPT _IOW('c', 107, struct crypt_op) -#define CIOCASYNCFETCH _IOR('c', 108, struct crypt_op) - /* additional ioctls for AEAD */ #define CIOCAUTHCRYPT _IOWR('c', 109, struct crypt_auth_op) +/* additional ioctls for asynchronous operation. + * These are conditionally enabled since version 1.6. + */ +#define CIOCASYNCCRYPT _IOW('c', 110, struct crypt_op) +#define CIOCASYNCFETCH _IOR('c', 111, struct crypt_op) + #endif /* L_CRYPTODEV_H */ diff --git a/crypto/cryptodev.h~ b/crypto/cryptodev.h~ new file mode 100644 index 0000000..6382d43 --- /dev/null +++ b/crypto/cryptodev.h~ @@ -0,0 +1,290 @@ +/* This is a source compatible implementation with the original API of + * cryptodev by Angelos D. Keromytis, found at openbsd cryptodev.h. + * Placed under public domain */ + +#ifndef L_CRYPTODEV_H +#define L_CRYPTODEV_H + +#include +#ifndef __KERNEL__ +#define __user +#endif + +/* API extensions for linux */ +#define CRYPTO_HMAC_MAX_KEY_LEN 512 +#define CRYPTO_CIPHER_MAX_KEY_LEN 64 + +/* All the supported algorithms + */ +enum cryptodev_crypto_op_t { + CRYPTO_DES_CBC = 1, + CRYPTO_3DES_CBC = 2, + CRYPTO_BLF_CBC = 3, + CRYPTO_CAST_CBC = 4, + CRYPTO_SKIPJACK_CBC = 5, + CRYPTO_MD5_HMAC = 6, + CRYPTO_SHA1_HMAC = 7, + CRYPTO_RIPEMD160_HMAC = 8, + CRYPTO_MD5_KPDK = 9, + CRYPTO_SHA1_KPDK = 10, + CRYPTO_RIJNDAEL128_CBC = 11, + CRYPTO_AES_CBC = CRYPTO_RIJNDAEL128_CBC, + CRYPTO_ARC4 = 12, + CRYPTO_MD5 = 13, + CRYPTO_SHA1 = 14, + CRYPTO_DEFLATE_COMP = 15, + CRYPTO_NULL = 16, + CRYPTO_LZS_COMP = 17, + CRYPTO_SHA2_256_HMAC = 18, + CRYPTO_SHA2_384_HMAC = 19, + CRYPTO_SHA2_512_HMAC = 20, + CRYPTO_AES_CTR = 21, + CRYPTO_AES_XTS = 22, + CRYPTO_AES_ECB = 23, + CRYPTO_AES_GCM = 50, + + CRYPTO_CAMELLIA_CBC = 101, + CRYPTO_RIPEMD160, + CRYPTO_SHA2_224, + CRYPTO_SHA2_256, + CRYPTO_SHA2_384, + CRYPTO_SHA2_512, + CRYPTO_SHA2_224_HMAC, + CRYPTO_ALGORITHM_ALL, /* Keep updated - see below */ +}; + +#define CRYPTO_ALGORITHM_MAX (CRYPTO_ALGORITHM_ALL - 1) + +/* Values for ciphers */ +#define DES_BLOCK_LEN 8 +#define DES3_BLOCK_LEN 8 +#define RIJNDAEL128_BLOCK_LEN 16 +#define AES_BLOCK_LEN RIJNDAEL128_BLOCK_LEN +#define CAMELLIA_BLOCK_LEN 16 +#define BLOWFISH_BLOCK_LEN 8 +#define SKIPJACK_BLOCK_LEN 8 +#define CAST128_BLOCK_LEN 8 + +/* the maximum of the above */ +#define EALG_MAX_BLOCK_LEN 16 + +/* Values for hashes/MAC */ +#define AALG_MAX_RESULT_LEN 64 + +/* maximum length of verbose alg names (depends on CRYPTO_MAX_ALG_NAME) */ +#define CRYPTODEV_MAX_ALG_NAME 64 + +#define HASH_MAX_LEN 64 + +/* input of CIOCGSESSION */ +struct session_op { + /* Specify either cipher or mac + */ + __u32 cipher; /* cryptodev_crypto_op_t */ + __u32 mac; /* cryptodev_crypto_op_t */ + + __u32 keylen; + __u8 __user *key; + __u32 mackeylen; + __u8 __user *mackey; + + __u32 ses; /* session identifier */ +}; + +struct session_info_op { + __u32 ses; /* session identifier */ + + /* verbose names for the requested ciphers */ + struct alg_info { + char cra_name[CRYPTODEV_MAX_ALG_NAME]; + char cra_driver_name[CRYPTODEV_MAX_ALG_NAME]; + } cipher_info, hash_info; + + __u16 alignmask; /* alignment constraints */ + __u32 flags; /* SIOP_FLAGS_* */ +}; + +/* If this flag is set then this algorithm uses + * a driver only available in kernel (software drivers, + * or drivers based on instruction sets do not set this flag). + * + * If multiple algorithms are involved (as in AEAD case), then + * if one of them is kernel-driver-only this flag will be set. + */ +#define SIOP_FLAG_KERNEL_DRIVER_ONLY 1 + +#define COP_ENCRYPT 0 +#define COP_DECRYPT 1 + +/* input of CIOCCRYPT */ +struct crypt_op { + __u32 ses; /* session identifier */ + __u16 op; /* COP_ENCRYPT or COP_DECRYPT */ + __u16 flags; /* see COP_FLAG_* */ + __u32 len; /* length of source data */ + __u8 __user *src; /* source data */ + __u8 __user *dst; /* pointer to output data */ + /* pointer to output data for hash/MAC operations */ + __u8 __user *mac; + /* initialization vector for encryption operations */ + __u8 __user *iv; +}; + +/* input of CIOCAUTHCRYPT */ +struct crypt_auth_op { + __u32 ses; /* session identifier */ + __u16 op; /* COP_ENCRYPT or COP_DECRYPT */ + __u16 flags; /* see COP_FLAG_AEAD_* */ + __u32 len; /* length of source data */ + __u32 auth_len; /* length of auth data */ + __u8 __user *auth_src; /* authenticated-only data */ + + /* The current implementation is more efficient if data are + * encrypted in-place (src==dst). */ + __u8 __user *src; /* data to be encrypted and authenticated */ + __u8 __user *dst; /* pointer to output data. Must have + * space for tag. For TLS this should be at least + * len + tag_size + block_size for padding */ + + __u8 __user *tag; /* where the tag will be copied to. TLS mode + * doesn't use that as tag is copied to dst. + * SRTP mode copies tag there. */ + __u32 tag_len; /* the length of the tag. Use zero for digest size or max tag. */ + + /* initialization vector for encryption operations */ + __u8 __user *iv; + __u32 iv_len; +}; + +/* In plain AEAD mode the following are required: + * flags : 0 + * iv : the initialization vector (12 bytes) + * auth_len: the length of the data to be authenticated + * auth_src: the data to be authenticated + * len : length of data to be encrypted + * src : the data to be encrypted + * dst : space to hold encrypted data. It must have + * at least a size of len + tag_size. + * tag_size: the size of the desired authentication tag or zero to use + * the maximum tag output. + * + * Note tag isn't being used because the Linux AEAD interface + * copies the tag just after data. + */ + +/* In TLS mode (used for CBC ciphers that required padding) + * the following are required: + * flags : COP_FLAG_AEAD_TLS_TYPE + * iv : the initialization vector + * auth_len: the length of the data to be authenticated only + * len : length of data to be encrypted + * auth_src: the data to be authenticated + * src : the data to be encrypted + * dst : space to hold encrypted data (preferably in-place). It must have + * at least a size of len + tag_size + blocksize. + * tag_size: the size of the desired authentication tag or zero to use + * the default mac output. + * + * Note that the padding used is the minimum padding. + */ + +/* In SRTP mode the following are required: + * flags : COP_FLAG_AEAD_SRTP_TYPE + * iv : the initialization vector + * auth_len: the length of the data to be authenticated. This must + * include the SRTP header + SRTP payload (data to be encrypted) + rest + * + * len : length of data to be encrypted + * auth_src: pointer the data to be authenticated. Should point at the same buffer as src. + * src : pointer to the data to be encrypted. + * dst : This is mandatory to be the same as src (in-place only). + * tag_size: the size of the desired authentication tag or zero to use + * the default mac output. + * tag : Pointer to an address where the authentication tag will be copied. + */ + + +/* struct crypt_op flags */ + +#define COP_FLAG_NONE (0 << 0) /* totally no flag */ +#define COP_FLAG_UPDATE (1 << 0) /* multi-update hash mode */ +#define COP_FLAG_FINAL (1 << 1) /* multi-update final hash mode */ +#define COP_FLAG_WRITE_IV (1 << 2) /* update the IV during operation */ +#define COP_FLAG_NO_ZC (1 << 3) /* do not zero-copy */ +#define COP_FLAG_AEAD_TLS_TYPE (1 << 4) /* authenticate and encrypt using the + * TLS protocol rules */ +#define COP_FLAG_AEAD_SRTP_TYPE (1 << 5) /* authenticate and encrypt using the + * SRTP protocol rules */ +#define COP_FLAG_RESET (1 << 6) /* multi-update reset the state. + * should be used in combination + * with COP_FLAG_UPDATE */ + + +/* Stuff for bignum arithmetic and public key + * cryptography - not supported yet by linux + * cryptodev. + */ + +#define CRYPTO_ALG_FLAG_SUPPORTED 1 +#define CRYPTO_ALG_FLAG_RNG_ENABLE 2 +#define CRYPTO_ALG_FLAG_DSA_SHA 4 + +struct crparam { + __u8 *crp_p; + __u32 crp_nbits; +}; + +#define CRK_MAXPARAM 8 + +/* input of CIOCKEY */ +struct crypt_kop { + __u32 crk_op; /* cryptodev_crk_ot_t */ + __u32 crk_status; + __u16 crk_iparams; + __u16 crk_oparams; + __u32 crk_pad1; + struct crparam crk_param[CRK_MAXPARAM]; +}; + +enum cryptodev_crk_op_t { + CRK_MOD_EXP = 0, + CRK_MOD_EXP_CRT = 1, + CRK_DSA_SIGN = 2, + CRK_DSA_VERIFY = 3, + CRK_DH_COMPUTE_KEY = 4, + CRK_ALGORITHM_ALL +}; + +#define CRK_ALGORITHM_MAX (CRK_ALGORITHM_ALL-1) + +/* features to be queried with CIOCASYMFEAT ioctl + */ +#define CRF_MOD_EXP (1 << CRK_MOD_EXP) +#define CRF_MOD_EXP_CRT (1 << CRK_MOD_EXP_CRT) +#define CRF_DSA_SIGN (1 << CRK_DSA_SIGN) +#define CRF_DSA_VERIFY (1 << CRK_DSA_VERIFY) +#define CRF_DH_COMPUTE_KEY (1 << CRK_DH_COMPUTE_KEY) + + +/* ioctl's. Compatible with old linux cryptodev.h + */ +#define CRIOGET _IOWR('c', 101, __u32) +#define CIOCGSESSION _IOWR('c', 102, struct session_op) +#define CIOCFSESSION _IOW('c', 103, __u32) +#define CIOCCRYPT _IOWR('c', 104, struct crypt_op) +#define CIOCKEY _IOWR('c', 105, struct crypt_kop) +#define CIOCASYMFEAT _IOR('c', 106, __u32) +#define CIOCGSESSINFO _IOWR('c', 107, struct session_info_op) + +/* to indicate that CRIOGET is not required in linux + */ +#define CRIOGET_NOT_NEEDED 1 + +/* additional ioctls for asynchronous operation */ +#define CIOCASYNCCRYPT _IOW('c', 107, struct crypt_op) +#define CIOCASYNCFETCH _IOR('c', 108, struct crypt_op) + +/* additional ioctls for AEAD */ +#define CIOCAUTHCRYPT _IOWR('c', 109, struct crypt_auth_op) + +#endif /* L_CRYPTODEV_H */ diff --git a/debian/changelog b/debian/changelog index 1a41d89..711ff1e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +cryptodev-linux (1.6-1) unstable; urgency=low + + * Upstream version 1.6 + + -- Florian Steinel Sun, 02 Jun 2013 15:06:20 +0200 + cryptodev-linux (1.5-3) unstable; urgency=low * Fix onboot loading of cryptodev once again diff --git a/debian/patches/0001-Fix-Makefile-version-magic.patch b/debian/patches/0001-Fix-Makefile-version-magic.patch deleted file mode 100644 index b5496f2..0000000 --- a/debian/patches/0001-Fix-Makefile-version-magic.patch +++ /dev/null @@ -1,340 +0,0 @@ -From: Bernhard Schuster -Date: Fri, 5 Oct 2012 10:47:27 +0200 -Subject: [PATCH] Fix Makefile version magic - ---- - Makefile | 5 +- - usr/include/crypto/cryptodev.h | 288 ++++++++++++++++++++++++++++++++++++++++ - version.h | 2 +- - 3 files changed, 293 insertions(+), 2 deletions(-) - create mode 100644 usr/include/crypto/cryptodev.h - -diff --git a/Makefile b/Makefile -index 2be8825..815de28 100644 ---- a/Makefile -+++ b/Makefile -@@ -10,6 +10,7 @@ build: version.h - make -C $(KERNEL_DIR) SUBDIRS=`pwd` modules - - version.h: Makefile -+ @cp version.h version.h~ - @echo "#define VERSION \"$(VERSION)\"" > version.h - - install: -@@ -19,11 +20,13 @@ install: - - clean: - make -C $(KERNEL_DIR) SUBDIRS=`pwd` clean -+ if test -f version.h~; then mv version.h~ version.h; fi - rm -f $(hostprogs) *~ - KERNEL_DIR=$(KERNEL_DIR) make -C tests clean - - check: -- KERNEL_DIR=$(KERNEL_DIR) make -C tests check -+ @echo "FIXME! Tests do not work due to compile issues (disabled)" -+# KERNEL_DIR=$(KERNEL_DIR) make -C tests check - - FILEBASE = cryptodev-linux-$(VERSION) - TMPDIR ?= /tmp -diff --git a/usr/include/crypto/cryptodev.h b/usr/include/crypto/cryptodev.h -new file mode 100644 -index 0000000..00193a4 ---- /dev/null -+++ b/usr/include/crypto/cryptodev.h -@@ -0,0 +1,288 @@ -+/* This is a source compatible implementation with the original API of -+ * cryptodev by Angelos D. Keromytis, found at openbsd cryptodev.h. -+ * Placed under public domain */ -+ -+#ifndef L_CRYPTODEV_H -+#define L_CRYPTODEV_H -+ -+#include -+#ifndef __KERNEL__ -+#define __user -+#endif -+ -+/* API extensions for linux */ -+#define CRYPTO_HMAC_MAX_KEY_LEN 512 -+#define CRYPTO_CIPHER_MAX_KEY_LEN 64 -+ -+/* All the supported algorithms -+ */ -+enum cryptodev_crypto_op_t { -+ CRYPTO_DES_CBC = 1, -+ CRYPTO_3DES_CBC = 2, -+ CRYPTO_BLF_CBC = 3, -+ CRYPTO_CAST_CBC = 4, -+ CRYPTO_SKIPJACK_CBC = 5, -+ CRYPTO_MD5_HMAC = 6, -+ CRYPTO_SHA1_HMAC = 7, -+ CRYPTO_RIPEMD160_HMAC = 8, -+ CRYPTO_MD5_KPDK = 9, -+ CRYPTO_SHA1_KPDK = 10, -+ CRYPTO_RIJNDAEL128_CBC = 11, -+ CRYPTO_AES_CBC = CRYPTO_RIJNDAEL128_CBC, -+ CRYPTO_ARC4 = 12, -+ CRYPTO_MD5 = 13, -+ CRYPTO_SHA1 = 14, -+ CRYPTO_DEFLATE_COMP = 15, -+ CRYPTO_NULL = 16, -+ CRYPTO_LZS_COMP = 17, -+ CRYPTO_SHA2_256_HMAC = 18, -+ CRYPTO_SHA2_384_HMAC = 19, -+ CRYPTO_SHA2_512_HMAC = 20, -+ CRYPTO_AES_CTR = 21, -+ CRYPTO_AES_XTS = 22, -+ CRYPTO_AES_ECB = 23, -+ CRYPTO_AES_GCM = 50, -+ -+ CRYPTO_CAMELLIA_CBC = 101, -+ CRYPTO_RIPEMD160, -+ CRYPTO_SHA2_256, -+ CRYPTO_SHA2_384, -+ CRYPTO_SHA2_512, -+ CRYPTO_ALGORITHM_ALL, /* Keep updated - see below */ -+}; -+ -+#define CRYPTO_ALGORITHM_MAX (CRYPTO_ALGORITHM_ALL - 1) -+ -+/* Values for ciphers */ -+#define DES_BLOCK_LEN 8 -+#define DES3_BLOCK_LEN 8 -+#define RIJNDAEL128_BLOCK_LEN 16 -+#define AES_BLOCK_LEN RIJNDAEL128_BLOCK_LEN -+#define CAMELLIA_BLOCK_LEN 16 -+#define BLOWFISH_BLOCK_LEN 8 -+#define SKIPJACK_BLOCK_LEN 8 -+#define CAST128_BLOCK_LEN 8 -+ -+/* the maximum of the above */ -+#define EALG_MAX_BLOCK_LEN 16 -+ -+/* Values for hashes/MAC */ -+#define AALG_MAX_RESULT_LEN 64 -+ -+/* maximum length of verbose alg names (depends on CRYPTO_MAX_ALG_NAME) */ -+#define CRYPTODEV_MAX_ALG_NAME 64 -+ -+#define HASH_MAX_LEN 64 -+ -+/* input of CIOCGSESSION */ -+struct session_op { -+ /* Specify either cipher or mac -+ */ -+ __u32 cipher; /* cryptodev_crypto_op_t */ -+ __u32 mac; /* cryptodev_crypto_op_t */ -+ -+ __u32 keylen; -+ __u8 __user *key; -+ __u32 mackeylen; -+ __u8 __user *mackey; -+ -+ __u32 ses; /* session identifier */ -+}; -+ -+struct session_info_op { -+ __u32 ses; /* session identifier */ -+ -+ /* verbose names for the requested ciphers */ -+ struct alg_info { -+ char cra_name[CRYPTODEV_MAX_ALG_NAME]; -+ char cra_driver_name[CRYPTODEV_MAX_ALG_NAME]; -+ } cipher_info, hash_info; -+ -+ __u16 alignmask; /* alignment constraints */ -+ __u32 flags; /* SIOP_FLAGS_* */ -+}; -+ -+/* If this flag is set then this algorithm uses -+ * a driver only available in kernel (software drivers, -+ * or drivers based on instruction sets do not set this flag). -+ * -+ * If multiple algorithms are involved (as in AEAD case), then -+ * if one of them is kernel-driver-only this flag will be set. -+ */ -+#define SIOP_FLAG_KERNEL_DRIVER_ONLY 1 -+ -+#define COP_ENCRYPT 0 -+#define COP_DECRYPT 1 -+ -+/* input of CIOCCRYPT */ -+struct crypt_op { -+ __u32 ses; /* session identifier */ -+ __u16 op; /* COP_ENCRYPT or COP_DECRYPT */ -+ __u16 flags; /* see COP_FLAG_* */ -+ __u32 len; /* length of source data */ -+ __u8 __user *src; /* source data */ -+ __u8 __user *dst; /* pointer to output data */ -+ /* pointer to output data for hash/MAC operations */ -+ __u8 __user *mac; -+ /* initialization vector for encryption operations */ -+ __u8 __user *iv; -+}; -+ -+/* input of CIOCAUTHCRYPT */ -+struct crypt_auth_op { -+ __u32 ses; /* session identifier */ -+ __u16 op; /* COP_ENCRYPT or COP_DECRYPT */ -+ __u16 flags; /* see COP_FLAG_AEAD_* */ -+ __u32 len; /* length of source data */ -+ __u32 auth_len; /* length of auth data */ -+ __u8 __user *auth_src; /* authenticated-only data */ -+ -+ /* The current implementation is more efficient if data are -+ * encrypted in-place (src==dst). */ -+ __u8 __user *src; /* data to be encrypted and authenticated */ -+ __u8 __user *dst; /* pointer to output data. Must have -+ * space for tag. For TLS this should be at least -+ * len + tag_size + block_size for padding */ -+ -+ __u8 __user *tag; /* where the tag will be copied to. TLS mode -+ * doesn't use that as tag is copied to dst. -+ * SRTP mode copies tag there. */ -+ __u32 tag_len; /* the length of the tag. Use zero for digest size or max tag. */ -+ -+ /* initialization vector for encryption operations */ -+ __u8 __user *iv; -+ __u32 iv_len; -+}; -+ -+/* In plain AEAD mode the following are required: -+ * flags : 0 -+ * iv : the initialization vector (12 bytes) -+ * auth_len: the length of the data to be authenticated -+ * auth_src: the data to be authenticated -+ * len : length of data to be encrypted -+ * src : the data to be encrypted -+ * dst : space to hold encrypted data. It must have -+ * at least a size of len + tag_size. -+ * tag_size: the size of the desired authentication tag or zero to use -+ * the maximum tag output. -+ * -+ * Note tag isn't being used because the Linux AEAD interface -+ * copies the tag just after data. -+ */ -+ -+/* In TLS mode (used for CBC ciphers that required padding) -+ * the following are required: -+ * flags : COP_FLAG_AEAD_TLS_TYPE -+ * iv : the initialization vector -+ * auth_len: the length of the data to be authenticated only -+ * len : length of data to be encrypted -+ * auth_src: the data to be authenticated -+ * src : the data to be encrypted -+ * dst : space to hold encrypted data (preferably in-place). It must have -+ * at least a size of len + tag_size + blocksize. -+ * tag_size: the size of the desired authentication tag or zero to use -+ * the default mac output. -+ * -+ * Note that the padding used is the minimum padding. -+ */ -+ -+/* In SRTP mode the following are required: -+ * flags : COP_FLAG_AEAD_SRTP_TYPE -+ * iv : the initialization vector -+ * auth_len: the length of the data to be authenticated. This must -+ * include the SRTP header + SRTP payload (data to be encrypted) + rest -+ * -+ * len : length of data to be encrypted -+ * auth_src: pointer the data to be authenticated. Should point at the same buffer as src. -+ * src : pointer to the data to be encrypted. -+ * dst : This is mandatory to be the same as src (in-place only). -+ * tag_size: the size of the desired authentication tag or zero to use -+ * the default mac output. -+ * tag : Pointer to an address where the authentication tag will be copied. -+ */ -+ -+ -+/* struct crypt_op flags */ -+ -+#define COP_FLAG_NONE (0 << 0) /* totally no flag */ -+#define COP_FLAG_UPDATE (1 << 0) /* multi-update hash mode */ -+#define COP_FLAG_FINAL (1 << 1) /* multi-update final hash mode */ -+#define COP_FLAG_WRITE_IV (1 << 2) /* update the IV during operation */ -+#define COP_FLAG_NO_ZC (1 << 3) /* do not zero-copy */ -+#define COP_FLAG_AEAD_TLS_TYPE (1 << 4) /* authenticate and encrypt using the -+ * TLS protocol rules */ -+#define COP_FLAG_AEAD_SRTP_TYPE (1 << 5) /* authenticate and encrypt using the -+ * SRTP protocol rules */ -+#define COP_FLAG_RESET (1 << 6) /* multi-update reset the state. -+ * should be used in combination -+ * with COP_FLAG_UPDATE */ -+ -+ -+/* Stuff for bignum arithmetic and public key -+ * cryptography - not supported yet by linux -+ * cryptodev. -+ */ -+ -+#define CRYPTO_ALG_FLAG_SUPPORTED 1 -+#define CRYPTO_ALG_FLAG_RNG_ENABLE 2 -+#define CRYPTO_ALG_FLAG_DSA_SHA 4 -+ -+struct crparam { -+ __u8 *crp_p; -+ __u32 crp_nbits; -+}; -+ -+#define CRK_MAXPARAM 8 -+ -+/* input of CIOCKEY */ -+struct crypt_kop { -+ __u32 crk_op; /* cryptodev_crk_ot_t */ -+ __u32 crk_status; -+ __u16 crk_iparams; -+ __u16 crk_oparams; -+ __u32 crk_pad1; -+ struct crparam crk_param[CRK_MAXPARAM]; -+}; -+ -+enum cryptodev_crk_op_t { -+ CRK_MOD_EXP = 0, -+ CRK_MOD_EXP_CRT = 1, -+ CRK_DSA_SIGN = 2, -+ CRK_DSA_VERIFY = 3, -+ CRK_DH_COMPUTE_KEY = 4, -+ CRK_ALGORITHM_ALL -+}; -+ -+#define CRK_ALGORITHM_MAX (CRK_ALGORITHM_ALL-1) -+ -+/* features to be queried with CIOCASYMFEAT ioctl -+ */ -+#define CRF_MOD_EXP (1 << CRK_MOD_EXP) -+#define CRF_MOD_EXP_CRT (1 << CRK_MOD_EXP_CRT) -+#define CRF_DSA_SIGN (1 << CRK_DSA_SIGN) -+#define CRF_DSA_VERIFY (1 << CRK_DSA_VERIFY) -+#define CRF_DH_COMPUTE_KEY (1 << CRK_DH_COMPUTE_KEY) -+ -+ -+/* ioctl's. Compatible with old linux cryptodev.h -+ */ -+#define CRIOGET _IOWR('c', 101, __u32) -+#define CIOCGSESSION _IOWR('c', 102, struct session_op) -+#define CIOCFSESSION _IOW('c', 103, __u32) -+#define CIOCCRYPT _IOWR('c', 104, struct crypt_op) -+#define CIOCKEY _IOWR('c', 105, struct crypt_kop) -+#define CIOCASYMFEAT _IOR('c', 106, __u32) -+#define CIOCGSESSINFO _IOWR('c', 107, struct session_info_op) -+ -+/* to indicate that CRIOGET is not required in linux -+ */ -+#define CRIOGET_NOT_NEEDED 1 -+ -+/* additional ioctls for asynchronous operation */ -+#define CIOCASYNCCRYPT _IOW('c', 107, struct crypt_op) -+#define CIOCASYNCFETCH _IOR('c', 108, struct crypt_op) -+ -+/* additional ioctls for AEAD */ -+#define CIOCAUTHCRYPT _IOWR('c', 109, struct crypt_auth_op) -+ -+#endif /* L_CRYPTODEV_H */ -diff --git a/version.h b/version.h -index ad34f8d..0b62be9 100644 ---- a/version.h -+++ b/version.h -@@ -1 +1 @@ --#define VERSION "1.4" -+#define VERSION "1.5" --- diff --git a/debian/patches/series b/debian/patches/series deleted file mode 100644 index 8d1a3c9..0000000 --- a/debian/patches/series +++ /dev/null @@ -1 +0,0 @@ -0001-Fix-Makefile-version-magic.patch diff --git a/extras/eng_cryptodev.c b/extras/eng_cryptodev.c index e3265bb..a312316 100644 --- a/extras/eng_cryptodev.c +++ b/extras/eng_cryptodev.c @@ -857,7 +857,11 @@ static const EVP_MD cryptodev_sha1 = { NID_sha1, NID_sha1WithRSAEncryption, SHA_DIGEST_LENGTH, - EVP_MD_FLAG_PKEY_METHOD_SIGNATURE|EVP_MD_FLAG_DIGALGID_ABSENT|EVP_MD_FLAG_ONESHOT, +#if defined(EVP_MD_FLAG_PKEY_METHOD_SIGNATURE) && defined(EVP_MD_FLAG_DIGALGID_ABSENT) + EVP_MD_FLAG_PKEY_METHOD_SIGNATURE| + EVP_MD_FLAG_DIGALGID_ABSENT| +#endif + EVP_MD_FLAG_ONESHOT, cryptodev_digest_init, cryptodev_digest_update, cryptodev_digest_final, @@ -872,7 +876,29 @@ static const EVP_MD cryptodev_sha256 = { NID_sha256, NID_sha256WithRSAEncryption, SHA256_DIGEST_LENGTH, - EVP_MD_FLAG_PKEY_METHOD_SIGNATURE|EVP_MD_FLAG_DIGALGID_ABSENT|EVP_MD_FLAG_ONESHOT, +#if defined(EVP_MD_FLAG_PKEY_METHOD_SIGNATURE) && defined(EVP_MD_FLAG_DIGALGID_ABSENT) + EVP_MD_FLAG_PKEY_METHOD_SIGNATURE| + EVP_MD_FLAG_DIGALGID_ABSENT| +#endif + EVP_MD_FLAG_ONESHOT, + cryptodev_digest_init, + cryptodev_digest_update, + cryptodev_digest_final, + cryptodev_digest_copy, + cryptodev_digest_cleanup, + EVP_PKEY_RSA_method, + SHA256_CBLOCK, + sizeof(EVP_MD *)+sizeof(struct dev_crypto_state), +}; +static const EVP_MD cryptodev_sha224 = { + NID_sha224, + NID_sha224WithRSAEncryption, + SHA224_DIGEST_LENGTH, +#if defined(EVP_MD_FLAG_PKEY_METHOD_SIGNATURE) && defined(EVP_MD_FLAG_DIGALGID_ABSENT) + EVP_MD_FLAG_PKEY_METHOD_SIGNATURE| + EVP_MD_FLAG_DIGALGID_ABSENT| +#endif + EVP_MD_FLAG_ONESHOT, cryptodev_digest_init, cryptodev_digest_update, cryptodev_digest_final, @@ -887,7 +913,11 @@ static const EVP_MD cryptodev_sha384 = { NID_sha384, NID_sha384WithRSAEncryption, SHA384_DIGEST_LENGTH, - EVP_MD_FLAG_PKEY_METHOD_SIGNATURE|EVP_MD_FLAG_DIGALGID_ABSENT|EVP_MD_FLAG_ONESHOT, +#if defined(EVP_MD_FLAG_PKEY_METHOD_SIGNATURE) && defined(EVP_MD_FLAG_DIGALGID_ABSENT) + EVP_MD_FLAG_PKEY_METHOD_SIGNATURE| + EVP_MD_FLAG_DIGALGID_ABSENT| +#endif + EVP_MD_FLAG_ONESHOT, cryptodev_digest_init, cryptodev_digest_update, cryptodev_digest_final, @@ -902,7 +932,11 @@ static const EVP_MD cryptodev_sha512 = { NID_sha512, NID_sha512WithRSAEncryption, SHA512_DIGEST_LENGTH, - EVP_MD_FLAG_PKEY_METHOD_SIGNATURE|EVP_MD_FLAG_DIGALGID_ABSENT|EVP_MD_FLAG_ONESHOT, +#if defined(EVP_MD_FLAG_PKEY_METHOD_SIGNATURE) && defined(EVP_MD_FLAG_DIGALGID_ABSENT) + EVP_MD_FLAG_PKEY_METHOD_SIGNATURE| + EVP_MD_FLAG_DIGALGID_ABSENT| +#endif + EVP_MD_FLAG_ONESHOT, cryptodev_digest_init, cryptodev_digest_update, cryptodev_digest_final, @@ -917,7 +951,11 @@ static const EVP_MD cryptodev_md5 = { NID_md5, NID_md5WithRSAEncryption, 16 /* MD5_DIGEST_LENGTH */, - EVP_MD_FLAG_PKEY_METHOD_SIGNATURE|EVP_MD_FLAG_DIGALGID_ABSENT|EVP_MD_FLAG_ONESHOT, +#if defined(EVP_MD_FLAG_PKEY_METHOD_SIGNATURE) && defined(EVP_MD_FLAG_DIGALGID_ABSENT) + EVP_MD_FLAG_PKEY_METHOD_SIGNATURE| + EVP_MD_FLAG_DIGALGID_ABSENT| +#endif + EVP_MD_FLAG_ONESHOT, cryptodev_digest_init, cryptodev_digest_update, cryptodev_digest_final, @@ -946,6 +984,9 @@ cryptodev_engine_digests(ENGINE *e, const EVP_MD **digest, case NID_sha1: *digest = &cryptodev_sha1; break; + case NID_sha224: + *digest = &cryptodev_sha224; + break; case NID_sha256: *digest = &cryptodev_sha256; break; @@ -1358,8 +1399,9 @@ cryptodev_dh_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh) kop.crk_iparams = 3; kop.crk_param[3].crp_p = (void*) key; - kop.crk_param[3].crp_nbits = keylen * 8; + kop.crk_param[3].crp_nbits = keylen; kop.crk_oparams = 1; + dhret = keylen/8; if (ioctl(fd, CIOCKEY, &kop) == -1) { const DH_METHOD *meth = DH_OpenSSL(); diff --git a/ioctl.c b/ioctl.c index a81b601..f26cf93 100644 --- a/ioctl.c +++ b/ioctl.c @@ -164,6 +164,10 @@ crypto_create_session(struct fcrypt *fcr, struct session_op *sop) case CRYPTO_SHA1_HMAC: hash_name = "hmac(sha1)"; break; + case CRYPTO_SHA2_224_HMAC: + hash_name = "hmac(sha224)"; + break; + case CRYPTO_SHA2_256_HMAC: hash_name = "hmac(sha256)"; break; @@ -187,6 +191,10 @@ crypto_create_session(struct fcrypt *fcr, struct session_op *sop) hash_name = "sha1"; hmac_mode = 0; break; + case CRYPTO_SHA2_224: + hash_name = "sha224"; + hmac_mode = 0; + break; case CRYPTO_SHA2_256: hash_name = "sha256"; hmac_mode = 0; @@ -530,6 +538,7 @@ clonefd(struct file *filp) return ret; } +#ifdef ENABLE_ASYNC /* enqueue a job for asynchronous completion * * returns: @@ -540,6 +549,9 @@ clonefd(struct file *filp) static int crypto_async_run(struct crypt_priv *pcr, struct kernel_crypt_op *kcop) { struct todo_list_item *item = NULL; + + if (unlikely(kcop->cop.flags & COP_FLAG_NO_ZC)) + return -EINVAL; mutex_lock(&pcr->free.lock); if (likely(!list_empty(&pcr->free.list))) { @@ -604,6 +616,7 @@ static int crypto_async_fetch(struct crypt_priv *pcr, return retval; } +#endif /* this function has to be called from process context */ static int fill_kcop_from_cop(struct kernel_crypt_op *kcop, struct fcrypt *fcr) @@ -856,6 +869,7 @@ cryptodev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg_) return ret; } return kcaop_to_user(&kcaop, fcr, arg); +#ifdef ENABLE_ASYNC case CIOCASYNCCRYPT: if (unlikely(ret = kcop_from_user(&kcop, fcr, arg))) return ret; @@ -867,6 +881,7 @@ cryptodev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg_) return ret; return kcop_to_user(&kcop, fcr, arg); +#endif default: return -EINVAL; } @@ -1012,6 +1027,7 @@ cryptodev_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg_) return ret; return compat_kcop_to_user(&kcop, fcr, arg); +#ifdef ENABLE_ASYNC case COMPAT_CIOCASYNCCRYPT: if (unlikely(ret = compat_kcop_from_user(&kcop, fcr, arg))) return ret; @@ -1023,7 +1039,7 @@ cryptodev_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg_) return ret; return compat_kcop_to_user(&kcop, fcr, arg); - +#endif default: return -EINVAL; } diff --git a/tests/Makefile b/tests/Makefile index 87ca3c7..c9f04e8 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,6 +1,6 @@ KERNEL_DIR ?= /lib/modules/$(shell uname -r)/build -KBUILD_CFLAGS += -I.. -CFLAGS += -I.. +KBUILD_CFLAGS += -I.. $(CRYPTODEV_CFLAGS) +CFLAGS += -I.. $(CRYPTODEV_CFLAGS) comp_progs := cipher_comp hash_comp hmac_comp diff --git a/tests/async_cipher.c b/tests/async_cipher.c index 96ef7bc..162a695 100644 --- a/tests/async_cipher.c +++ b/tests/async_cipher.c @@ -15,6 +15,8 @@ #include "testhelper.h" +#ifdef ENABLE_ASYNC + static int debug = 0; #define DATA_SIZE 8*1024 @@ -327,4 +329,10 @@ main(int argc, char** argv) return 0; } - +#else +int +main(int argc, char** argv) +{ + return (0); +} +#endif diff --git a/tests/async_hmac.c b/tests/async_hmac.c index 4083e89..97fd0c5 100644 --- a/tests/async_hmac.c +++ b/tests/async_hmac.c @@ -16,6 +16,8 @@ #include "testhelper.h" +#ifdef ENABLE_ASYNC + static int debug = 0; #define DATA_SIZE 4096 @@ -292,3 +294,10 @@ main() return 0; } +#else +int +main(int argc, char** argv) +{ + return (0); +} +#endif diff --git a/tests/async_speed.c b/tests/async_speed.c index 4aea5e3..1188599 100644 --- a/tests/async_speed.c +++ b/tests/async_speed.c @@ -28,6 +28,8 @@ #include #include +#ifdef ENABLE_ASYNC + static double udifftimeval(struct timeval start, struct timeval end) { return (double)(end.tv_usec - start.tv_usec) + @@ -213,3 +215,11 @@ int main(void) close(fd); return 0; } + +#else +int +main(int argc, char** argv) +{ + return (0); +} +#endif diff --git a/version.h b/version.h index ad34f8d..83d49da 100644 --- a/version.h +++ b/version.h @@ -1 +1 @@ -#define VERSION "1.4" +#define VERSION "1.6"