lkml.org 
[lkml]   [2013]   [Sep]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH V4 04/15] asymmetric keys: implement OS2IP in rsa
    Date
    Implement Octet String to Integer conversion [RFC3447 sec 4.2] in rsa.c. It's
    the second step of signature generation operation.

    This patch is temporary set non-RSASP1 message to pks->S for debugging.

    The naming of RSA_OS2IP and the variables used in this function accord PKCS#1
    spec but not follow kernel naming convention, it useful when look at them with
    spec.

    Reference: ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-1v2/pkcs1ietffinal.txt
    Reference: http://www.emc.com/collateral/white-papers/h11300-pkcs-1v2-2-rsa-cryptography-standard-wp.pdf

    Cc: Pavel Machek <pavel@ucw.cz>
    Reviewed-by: Jiri Kosina <jkosina@suse.cz>
    Signed-off-by: Lee, Chun-Yi <jlee@suse.com>
    ---
    crypto/asymmetric_keys/rsa.c | 29 ++++++++++++++++++++++++-----
    1 files changed, 24 insertions(+), 5 deletions(-)

    diff --git a/crypto/asymmetric_keys/rsa.c b/crypto/asymmetric_keys/rsa.c
    index aac8b77..a092aac 100644
    --- a/crypto/asymmetric_keys/rsa.c
    +++ b/crypto/asymmetric_keys/rsa.c
    @@ -168,6 +168,20 @@ static int RSA_I2OSP(MPI x, size_t xLen, u8 **_X)
    }

    /*
    + * Octet String to Integer conversion [RFC3447 sec 4.2]
    + */
    +static int RSA_OS2IP(u8 *X, size_t XLen, MPI *_x)
    +{
    + MPI x;
    +
    + x = mpi_alloc((XLen + BYTES_PER_MPI_LIMB - 1) / BYTES_PER_MPI_LIMB);
    + mpi_set_buffer(x, X, XLen, 0);
    +
    + *_x = x;
    + return 0;
    +}
    +
    +/*
    * EMSA_PKCS1-v1_5-ENCODE [RFC3447 sec 9.2]
    * @M: message to be signed, an octet string
    * @emLen: intended length in octets of the encoded message
    @@ -419,6 +433,9 @@ static struct public_key_signature *RSA_generate_signature(
    {
    struct public_key_signature *pks;
    u8 *EM = NULL;
    + MPI m = NULL;
    + MPI s = NULL;
    + unsigned X_size;
    size_t emLen;
    int ret;

    @@ -438,14 +455,16 @@ static struct public_key_signature *RSA_generate_signature(
    if (ret < 0)
    goto error_v1_5_encode;

    - /* TODO 2): m = OS2IP (EM) */
    + /* 2): m = OS2IP (EM) */
    + ret = RSA_OS2IP(EM, emLen, &m);
    + if (ret < 0)
    + goto error_v1_5_encode;

    /* TODO 3): s = RSASP1 (K, m) */
    + s = m;

    - /* TODO 4): S = I2OSP (s, k) */
    -
    - /* TODO: signature S to a u8* S or set to sig->rsa.s? */
    - pks->S = EM; /* TODO: temporary set S to EM */
    + /* 4): S = I2OSP (s, k) */
    + _RSA_I2OSP(s, &X_size, &pks->S);

    return pks;

    --
    1.6.0.2


    \
     
     \ /
      Last update: 2013-09-15 03:21    [W:5.818 / U:0.440 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site