This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to use cryptocell so sign data without a hash

In order to implement the standard RSA-PKCS, raw data must be signed with the private key without performing a hash.

All the CRYS functions wants either a HASH as input or want to comute a HASH inthe sign function.

How can I sign (actually encrypt) data with a private key without using a hash

Parents Reply Children
  • Maybe you are looking at the wrong api?

    There are two encypryption api's in CC310 for RSA:  
    RSA: CRYS_RSA_OAEP_Encrypt() and CRYS_RSA_PKCS1v15_Encrypt()

    Which to use depends on the variant you want to do, in general look at examples here:
    examples\crypto\nrf_cc310\rsa\main.c

  • Both Functions mentioned requires the UserPubKey_ptr key as input. I want to sign with the Private key (Basically encrypt with the private key). Will CRYS_RSA_PKCS1v15_Encrypt allow a private key as input?

  • Hi,

    From the last post, it seems clear you want to sign the data, not encrypt it (it was initially unclear). In that case, the function you are looking for is probably CRYS_RSA_PSS_SHA1_Sign(). You can refer to <SDK>\examples\crypto\nrf_cc310\rsa\main.c to see how it is done.

    Update: remove the statement about hashing, since it is optional whether to provide a hash digest as input or just the data and let hashing be handled internally.

  • As stated previously: 

    Main issue: How can I sign (RSA) data of variable length without using a Hash before or after the signature?

    I don't want to compute a hash of the data, before or after. I just want to sign the raw data of variable length. My data is an asn.1 structure that should not be hashed. Is this possible?

  • Hi,

    The API does not allow not hashing. However, you can try using CRYS_RSA_HASH_NO_HASH_mode or CRYS_RSA_After_HASH_NOT_KNOWN_mode. That is just intended for testing, though. See supported modes here (excluding MD5):

    /*! Defines the enum for the HASH operation mode. */
    typedef enum
    {
    	CRYS_RSA_HASH_MD5_mode  = 0,	/*!< For PKCS1 v1.5 only. The input data will be hashed with MD5 */
    	CRYS_RSA_HASH_SHA1_mode = 1,	/*!< The input data will be hashed with SHA1. */
    	CRYS_RSA_HASH_SHA224_mode = 2,  /*!< The input data will be hashed with SHA224. */
    	CRYS_RSA_HASH_SHA256_mode = 3,  /*!< The input data will be hashed with SHA256. */
    	CRYS_RSA_HASH_SHA384_mode = 4,  /*!< The input data will be hashed with SHA384. */
    	CRYS_RSA_HASH_SHA512_mode = 5,	/*!< The input data will be hashed with SHA512. */
    	CRYS_RSA_After_MD5_mode = 6,		/*!< For PKCS1 v1.5 only. The input data is a digest of MD5 and will not be hashed. */
    	CRYS_RSA_After_SHA1_mode = 7,	/*!< The input data is a digest of SHA1 and will not be hashed. */
    	CRYS_RSA_After_SHA224_mode = 8,	/*!< The input data is a digest of SHA224 and will not be hashed. */
    	CRYS_RSA_After_SHA256_mode = 9,	/*!< The input data is a digest of SHA256 and will not be hashed. */
    	CRYS_RSA_After_SHA384_mode = 10,	/*!< The input data is a digest of SHA384 and will not be hashed. */
    	CRYS_RSA_After_SHA512_mode = 11,	/*!< The input data is a digest of SHA512 and will not be hashed. */
    	CRYS_RSA_After_HASH_NOT_KNOWN_mode = 12,    /*!< \internal used only for PKCS#1 Ver 1.5 - possible to perform verify operation without hash mode input, 
    						the hash mode is derived from the signature.*/
    	CRYS_RSA_HASH_NO_HASH_mode = 13,	/*!< Used for PKCS1 v1.5 Encrypt and Decrypt.*/
    	CRYS_RSA_HASH_NumOfModes,		/*!< Maximal number of hash operations modes. */
    	
    	CRYS_RSA_HASH_OpModeLast  = 0x7FFFFFFF, /*! Reserved.*/
    
    }CRYS_RSA_HASH_OpMode_t;   

    By the way, since I have not seen this request before. Which part of PKCS requires raw data?

Related