On Thu, May 12, 2016 at 06:00:33PM +0300, Tudor Ambarus wrote: > > int rsa_get_n(void *context, size_t hdrlen, unsigned char tag, > const void *value, size_t vlen) > { > struct rsa_key *key = context; > + const char *ptr = value; > + int ret; > > - key->n = mpi_read_raw_data(value, vlen); > - > - if (!key->n) > - return -ENOMEM; > + while (!*ptr && vlen) { > + ptr++; > + vlen--; > + } > > /* In FIPS mode only allow key size 2K & 3K */ > - if (fips_enabled && (mpi_get_size(key->n) != 256 && > - mpi_get_size(key->n) != 384)) { > + if (fips_enabled && (vlen != 256 && vlen != 384)) { > pr_err("RSA: key size not allowed in FIPS mode\n"); > - mpi_free(key->n); > - key->n = NULL; > return -EINVAL; > } > + /* invalid key size provided */ > + ret = rsa_check_key_length(vlen << 3); > + if (ret) > + return ret; > + > + key->n = kzalloc(vlen, key->flags); > + if (!key->n) > + return -ENOMEM; > + The helper shouldn't be copying it at all. Just return the raw key as is and then the caller can copy it or MPI parse it, etc. The helper should just do the parsing and nothing else. Cheers, -- Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt -- To unsubscribe from this list: send the line "unsubscribe linux-crypto" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html