#define ll_crypto_hash_init(desc) crypto_hash_init(desc)
#define ll_crypto_hash_update(desc, sl, bytes) crypto_hash_update(desc, sl, bytes)
#define ll_crypto_hash_final(desc, out) crypto_hash_final(desc, out)
-#define ll_crypto_alloc_blkcipher(name, type, mask) \
- crypto_alloc_blkcipher(name ,type, mask)
#define ll_crypto_blkcipher_setkey(tfm, key, keylen) \
crypto_blkcipher_setkey(tfm, key, keylen)
#define ll_crypto_blkcipher_set_iv(tfm, src, len) \
#define ll_crypto_blkcipher_decrypt_iv(desc, dst, src, bytes) \
crypto_blkcipher_decrypt_iv(desc, dst, src, bytes)
+static inline
+struct ll_crypto_cipher *ll_crypto_alloc_blkcipher(const char *name,
+ u32 type, u32 mask)
+{
+ struct ll_crypto_cipher *rtn = crypto_alloc_blkcipher(name, type, mask);
+
+ return (rtn == NULL ? ERR_PTR(-ENOMEM) : rtn);
+}
+
static inline int ll_crypto_hmac(struct ll_crypto_hash *tfm,
u8 *key, unsigned int *keylen,
struct scatterlist *sg,
struct ll_crypto_cipher *ll_crypto_alloc_blkcipher(const char * algname,
u32 type, u32 mask)
{
- char buf[CRYPTO_MAX_ALG_NAME + 1];
- const char *pan = algname;
- u32 flag = 0;
-
- if (strncmp("cbc(", algname, 4) == 0)
- flag |= CRYPTO_TFM_MODE_CBC;
- else if (strncmp("ecb(", algname, 4) == 0)
- flag |= CRYPTO_TFM_MODE_ECB;
- if (flag) {
- char *vp = strnchr(algname, CRYPTO_MAX_ALG_NAME, ')');
- if (vp) {
- memcpy(buf, algname + 4, vp - algname - 4);
- buf[vp - algname - 4] = '\0';
- pan = buf;
- } else {
- flag = 0;
- }
- }
- return crypto_alloc_tfm(pan, flag);
+ struct ll_crypto_cipher *rtn;
+ char buf[CRYPTO_MAX_ALG_NAME + 1];
+ const char *pan = algname;
+ u32 flag = 0;
+
+ if (strncmp("cbc(", algname, 4) == 0)
+ flag |= CRYPTO_TFM_MODE_CBC;
+ else if (strncmp("ecb(", algname, 4) == 0)
+ flag |= CRYPTO_TFM_MODE_ECB;
+ if (flag) {
+ char *vp = strnchr(algname, CRYPTO_MAX_ALG_NAME, ')');
+ if (vp) {
+ memcpy(buf, algname + 4, vp - algname - 4);
+ buf[vp - algname - 4] = '\0';
+ pan = buf;
+ } else {
+ flag = 0;
+ }
+ }
+ rtn = crypto_alloc_tfm(pan, flag);
+ return (rtn == NULL ? ERR_PTR(-ENOMEM) : rtn);
}
static inline
char alg[CRYPTO_MAX_ALG_NAME+1] = "aes";
ENTRY;
- /* passing "aes" in a variable instead of a constant string keeps gcc
- * 4.3.2 happy */
- tfm = ll_crypto_alloc_blkcipher(alg, 0, 0 );
- if (tfm == NULL) {
- CERROR("failed to load transform for aes\n");
- RETURN(-EFAULT);
- }
+ /* passing "aes" in a variable instead of a constant string keeps gcc
+ * 4.3.2 happy */
+ tfm = ll_crypto_alloc_blkcipher(alg, 0, 0 );
+ if (IS_ERR(tfm)) {
+ CERROR("failed to load transform for aes\n");
+ RETURN(PTR_ERR(tfm));
+ }
min = ll_crypto_tfm_alg_min_keysize(tfm);
if (keylen < min) {
char alg[CRYPTO_MAX_ALG_NAME+1] = "aes";
ENTRY;
- /* passing "aes" in a variable instead of a constant string keeps gcc
- * 4.3.2 happy */
- tfm = ll_crypto_alloc_blkcipher(alg, 0, 0 );
- if (tfm == NULL) {
- CERROR("failed to load transform for aes\n");
- RETURN(-EFAULT);
- }
+ /* passing "aes" in a variable instead of a constant string keeps gcc
+ * 4.3.2 happy */
+ tfm = ll_crypto_alloc_blkcipher(alg, 0, 0 );
+ if (IS_ERR(tfm)) {
+ CERROR("failed to load transform for aes\n");
+ RETURN(PTR_ERR(tfm));
+ }
min = ll_crypto_tfm_alg_min_keysize(tfm);
if (keylen < min) {
static
int keyblock_init(struct krb5_keyblock *kb, char *alg_name, int alg_mode)
{
- kb->kb_tfm = ll_crypto_alloc_blkcipher(alg_name, alg_mode, 0);
- if (kb->kb_tfm == NULL) {
- CERROR("failed to alloc tfm: %s, mode %d\n",
- alg_name, alg_mode);
- return -1;
- }
+ kb->kb_tfm = ll_crypto_alloc_blkcipher(alg_name, alg_mode, 0);
+ if (IS_ERR(kb->kb_tfm)) {
+ CERROR("failed to alloc tfm: %s, mode %d\n",
+ alg_name, alg_mode);
+ return -1;
+ }
if (ll_crypto_blkcipher_setkey(kb->kb_tfm, kb->kb_key.data, kb->kb_key.len)) {
CERROR("failed to set %s key, len %d\n",
GOTO(arc4_out, rc = -EACCES);
}
- arc4_tfm = ll_crypto_alloc_blkcipher("ecb(arc4)", 0, 0);
- if (arc4_tfm == NULL) {
- CERROR("failed to alloc tfm arc4 in ECB mode\n");
- GOTO(arc4_out_key, rc = -EACCES);
- }
+ arc4_tfm = ll_crypto_alloc_blkcipher("ecb(arc4)", 0, 0);
+ if (IS_ERR(arc4_tfm)) {
+ CERROR("failed to alloc tfm arc4 in ECB mode\n");
+ GOTO(arc4_out_key, rc = -EACCES);
+ }
if (ll_crypto_blkcipher_setkey(arc4_tfm, arc4_keye.data,
arc4_keye.len)) {
GOTO(arc4_out, rc = -EACCES);
}
- arc4_tfm = ll_crypto_alloc_blkcipher("ecb(arc4)", 0, 0);
- if (arc4_tfm == NULL) {
- CERROR("failed to alloc tfm arc4 in ECB mode\n");
- GOTO(arc4_out_key, rc = -EACCES);
- }
+ arc4_tfm = ll_crypto_alloc_blkcipher("ecb(arc4)", 0, 0);
+ if (IS_ERR(arc4_tfm)) {
+ CERROR("failed to alloc tfm arc4 in ECB mode\n");
+ GOTO(arc4_out_key, rc = -EACCES);
+ }
if (ll_crypto_blkcipher_setkey(arc4_tfm,
arc4_keye.data, arc4_keye.len)) {