Asymmetric Signature

Asymmetric Signature Algorithm Definitions

structsig_alg

generic public key signature algorithm

Definition:

struct sig_alg {    int (*sign)(struct crypto_sig *tfm, const void *src, unsigned int slen, void *dst, unsigned int dlen);    int (*verify)(struct crypto_sig *tfm, const void *src, unsigned int slen, const void *digest, unsigned int dlen);    int (*set_pub_key)(struct crypto_sig *tfm, const void *key, unsigned int keylen);    int (*set_priv_key)(struct crypto_sig *tfm, const void *key, unsigned int keylen);    unsigned int (*key_size)(struct crypto_sig *tfm);    unsigned int (*digest_size)(struct crypto_sig *tfm);    unsigned int (*max_size)(struct crypto_sig *tfm);    int (*init)(struct crypto_sig *tfm);    void (*exit)(struct crypto_sig *tfm);    struct crypto_alg base;};

Members

sign

Function performs a sign operation as defined by public keyalgorithm. On success, the signature size is returned.Optional.

verify

Function performs a complete verify operation as defined bypublic key algorithm, returning verification status. Optional.

set_pub_key

Function invokes the algorithm specific set public keyfunction, which knows how to decode and interpretthe BER encoded public key and parameters. Mandatory.

set_priv_key

Function invokes the algorithm specific set private keyfunction, which knows how to decode and interpretthe BER encoded private key and parameters. Optional.

key_size

Function returns key size. Mandatory.

digest_size

Function returns maximum digest size. Optional.

max_size

Function returns maximum signature size. Optional.

init

Initialize the cryptographic transformation object.This function is used to initialize the cryptographictransformation object. This function is called only once atthe instantiation time, right after the transformation contextwas allocated. In case the cryptographic hardware has somespecial requirements which need to be handled by software, thisfunction shall check for the precise requirement of thetransformation and put any software fallbacks in place.

exit

Deinitialize the cryptographic transformation object. This is acounterpart toinit, used to remove various changes set ininit.

base

Common crypto API algorithm data structure

Asymmetric Signature API

The Public Key Signature API is used with the algorithms of typeCRYPTO_ALG_TYPE_SIG (listed as type “sig” in /proc/crypto)

structcrypto_sig*crypto_alloc_sig(constchar*alg_name,u32type,u32mask)

allocate signature tfm handle

Parameters

constchar*alg_name

is the cra_name / name or cra_driver_name / driver name of thesigning algorithm e.g. “ecdsa”

u32type

specifies the type of the algorithm

u32mask

specifies the mask for the algorithm

Description

Allocate a handle for public key signature algorithm. The returnedstructcrypto_sig is the handle that is required for any subsequentAPI invocation for signature operations.

Return

allocated handle in case of success;IS_ERR() is true in caseof an error,PTR_ERR() returns the error code.

voidcrypto_free_sig(structcrypto_sig*tfm)

free signature tfm handle

Parameters

structcrypto_sig*tfm

signature tfm handle allocated withcrypto_alloc_sig()

Description

Iftfm is a NULL or error pointer, this function does nothing.

unsignedintcrypto_sig_keysize(structcrypto_sig*tfm)

Get key size

Parameters

structcrypto_sig*tfm

signature tfm handle allocated withcrypto_alloc_sig()

Description

Function returns the key size in bits.Function assumes that the key is already set in the transformation. If thisfunction is called without a setkey or with a failed setkey, you may end upin a NULL dereference.

unsignedintcrypto_sig_digestsize(structcrypto_sig*tfm)

Get maximum digest size

Parameters

structcrypto_sig*tfm

signature tfm handle allocated withcrypto_alloc_sig()

Description

Function returns the maximum digest size in bytes.Function assumes that the key is already set in the transformation. If thisfunction is called without a setkey or with a failed setkey, you may end upin a NULL dereference.

unsignedintcrypto_sig_maxsize(structcrypto_sig*tfm)

Get maximum signature size

Parameters

structcrypto_sig*tfm

signature tfm handle allocated withcrypto_alloc_sig()

Description

Function returns the maximum signature size in bytes.Function assumes that the key is already set in the transformation. If thisfunction is called without a setkey or with a failed setkey, you may end upin a NULL dereference.

intcrypto_sig_sign(structcrypto_sig*tfm,constvoid*src,unsignedintslen,void*dst,unsignedintdlen)

Invoke signing operation

Parameters

structcrypto_sig*tfm

signature tfm handle allocated withcrypto_alloc_sig()

constvoid*src

source buffer

unsignedintslen

source length

void*dst

destination obuffer

unsignedintdlen

destination length

Description

Function invokes the specific signing operation for a given algorithm

Return

signature size on success; error code in case of error

intcrypto_sig_verify(structcrypto_sig*tfm,constvoid*src,unsignedintslen,constvoid*digest,unsignedintdlen)

Invoke signature verification

Parameters

structcrypto_sig*tfm

signature tfm handle allocated withcrypto_alloc_sig()

constvoid*src

source buffer

unsignedintslen

source length

constvoid*digest

digest

unsignedintdlen

digest length

Description

Function invokes the specific signature verification operationfor a given algorithm.

Return

zero on verification success; error code in case of error.

intcrypto_sig_set_pubkey(structcrypto_sig*tfm,constvoid*key,unsignedintkeylen)

Invoke set public key operation

Parameters

structcrypto_sig*tfm

tfm handle

constvoid*key

BER encoded public key, algo OID, paramlen, BER encodedparameters

unsignedintkeylen

length of the key (not including other data)

Description

Function invokes the algorithm specific set key function, which knowshow to decode and interpret the encoded key and parameters

Return

zero on success; error code in case of error

intcrypto_sig_set_privkey(structcrypto_sig*tfm,constvoid*key,unsignedintkeylen)

Invoke set private key operation

Parameters

structcrypto_sig*tfm

tfm handle

constvoid*key

BER encoded private key, algo OID, paramlen, BER encodedparameters

unsignedintkeylen

length of the key (not including other data)

Description

Function invokes the algorithm specific set key function, which knowshow to decode and interpret the encoded key and parameters

Return

zero on success; error code in case of error