From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751612AbcDAQbU (ORCPT ); Fri, 1 Apr 2016 12:31:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47725 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750804AbcDAQbT (ORCPT ); Fri, 1 Apr 2016 12:31:19 -0400 Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells In-Reply-To: <1459345402-24112-1-git-send-email-k.marinushkin@gmail.com> References: <1459345402-24112-1-git-send-email-k.marinushkin@gmail.com> To: Kirill Marinushkin Cc: dhowells@redhat.com, keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] Security: Keys: Big keys stored encrypted MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <32087.1459528276.1@warthog.procyon.org.uk> Date: Fri, 01 Apr 2016 17:31:16 +0100 Message-ID: <32088.1459528276@warthog.procyon.org.uk> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Kirill Marinushkin wrote: > +enum { > + ENC, > + DEC, > +}; "enum big_key_mode" and use it as a parameter type to big_key_crypt(). Also BIG_KEY_ENC, BIG_KEY_DEC. Please use prefixes consistently. > +static const char *rng_name = "stdrng"; > + > +/* > + * Algorithm name for big_key data encryption > + */ > +static const char *alg_name = "ecb(aes)"; Use const char arrays not const char pointers as that saves on a pointer storage. > +/* > + * Aligned data length of big_key encryption > + */ > +#define ALIGNED_LEN(l) (l + ENC_BLOCK_SIZE - l % ENC_BLOCK_SIZE) Surely there's a crypto thing for this? The block size and key size ought to be functions of the algorithm you select rather than being hardcoded. > +static int gen_enckey(u8 *key) big_key_gen_enckey(). > +{ > + int ret = -EINVAL; > + struct crypto_rng *rng = NULL; > + > + rng = crypto_alloc_rng(rng_name, 0, 0); > + if (IS_ERR(rng)) > + return -EFAULT; > + > + ret = crypto_rng_reset(rng, NULL, crypto_rng_seedsize(rng)); > + > + if (!ret) > + ret = crypto_rng_get_bytes(rng, key, ENC_KEY_SIZE); > + > + if (rng) rng can be NULL here?! > +static int big_crypt(u8 op, u8 *data, size_t datalen, u8 *key) big_key_crypt().