hu_RSAKeySet()

Creates an RSA private and/or public key object from the given key value(s).

Synopsis:

#include "hursa.h"
 
int hu_RSAKeySet(sb_Params rsaParams, size_t eLen, const unsigned char *e, size_t nLen, const unsigned char *n, size_t dLen, const unsigned char *d, size_t pLen, const unsigned char *p, size_t qLen, const unsigned char *q, size_t dModPLen, const unsigned char *dModPm1, size_t dModQLen, const unsigned char *dModQm1, size_t qInvLen, const unsigned char *qInvModP, sb_PrivateKey *privateKey, sb_PublicKey *publicKey, sb_GlobalCtx sbCtx)

Since:

BlackBerry 10.0.0

Arguments:

rsaParams

An RSA parameters object.

eLen

The length (in bytes) of the public exponent. Must be less than or equal to nLen.

e

The public exponent.

nLen

The length (in bytes) of the modulus.

n

The modulus.

dLen

The length (in bytes) of the private exponent. Must be less than or equal to nLen.

d

The private exponent.

pLen

The length (in bytes) of the first prime p. Must be less than or equal to nLen.

p

First large prime factor of the modulus.

qLen

The length (in bytes) of the second prime p. Must be less than or equal to nLen.

q

Second large prime factor of the modulus.

dModPLen

The length (in bytes) of the d mod p-1 CRT coefficient. Must be equal to pLen.

dModPm1

d mod p-1 CRT coefficient.

dModQLen

The length (in bytes) of the d mod q-1 CRT coefficient. Must be equal to qLen.

dModQm1

d mod q-1 CRT coefficient.

qInvLen

The length (in bytes) of q inverse mod p CRT coefficient.

qInvModP

q inverse mod p CRT coefficient.

privateKey

The private key object pointer.

publicKey

The public key object pointer.

sbCtx

A global context.

Library:

libhuapi (For the qcc command, use the -l huapi option to link against this library)

Description:

A private key object can be created by supplying one of the following combinations of key data:

  • p, q, d
  • p, q, d mod p-1, d mod q-1
  • n, d, e
  • n, d

Private key objects contains the key data in the CRT format. The following rules apply:

  • If p and q are supplied, either d mod p-1 and d mod q-1, or d must be supplied. If all three are supplied, d will be ignored, and no check will be performed to ensure that the values are self-consistent.
  • If p, q and qInvModP are supplied, then no check is performed to ensure that the values are self-consistent.
  • If n and d are supplied, n is factored to construct CRT format using e. In all cases, public exponent e is required. If e is not supplied, this function will assume a default value of 65537 (0x10001) as the public exponent.

Private key object always

A public key object can be created by supplying n and, optionally, e. If e is not supplied, this function will assume a default value of 65537 (0x10001) as the public exponent.

Returns:

SB_ERR_NULL_PARAMS

The rsaParams object is NULL.

SB_ERR_BAD_PARAMS

The tag for the params object is not of the expected type.

SB_ERR_NULL_OUTPUT

Both the private and public key object pointers are NULL.

SB_ERR_BAD_INPUT

Not enough key data supplied to create a key.

SB_ERR_BAD_RSA_E_LEN

The length of the public exponent is invalid.

SB_FAIL_ALLOC

Memory allocation failure.

SB_SUCCESS

Success.