sx_async_mod_single_op_cmd_go

C

struct sx_pk_dreq sx_async_mod_single_op_cmd_go(
      struct sx_pk_cnx *cnx,
      const struct sx_pk_cmd_def *cmd,
      const sx_op *modulo,
      const sx_op *b)

Description

Asynchronous (non-blocking) Primitive modular operation with 1 operand Start a primitive modular operation with 1 operand on the accelerator and return immediately. When the operation finishes on the accelerator, call sx_async_finish_single()

Parameters

ParamDescription
cnxConnection structure obtained through SX_PK_OPEN() at startup
cmdcmd Command definition. Should be a primitive modular operation with 1 operands. For example: SX_PK_CMD_ODD_MOD_INV, SX_PK_CMD_ODD_MOD_REDUCE, SX_PK_CMD_EVEN_MOD_INV, SX_PK_CMD_EVEN_MOD_REDUCE
moduloModulus operand. Must be odd if using SX_PK_CMD_ODD_MOD_INV or SX_PK_CMD_ODD_MOD_REDUCE command and even when using SX_PK_CMD_EVEN_MOD_INV or SX_PK_CMD_EVEN_MOD_REDUCE command
bOperand of modular operation

Returns

Acquired acceleration request for this operation

sx_mod_single_op_cmd

C

int sx_mod_single_op_cmd(
      struct sx_pk_cnx *cnx,
      const struct sx_pk_cmd_def *cmd,
      const sx_op *modulo,
      const sx_op *b,
      sx_op *result)```

## Description

Compute single operand modular operation
 - result = b mod modulo for SX_PK_CMD_ODD_MOD_REDUCE, SX_PK_CMD_EVEN_MOD_REDUCE
 - result = 1 / b mod modulo for SX_PK_CMD_ODD_MOD_INV, SX_PK_CMD_EVEN_MOD_INV

## Parameters

| Param | Description |
|:----- |:----------- |
| cnx |  Connection structure obtained through SX_PK_OPEN() at startup |
| cmd | cmd Command definition. Should be a primitive modular operation with 1 operands. For example: SX_PK_CMD_ODD_MOD_REDUCE, SX_PK_CMD_ODD_MOD_INV, SX_PK_CMD_EVEN_MOD_REDUCE, SX_PK_CMD_EVEN_MOD_INV |
| modulo | modulo Modulus operand. Must be odd if using SX_PK_CMD_ODD_MOD_INV or SX_PK_CMD_ODD_MOD_REDUCE command and even when using SX_PK_CMD_EVEN_MOD_INV or SX_PK_CMD_EVEN_MOD_REDUCE command |
| b | Operand of modular operation |
| result | Result Operand |

## See
sx_async_mod_single_op_cmd_go() and sx_async_finish_single() for an asynchronous version

## Returns
SX_OK
SX_ERR_INVALID_PARAM
SX_ERR_NOT_INVERTIBLE
SX_ERR_UNKNOWN_ERROR
SX_ERR_BUSY
SX_ERR_NOT_IMPLEMENTED
SX_ERR_OPERAND_TOO_LARGE
SX_ERR_PLATFORM_ERROR
SX_ERR_EXPIRED

# sx_async_mod_cmd_go

## C

```c
struct sx_pk_dreq sx_async_mod_cmd_go(
      struct sx_pk_cnx *cnx,
      const struct sx_pk_cmd_def *cmd,
      const sx_op *modulo,
      const sx_op *a,
      const sx_op *b)

Description

Asynchronous (non-blocking) Primitive modular operation with 2 operands Start a primitive modular operation with 2 operands on the accelerator and return immediately. When the operation finishes on the accelerator, call sx_async_finish_single()

Parameters

ParamDescription
cnxConnection structure obtained through SX_PK_OPEN() at startup
cmdcmd Command definition. Should be a primitive modular operation with 2 operands. For example: SX_PK_CMD_MOD_ADD, SX_PK_CMD_SUB, SX_PK_CMD_ODD_MOD_MULT, SX_PK_CMD_ODD_MOD_DIV
moduloModulus operand.
aFirst Operand of modular operation
bSecond Operand of modular operation

See

sx_mod_primitive_cmd() for a synchronous version

Returns

Acquired acceleration request for this operation

sx_mod_primitive_cmd

C

int sx_mod_primitive_cmd(
      struct sx_pk_cnx *cnx,
      const struct sx_pk_cmd_def *cmd,
      const sx_op *modulo,
      const sx_op *a,
      const sx_op *b,
      sx_op *result)

Description

Primitive modular operation with 2 operands

  • result = a + b mod modulo for ::SX_PK_CMD_MOD_ADD
  • result = a - b mod modulo for ::SX_PK_CMD_MOD_SUB
  • result = ab mod modulo for ::SX_PK_CMD_ODD_MOD_MULT with odd modulus
  • result = a / b mod modulo for ::SX_PK_CMD_ODD_MOD_DIV with odd modulus Perform a modular addition or subtraction or odd modular multiplication or odd modular division.

Parameters

ParamDescription
cnxConnection structure obtained through SX_PK_OPEN() at startup
cmdcmd Command definition. Should be a primitive modular operation with 2 operands
moduloModulus operand.
aFirst Operand of modular operation
bSecond Operand of modular operation
resultResult Operand

See

sx_async_mod_cmd_go() and sx_async_finish_single for an asynchronous version

Returns

SX_OK SX_ERR_NOT_INVERTIBLE SX_ERR_INVALID_PARAM SX_ERR_UNKNOWN_ERROR SX_ERR_BUSY SX_ERR_NOT_IMPLEMENTED SX_ERR_OPERAND_TOO_LARGE SX_ERR_PLATFORM_ERROR SX_ERR_EXPIRED

sx_async_mod_inv_go

C

struct sx_pk_dreq sx_async_mod_inv_go(
      struct sx_pk_cnx *cnx,
      const sx_op *modulo,
      const sx_op *b)

Description

Asynchronous (non-blocking) mod inversion. Start a modular inversion on the accelerator and return immediately. When the operation finishes on the accelerator, call sx_async_finish_single()

Parameters

ParamDescription
cnxConnection structure obtained through SX_PK_OPEN() at startup
moduloModulus operand
bOperand to inverse

See

sx_async_finish_single(), sx_mod_inv()

Returns

Acquired acceleration request for this operation

sx_mod_inv

C

int sx_mod_inv(
      struct sx_pk_cnx *cnx,
      const sx_op *modulo,
      const sx_op *b,
      sx_op *result)

Description

Compute modular inversion result = 1/b mod modulo

Parameters

ParamDescription
cnxConnection structure obtained through SX_PK_OPEN() at startup
moduloModulus operand
bOperand to inverse
resultResult operand of the modular inversion

See

sx_async_mod_inv_go() for an asynchronous version

Returns

SX_OK SX_ERR_NOT_INVERTIBLE SX_ERR_INVALID_PARAM SX_ERR_UNKNOWN_ERROR SX_ERR_BUSY SX_ERR_NOT_IMPLEMENTED SX_ERR_OPERAND_TOO_LARGE SX_ERR_PLATFORM_ERROR SX_ERR_EXPIRED

sx_async_mod_exp_go

C

struct sx_pk_dreq sx_async_mod_exp_go(
      struct sx_pk_cnx *cnx,
      const sx_op *input,
      const sx_op *exp,
      const sx_op *m)

Description

Asynchronous (non-blocking) modular exponentiation. Start a modular exponentiation on the accelerator and return immediately. When the operation finishes on the accelerator, call sx_async_mod_exp_end()

Parameters

ParamDescription
cnxConnection structure obtained through SX_PK_OPEN() at startup
inputBase operand for modular exponentiation
expExponent operand
mModulus operand

See

sx_mod_exp() for a synchronous version

Returns

Acquired acceleration request for this operation

sx_async_mod_exp_end

C

void sx_async_mod_exp_end(
      sx_pk_accel *req,
      sx_op *result)

Description

Finish asynchronous (non-blocking) modular exponentiation. Get the output operand of the modular exponentiation and release the accelerator. The operation on the accelerator must be finished before calling this function.

Parameters

ParamDescription
reqThe pewviously acquired acceleration request for this operation
resultResult operand

See

sx_async_mod_exp_go() and sx_mod_exp()

Returns

None

sx_mod_exp

C

int sx_mod_exp(
        struct sx_pk_cnx *cnx,
        const sx_op *input,
        const sx_op *exp,
        const sx_op *m,
        sx_op *result)

Description

Compute modular exponentiation. result = input ^ exp mod m

Parameters

ParamDescription
cnxConnection structure obtained through SX_PK_OPEN() at startup
inputBase operand
expExponent operand
mModulus operand
resultResult operand

See

sx_async_mod_exp_go(), sx_async_mod_exp_end() for an asynchronous version

Returns

SX_OK SX_ERR_INVALID_PARAM SX_ERR_UNKNOWN_ERROR SX_ERR_BUSY SX_ERR_NOT_IMPLEMENTED SX_ERR_OPERAND_TOO_LARGE SX_ERR_PLATFORM_ERROR SX_ERR_EXPIRED

sx_async_crt_mod_exp_go

C

struct sx_pk_dreq sx_async_crt_mod_exp_go(
      struct sx_pk_cnx *cnx,
      const sx_op *in,
      const sx_op *p,
      const sx_op *q,
      const sx_op *dp,
      const sx_op *dq,
      const sx_op *qinv)

Description

Asynchronous (non-blocking) modular exponentiation with CRT. Start a modular exponentiation with CRT on the accelerator and return immediately. When the operation finishes on the accelerator, call sx_async_crt_mod_exp_end()

Parameters

ParamDescription
cnxConnection structure obtained through SX_PK_OPEN() at startup
inInput
pprime number P
qprime number q
dpd mod (p-1), with d the private key
dqd mod (q-1), with d the private key
qinvq^(-1) mod p

See

sx_async_crt_mod_exp_end()

Returns

Acquired acceleration request for this operation

sx_async_crt_mod_exp_end

C

void sx_async_crt_mod_exp_end(
      sx_pk_accel *req,
      sx_op *result)

Description

Finish asynchronous (non-blocking) modular exponentiation with CRT. Get the output operand of the modular exponentiation with CRT and release the reserved resources. The operation on the accelerator must be finished before calling this function.

Parameters

ParamDescription
reqThe previously acquired acceleration request for this operation
resultResult

See

sx_async_crt_mod_exp_go()

Returns

None

sx_crt_mod_exp

C

int sx_crt_mod_exp(
        struct sx_pk_cnx *cnx,
        const sx_op *in,
        const sx_op *p,
        const sx_op *q,
        const sx_op *dp,
        const sx_op *dq,
        const sx_op *qinv,
        sx_op *result)

Description

Compute modular exponentiation with CRT Compute (result = in ^ db mod m) with those steps:

vp = in dp mod p vq = in dq mod q u = (vp -vq)qinv mod p result = vq + uq

Parameters

ParamDescription
cnxConnection structure obtained through SX_PK_OPEN() at startup
inInput
pprime number P
qprime number q
dpd mod (p-1), with d the private key
dqd mod (q-1), with d the private key
qinvq^(-1) mod p
resultResult of modular exponentiation with CRT

See

sx_async_crt_mod_exp_go(), sx_async_crt_mod_exp_end() for an asynchronous version

Returns

SX_OK SX_ERR_INVALID_PARAM SX_ERR_UNKNOWN_ERROR SX_ERR_BUSY SX_ERR_NOT_IMPLEMENTED SX_ERR_OPERAND_TOO_LARGE SX_ERR_PLATFORM_ERROR SX_ERR_EXPIRED

sx_async_rsa_keygen_go

C

struct sx_pk_dreq sx_async_rsa_keygen_go(struct sx_pk_cnx *cnx,
   const sx_op *p, const sx_op *q, const sx_op *public_expo)

Description

Asynchronous (non-blocking) RSA private key generation. Start an RSA private key generation on the accelerator and return immediately. When the operation finishes on the accelerator, call sx_async_rsa_keygen_end()

Parameters

ParamDescription
cnxConnection structure obtained through SX_PK_OPEN() at startup
pprime number P
qprime number q
public_expoPublic exponent operand

Returns

Acquired acceleration request for this operation

sx_async_rsa_keygen_end

C

void sx_async_rsa_keygen_end(sx_pk_accel *req, sx_op *n, sx_op *lambda_n, sx_op *privkey)

Description

Finish asynchronous (non-blocking) RSA private key generation. Get the output operands of the RSA private key generation and release the reserved resources. The operation on the accelerator must be finished before calling this function

Parameters

ParamDescription
reqThe previously acquired acceleration request for this operation
nMultiple of 2 primes p and q
lambda_nLeast common multiple of p-1 and q-1
privkeyPrivate Key

Returns

None

sx_rsa_keygen

C

int sx_rsa_keygen(struct sx_pk_cnx *cnx,
     const sx_op *p, const sx_op *q, const sx_op *public_expo,
     sx_op *n, sx_op *lambda_n, sx_op *privkey)

Description

Compute RSA private key and lambda_n from primes p and q. The private key is generated with the following steps:

  1. n = pq
  2. lambda_n = lcm(p-1,q-1)
  3. d = e^-1 % lambda_n Where d is the private key (privkey).

Parameters

ParamDescription
cnxConnection structure obtained through SX_PK_OPEN() at startup
pPrime value P
qPrime value q
public_expoPublic exponent operand
nResulting operand
lambda_nResulting lambda_n operand
privkeyResulting Private Key operand

See

sx_async_rsa_keygen_go(), sx_async_rsa_keygen_end() for an asynchronous version

Returns

SX_OK SX_ERR_INVALID_PARAM SX_ERR_UNKNOWN_ERROR SX_ERR_BUSY SX_ERR_NOT_IMPLEMENTED SX_ERR_OPERAND_TOO_LARGE SX_ERR_PLATFORM_ERROR SX_ERR_EXPIRED

sx_async_rsa_crt_keyparams_go

C

struct sx_pk_dreq sx_async_rsa_crt_keyparams_go(
   struct sx_pk_cnx *cnx, const sx_op *p, const sx_op *q,
   const sx_op *privkey)

Description

Asynchronous (non-blocking) RSA CRT private key parameters. Start a RSA CRT private key generation on the accelerator and return immediately. When the operation finishes on the accelerator, call sx_async_rsa_crt_keyparams_end()

Parameters

ParamDescription
cnxConnection structure obtained through SX_PK_OPEN() at startup
pPrime operand p
qPrime operand q
privkeyResulting Private Key operand

See

sx_async_rsakeyparams_end() and sx_async_rsa_crt_keyparams()

Returns

Acquired acceleration request for this operation

sx_async_rsa_crt_keyparams_end

C

void sx_async_rsa_crt_keyparams_end(sx_pk_accel *req,
                             sx_op *dp, sx_op *dq, sx_op *qinv)

Description

Finish asynchronous (non-blocking) RSA CRT private key parameters. Get the output operands of the RSA CRT private key parameters and release the reserved resources. The operation on the accelerator must be finished before calling this function.

Parameters

ParamDescription
reqThe previously acquired acceleration request for this operation
dpd mod (p-1)
dqd moe (q-1)
qinvq ^ -1 mod p

See

sx_async_rsa_crt_keyparams_go() and sx_rsa_crt_keyparams()

Returns

None

sx_async_rsa_crt_keyparams_end

C

int sx_rsa_crt_keyparams(struct sx_pk_cnx *cnx,
     const sx_op *p, const sx_op *q, const sx_op *privkey,
     sx_op *dp, sx_op *dq, sx_op *qinv)

Description

Compute RSA CRT private key parameters. Computes the following parameters: dp = d mod (p - 1) dq = d mod (q - 1) qinv = q ^ -1 mod p where d is the private key and the pair p and q are the secret primes used to create the RSA private key.

Parameters

ParamDescription
cnxConnection structure obtained through SX_PK_OPEN() at startup
pPrime value p
qPrime value q
privkeyPrivate key operand
dpd mod (p-1)
dqd moe (q-1)
qinvq ^ -1 mod p

See

sx_async_rsa_crt_keyparams_go(), sx_async_rsa_crt_keyparams_end() for an asynchronous version

Returns

SX_OK SX_ERR_NOT_INVERTIBLE SX_ERR_OUT_OF_RANGE SX_ERR_INVALID_PARAM SX_ERR_UNKNOWN_ERROR SX_ERR_BUSY SX_ERR_NOT_IMPLEMENTED SX_ERR_OPERAND_TOO_LARGE SX_ERR_PLATFORM_ERROR SX_ERR_EXPIRED