lkml.org 
[lkml]   [2015]   [Jun]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH RFC v3 1/3] crypto: add PKE API
On Wed, Jun 03, 2015 at 03:44:08PM -0700, Tadeusz Struk wrote:
>
> +/**
> + * struct akcipher_alg - generic public key algorithm
> + *
> + * @sign: Function performs a sign operation as defined by public key
> + * algorithm
> + * @verify: Function performs a sign operation as defined by public key
> + * algorithm
> + * @encrypt: Function performs an encrytp operation as defined by public key
> + * algorithm
> + * @decrypt: Function performs a decrypt operation as defined by public key
> + * algorithm
> + * @reqsize: Request context size required by algorithm implementation
> + * @base: Common crypto API algorithm data structure
> + */
> +struct akcipher_alg {
> + int (*sign)(struct akcipher_request *req);
> + int (*verify)(struct akcipher_request *req);
> + int (*encrypt)(struct akcipher_request *req);
> + int (*decrypt)(struct akcipher_request *req);
> +
> + unsigned int reqsize;
> + struct crypto_alg base;
> +};

Because the caller is going to be allocating memory for the output,
we need to provide a way for them to know how much memory to
allocate.

This presumably will depend on the key size.

So something like

int (*maxsize)(struct crypto_akcipher *tfm);

is needed.

You should also provide setkey here. You can't just save a pointer
to the key. The transform must hold the key physically as the
original may go away. It should also ensure that the key is
actually valid for the transform.

> +/**
> + * struct crypto_akcipher - user-instantiated objects which encapsulate
> + * algorithms and core processing logic
> + *
> + * @base: Common crypto API algorithm data structure
> + * @pkey: Key representation. Note: this can be both public or private
> + * key, depending on the operation.
> + * @__ctx: Start of private context data
> + */
> +struct crypto_akcipher {
> + struct crypto_tfm base;
> + const struct public_key *pkey;
> + void *__ctx[] CRYPTO_MINALIGN_ATTR;
> +};

base already has ctx so you should get rid of ctx and move base
to the end of the struct.

Cheers,
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt


\
 
 \ /
  Last update: 2015-06-04 09:01    [W:0.785 / U:0.448 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site