Digital signing and verification
QNX SDP8.0QNX OS System Security GuideAPIConfiguration
The qcrypto library API includes functions that provide cryptographic signing and verification primitives. Several forms are provided to give you the flexibility of using one that is best suited to your needs.
Cryptographic signatures are useful for protecting assets by allowing an asset's integrity to be verified before it is used. Systems often use these signatures for code signing in secure boot environments.
See the library reference for detailed descriptions of the signing and verification functions.
General signature:
Signature signing:
Signature verification:
Signature size:
DSA and ECDSA signature size
For DSA and ECDSA, the signature size returned can be larger than the result signature because of the random number generation chosen as part of the algorithm (which is also why these signatures differ each time). The qcrypto_signature_sigsize() function returns the largest buffer required to make the signature fit if the client code wants to allocate space. The client should rely on the final size as returned by the qcrypto_signature_sign*() functions.RSA signatures PSS padding mode
When using RSA PSS padding, the salt size should be equal to or longer than the digest length used for signing. When verifying, the salt size must be provided for verification to succeed.Signature examples
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <qcrypto/qcrypto.h>
#include <qcrypto/qcrypto_error.h>
#include <qcrypto/qcrypto_keys.h>
int main(void)
{
int ret;
int sig_result = 1;
int ver_result = 1;
qcrypto_ctx_t *qctx = NULL;
qcrypto_ctx_t *qkeyctx = NULL;
qcrypto_key_t *qprivkey = NULL;
qcrypto_key_t *qpubkey = NULL;
const uint8_t sigbuf[] = {
0x90, 0xb6, 0x05, 0xa5, 0x40, 0x06, 0xc3, 0xeb, 0x74, 0x9c, 0x4a, 0x03,
0xb3, 0xcb, 0x9e, 0xd5, 0xcd, 0x8a, 0xb9, 0x5f, 0xe1, 0x8f, 0x3f, 0xd4,
0x9e, 0x0a, 0xc0, 0xb9, 0x54, 0x4b, 0x87, 0xf5, 0x0c, 0xb1, 0xdf, 0x83,
0x1c, 0xb0, 0x95, 0xff, 0xf5, 0xba, 0x1e, 0x57, 0x46, 0x0a, 0x49, 0x70,
0x92, 0x87, 0xcc, 0xa4, 0x26, 0x70, 0xee, 0x4f, 0xe3, 0xba, 0x05, 0xd8,
0x73, 0xa6, 0x2b, 0x43, 0xe9, 0x2a, 0x69, 0x9a, 0x1c, 0xf7, 0x14, 0x35,
0x86, 0xd1, 0x81, 0xe9, 0x88, 0x31, 0xbb, 0x71, 0x59, 0xc3, 0xfe, 0x23,
0x46, 0x44, 0x0f, 0xe0, 0xf8, 0x3f, 0x52, 0xc0, 0x96, 0xa4, 0xfa, 0x4e,
0xd8, 0x22, 0x74, 0x66, 0x1d, 0x11, 0x57, 0xb6, 0xb1, 0x77, 0x47, 0x5f,
0x41, 0xbc, 0x37, 0x31, 0x8e, 0x45, 0xef, 0x62, 0x1b, 0x7b, 0xd3, 0xf3,
0x1a, 0xcc, 0xd7, 0xf3, 0x15, 0xbd, 0xff, 0xa8, 0x37, 0xc6, 0x96, 0xa2,
0xb4, 0xb8, 0x47, 0x98, 0x91, 0xa7, 0xcd, 0x87, 0x63, 0x88, 0x37, 0xc6,
0x47, 0xf8, 0x9f, 0x35, 0xe0, 0x72, 0xbb, 0x7f, 0xb3, 0xfc, 0xed, 0x7a,
0x5e, 0xb4, 0xe5, 0x96, 0x37, 0xcb, 0x44, 0x57, 0x76, 0x60, 0x8e, 0x1a,
0x1a, 0x97, 0x7d, 0xd6, 0x86, 0x16, 0xf8, 0x11, 0x5c, 0x61, 0x6b, 0xbc,
0x39, 0xc4, 0x8d, 0x05, 0xb4, 0xf9, 0x83, 0xe7, 0x96, 0x49, 0x30, 0xb6,
0x75, 0x92, 0xca, 0x85, 0xf2, 0xf1, 0x2b, 0x52, 0xde, 0xfd, 0xd4, 0xa4,
0xda, 0xf9, 0xb8, 0x12, 0xe3, 0xd4, 0x69, 0x6e, 0x20, 0xe3, 0xfe, 0x04,
0x4a, 0xa7, 0x31, 0xa6, 0x5a, 0xa2, 0x3d, 0xae, 0x28, 0x1e, 0x25, 0xc9,
0x85, 0xd7, 0xf4, 0x35, 0x30, 0x48, 0x80, 0x55, 0xd5, 0x75, 0x8d, 0xef,
0xf9, 0xf5, 0x11, 0x4a, 0xa1, 0x4e, 0xd3, 0x9a, 0x93, 0x94, 0x02, 0x76,
0x2f, 0xf2, 0x08, 0xee
};
const uint8_t privkeybuf[] = {
0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x50,
0x52, 0x49, 0x56, 0x41, 0x54, 0x45, 0x20, 0x4b, 0x45, 0x59, 0x2d, 0x2d,
0x2d, 0x2d, 0x2d, 0x0a, 0x4d, 0x49, 0x49, 0x45, 0x76, 0x41, 0x49, 0x42,
0x41, 0x44, 0x41, 0x4e, 0x42, 0x67, 0x6b, 0x71, 0x68, 0x6b, 0x69, 0x47,
0x39, 0x77, 0x30, 0x42, 0x41, 0x51, 0x45, 0x46, 0x41, 0x41, 0x53, 0x43,
0x42, 0x4b, 0x59, 0x77, 0x67, 0x67, 0x53, 0x69, 0x41, 0x67, 0x45, 0x41,
0x41, 0x6f, 0x49, 0x42, 0x41, 0x51, 0x43, 0x37, 0x32, 0x2b, 0x65, 0x30,
0x5a, 0x61, 0x73, 0x58, 0x56, 0x74, 0x59, 0x48, 0x0a, 0x46, 0x36, 0x41,
0x43, 0x34, 0x58, 0x79, 0x45, 0x54, 0x2f, 0x30, 0x33, 0x67, 0x44, 0x34,
0x38, 0x4f, 0x43, 0x6c, 0x66, 0x72, 0x31, 0x32, 0x33, 0x59, 0x73, 0x64,
0x4f, 0x6f, 0x72, 0x67, 0x68, 0x6a, 0x4b, 0x56, 0x48, 0x76, 0x55, 0x43,
0x34, 0x45, 0x30, 0x69, 0x71, 0x56, 0x7a, 0x32, 0x75, 0x44, 0x31, 0x2f,
0x37, 0x53, 0x77, 0x6a, 0x38, 0x79, 0x70, 0x2b, 0x6a, 0x49, 0x57, 0x53,
0x36, 0x0a, 0x6d, 0x39, 0x58, 0x38, 0x62, 0x62, 0x37, 0x74, 0x75, 0x6c,
0x41, 0x75, 0x33, 0x55, 0x59, 0x65, 0x66, 0x2b, 0x4d, 0x4d, 0x70, 0x4b,
0x2b, 0x46, 0x32, 0x7a, 0x4e, 0x46, 0x51, 0x71, 0x4a, 0x37, 0x6c, 0x6c,
0x35, 0x65, 0x4c, 0x50, 0x6e, 0x6d, 0x62, 0x71, 0x4c, 0x50, 0x36, 0x65,
0x2b, 0x63, 0x78, 0x55, 0x68, 0x30, 0x68, 0x73, 0x79, 0x67, 0x45, 0x6f,
0x6f, 0x50, 0x35, 0x64, 0x6f, 0x55, 0x0a, 0x4d, 0x33, 0x35, 0x36, 0x2f,
0x69, 0x77, 0x69, 0x64, 0x41, 0x49, 0x76, 0x4f, 0x36, 0x37, 0x6c, 0x63,
0x33, 0x76, 0x61, 0x74, 0x44, 0x6a, 0x4b, 0x33, 0x37, 0x48, 0x69, 0x6e,
0x2f, 0x7a, 0x74, 0x34, 0x4a, 0x44, 0x2b, 0x66, 0x62, 0x2b, 0x68, 0x43,
0x36, 0x58, 0x61, 0x42, 0x4e, 0x33, 0x6c, 0x36, 0x66, 0x4f, 0x32, 0x6c,
0x36, 0x67, 0x42, 0x42, 0x76, 0x54, 0x75, 0x72, 0x70, 0x2f, 0x49, 0x0a,
0x6f, 0x38, 0x61, 0x38, 0x49, 0x58, 0x64, 0x56, 0x63, 0x42, 0x2b, 0x4a,
0x67, 0x51, 0x78, 0x5a, 0x6f, 0x62, 0x78, 0x56, 0x35, 0x45, 0x52, 0x72,
0x31, 0x38, 0x4a, 0x50, 0x59, 0x67, 0x2b, 0x35, 0x48, 0x32, 0x39, 0x31,
0x64, 0x53, 0x77, 0x33, 0x73, 0x4f, 0x37, 0x43, 0x30, 0x64, 0x4d, 0x73,
0x31, 0x42, 0x65, 0x70, 0x78, 0x37, 0x44, 0x31, 0x43, 0x39, 0x4c, 0x79,
0x2b, 0x6f, 0x65, 0x4d, 0x0a, 0x44, 0x71, 0x4d, 0x4d, 0x71, 0x4d, 0x71,
0x45, 0x73, 0x64, 0x41, 0x41, 0x39, 0x74, 0x78, 0x6d, 0x68, 0x49, 0x38,
0x55, 0x48, 0x4c, 0x42, 0x61, 0x4e, 0x6e, 0x36, 0x7a, 0x4f, 0x77, 0x54,
0x2b, 0x50, 0x55, 0x6a, 0x30, 0x71, 0x74, 0x67, 0x70, 0x71, 0x5a, 0x59,
0x50, 0x58, 0x70, 0x4e, 0x68, 0x6d, 0x59, 0x69, 0x32, 0x45, 0x57, 0x31,
0x47, 0x64, 0x58, 0x43, 0x56, 0x58, 0x32, 0x46, 0x41, 0x0a, 0x77, 0x5a,
0x45, 0x74, 0x6c, 0x41, 0x7a, 0x72, 0x41, 0x67, 0x45, 0x44, 0x41, 0x6f,
0x49, 0x42, 0x41, 0x48, 0x30, 0x39, 0x52, 0x53, 0x4c, 0x75, 0x63, 0x67,
0x2b, 0x50, 0x4f, 0x56, 0x6f, 0x50, 0x77, 0x41, 0x48, 0x72, 0x71, 0x46,
0x67, 0x31, 0x55, 0x33, 0x70, 0x56, 0x66, 0x74, 0x4c, 0x51, 0x47, 0x35,
0x55, 0x66, 0x6b, 0x38, 0x2b, 0x58, 0x4c, 0x34, 0x6e, 0x42, 0x30, 0x42,
0x5a, 0x64, 0x0a, 0x77, 0x34, 0x55, 0x6f, 0x31, 0x64, 0x41, 0x4d, 0x32,
0x78, 0x77, 0x36, 0x4b, 0x52, 0x36, 0x30, 0x36, 0x71, 0x65, 0x48, 0x57,
0x31, 0x4d, 0x78, 0x76, 0x38, 0x49, 0x57, 0x51, 0x79, 0x63, 0x53, 0x6a,
0x71, 0x68, 0x4a, 0x4b, 0x66, 0x50, 0x52, 0x69, 0x73, 0x6e, 0x6f, 0x32,
0x57, 0x6d, 0x71, 0x6c, 0x31, 0x33, 0x44, 0x48, 0x36, 0x36, 0x53, 0x49,
0x69, 0x34, 0x73, 0x62, 0x46, 0x4a, 0x6b, 0x0a, 0x50, 0x75, 0x6c, 0x7a,
0x55, 0x55, 0x52, 0x4a, 0x77, 0x64, 0x2f, 0x78, 0x53, 0x6d, 0x69, 0x44,
0x68, 0x61, 0x4d, 0x45, 0x69, 0x47, 0x71, 0x33, 0x42, 0x72, 0x56, 0x44,
0x35, 0x72, 0x67, 0x69, 0x56, 0x46, 0x48, 0x2b, 0x79, 0x42, 0x62, 0x34,
0x41, 0x58, 0x54, 0x53, 0x64, 0x4a, 0x6a, 0x33, 0x70, 0x2b, 0x63, 0x69,
0x30, 0x49, 0x63, 0x2f, 0x79, 0x2b, 0x78, 0x70, 0x67, 0x6c, 0x6a, 0x39,
0x0a, 0x76, 0x57, 0x4f, 0x4d, 0x39, 0x6c, 0x59, 0x2f, 0x38, 0x62, 0x45,
0x59, 0x41, 0x43, 0x61, 0x52, 0x44, 0x63, 0x5a, 0x50, 0x33, 0x39, 0x72,
0x6c, 0x57, 0x54, 0x75, 0x57, 0x4e, 0x6c, 0x42, 0x64, 0x68, 0x41, 0x2f,
0x45, 0x61, 0x34, 0x57, 0x74, 0x67, 0x6f, 0x53, 0x65, 0x62, 0x5a, 0x76,
0x35, 0x57, 0x6c, 0x77, 0x76, 0x35, 0x62, 0x69, 0x4d, 0x38, 0x50, 0x79,
0x75, 0x59, 0x48, 0x77, 0x2b, 0x0a, 0x6e, 0x48, 0x5a, 0x49, 0x50, 0x55,
0x79, 0x51, 0x44, 0x6a, 0x59, 0x56, 0x31, 0x6f, 0x32, 0x6a, 0x49, 0x41,
0x49, 0x5a, 0x50, 0x6c, 0x4c, 0x2f, 0x6e, 0x58, 0x50, 0x6f, 0x47, 0x74,
0x4b, 0x54, 0x35, 0x39, 0x5a, 0x4a, 0x43, 0x55, 0x68, 0x79, 0x68, 0x32,
0x49, 0x58, 0x6a, 0x52, 0x54, 0x75, 0x43, 0x4f, 0x37, 0x59, 0x37, 0x61,
0x34, 0x46, 0x31, 0x45, 0x58, 0x73, 0x55, 0x78, 0x77, 0x48, 0x0a, 0x42,
0x64, 0x4b, 0x36, 0x4a, 0x66, 0x47, 0x6b, 0x62, 0x69, 0x52, 0x35, 0x72,
0x38, 0x35, 0x58, 0x7a, 0x67, 0x5a, 0x71, 0x53, 0x78, 0x6f, 0x4e, 0x6b,
0x51, 0x6c, 0x49, 0x4e, 0x41, 0x33, 0x55, 0x43, 0x6e, 0x6e, 0x75, 0x79,
0x6a, 0x73, 0x43, 0x67, 0x59, 0x45, 0x41, 0x39, 0x5a, 0x48, 0x4e, 0x73,
0x4c, 0x73, 0x35, 0x70, 0x6c, 0x52, 0x78, 0x75, 0x45, 0x51, 0x55, 0x36,
0x43, 0x38, 0x6f, 0x0a, 0x70, 0x4e, 0x37, 0x7a, 0x42, 0x53, 0x53, 0x44,
0x6f, 0x67, 0x6e, 0x4e, 0x2b, 0x74, 0x42, 0x72, 0x5a, 0x4a, 0x79, 0x4d,
0x57, 0x2f, 0x55, 0x45, 0x67, 0x30, 0x61, 0x34, 0x79, 0x62, 0x71, 0x30,
0x70, 0x6e, 0x67, 0x66, 0x51, 0x72, 0x57, 0x72, 0x32, 0x4a, 0x44, 0x34,
0x76, 0x4c, 0x32, 0x6b, 0x75, 0x6e, 0x47, 0x30, 0x54, 0x57, 0x63, 0x4a,
0x43, 0x48, 0x54, 0x69, 0x4b, 0x43, 0x52, 0x57, 0x0a, 0x52, 0x64, 0x67,
0x6c, 0x50, 0x41, 0x65, 0x62, 0x50, 0x58, 0x41, 0x57, 0x78, 0x51, 0x68,
0x6f, 0x66, 0x4e, 0x64, 0x59, 0x33, 0x46, 0x79, 0x72, 0x55, 0x59, 0x74,
0x32, 0x38, 0x74, 0x41, 0x55, 0x46, 0x2f, 0x45, 0x31, 0x56, 0x43, 0x76,
0x4f, 0x4c, 0x73, 0x7a, 0x31, 0x55, 0x54, 0x4e, 0x52, 0x58, 0x37, 0x71,
0x4d, 0x70, 0x4b, 0x31, 0x37, 0x74, 0x6b, 0x42, 0x61, 0x34, 0x74, 0x38,
0x56, 0x0a, 0x59, 0x4c, 0x6d, 0x6c, 0x2f, 0x39, 0x4b, 0x61, 0x38, 0x4d,
0x66, 0x52, 0x47, 0x48, 0x50, 0x50, 0x6c, 0x50, 0x2f, 0x45, 0x44, 0x37,
0x38, 0x43, 0x67, 0x59, 0x45, 0x41, 0x77, 0x39, 0x61, 0x57, 0x52, 0x43,
0x33, 0x77, 0x70, 0x38, 0x73, 0x36, 0x41, 0x77, 0x78, 0x4c, 0x39, 0x58,
0x7a, 0x6e, 0x75, 0x69, 0x34, 0x73, 0x30, 0x78, 0x51, 0x72, 0x54, 0x51,
0x74, 0x2f, 0x55, 0x33, 0x2b, 0x73, 0x0a, 0x48, 0x41, 0x66, 0x75, 0x65,
0x68, 0x66, 0x6e, 0x57, 0x48, 0x76, 0x61, 0x6e, 0x6a, 0x54, 0x33, 0x44,
0x6c, 0x4e, 0x39, 0x4b, 0x53, 0x46, 0x59, 0x67, 0x45, 0x4e, 0x6a, 0x77,
0x6b, 0x45, 0x63, 0x79, 0x6c, 0x4a, 0x55, 0x67, 0x74, 0x33, 0x50, 0x30,
0x50, 0x7a, 0x4f, 0x36, 0x54, 0x51, 0x4a, 0x49, 0x63, 0x35, 0x38, 0x6c,
0x33, 0x44, 0x78, 0x4b, 0x56, 0x55, 0x48, 0x6d, 0x6b, 0x66, 0x49, 0x0a,
0x53, 0x6e, 0x50, 0x69, 0x59, 0x44, 0x74, 0x61, 0x73, 0x32, 0x4a, 0x63,
0x6c, 0x66, 0x63, 0x4c, 0x61, 0x62, 0x79, 0x68, 0x39, 0x36, 0x6c, 0x66,
0x6b, 0x58, 0x31, 0x6a, 0x4e, 0x79, 0x44, 0x68, 0x59, 0x48, 0x34, 0x47,
0x2b, 0x70, 0x47, 0x33, 0x4f, 0x70, 0x68, 0x4e, 0x4b, 0x4d, 0x30, 0x41,
0x63, 0x76, 0x4c, 0x4c, 0x2f, 0x4d, 0x7a, 0x47, 0x4a, 0x6a, 0x2b, 0x68,
0x2b, 0x72, 0x67, 0x7a, 0x0a, 0x37, 0x48, 0x62, 0x70, 0x7a, 0x64, 0x55,
0x43, 0x67, 0x59, 0x45, 0x41, 0x6f, 0x37, 0x61, 0x4a, 0x49, 0x48, 0x7a,
0x52, 0x47, 0x59, 0x32, 0x68, 0x4a, 0x59, 0x4b, 0x34, 0x6d, 0x73, 0x6f,
0x62, 0x47, 0x4a, 0x53, 0x69, 0x41, 0x32, 0x32, 0x74, 0x46, 0x72, 0x45,
0x7a, 0x2f, 0x49, 0x72, 0x79, 0x51, 0x78, 0x4d, 0x49, 0x50, 0x55, 0x34,
0x44, 0x41, 0x69, 0x38, 0x6c, 0x32, 0x39, 0x48, 0x4e, 0x0a, 0x78, 0x46,
0x41, 0x55, 0x31, 0x79, 0x50, 0x48, 0x35, 0x62, 0x58, 0x37, 0x4b, 0x48,
0x35, 0x74, 0x30, 0x61, 0x45, 0x69, 0x33, 0x6b, 0x53, 0x77, 0x73, 0x45,
0x33, 0x73, 0x47, 0x73, 0x4c, 0x6b, 0x4c, 0x70, 0x41, 0x59, 0x30, 0x71,
0x2b, 0x38, 0x30, 0x36, 0x41, 0x50, 0x4c, 0x67, 0x57, 0x61, 0x2f, 0x65,
0x54, 0x6c, 0x36, 0x44, 0x33, 0x48, 0x69, 0x37, 0x4a, 0x50, 0x54, 0x49,
0x71, 0x34, 0x0a, 0x44, 0x2f, 0x59, 0x6a, 0x6a, 0x58, 0x4b, 0x4a, 0x64,
0x49, 0x69, 0x6a, 0x69, 0x33, 0x65, 0x4c, 0x6c, 0x53, 0x63, 0x49, 0x62,
0x63, 0x6a, 0x39, 0x4a, 0x43, 0x72, 0x6e, 0x51, 0x65, 0x6f, 0x4f, 0x51,
0x48, 0x76, 0x44, 0x2f, 0x2b, 0x47, 0x38, 0x6f, 0x49, 0x55, 0x32, 0x45,
0x45, 0x30, 0x31, 0x44, 0x66, 0x2f, 0x59, 0x43, 0x6e, 0x38, 0x43, 0x67,
0x59, 0x45, 0x41, 0x67, 0x6f, 0x38, 0x4f, 0x0a, 0x32, 0x42, 0x36, 0x67,
0x62, 0x39, 0x7a, 0x52, 0x56, 0x31, 0x32, 0x48, 0x2b, 0x50, 0x33, 0x76,
0x30, 0x58, 0x51, 0x64, 0x34, 0x67, 0x31, 0x79, 0x4d, 0x31, 0x7a, 0x2f,
0x6a, 0x50, 0x2f, 0x49, 0x45, 0x71, 0x2f, 0x30, 0x55, 0x57, 0x56, 0x45,
0x35, 0x61, 0x66, 0x6e, 0x46, 0x43, 0x4e, 0x50, 0x58, 0x75, 0x4a, 0x54,
0x63, 0x4d, 0x44, 0x6c, 0x71, 0x74, 0x65, 0x58, 0x31, 0x74, 0x59, 0x54,
0x0a, 0x4d, 0x59, 0x77, 0x34, 0x56, 0x7a, 0x36, 0x4b, 0x69, 0x31, 0x4d,
0x30, 0x6d, 0x33, 0x67, 0x47, 0x46, 0x6f, 0x6d, 0x6f, 0x5a, 0x50, 0x58,
0x32, 0x47, 0x34, 0x34, 0x46, 0x45, 0x59, 0x55, 0x77, 0x4d, 0x61, 0x4b,
0x57, 0x36, 0x74, 0x49, 0x38, 0x64, 0x35, 0x62, 0x6f, 0x59, 0x2f, 0x6f,
0x48, 0x6d, 0x39, 0x4d, 0x57, 0x70, 0x52, 0x75, 0x56, 0x43, 0x36, 0x6a,
0x73, 0x7a, 0x32, 0x74, 0x41, 0x0a, 0x36, 0x76, 0x36, 0x76, 0x55, 0x62,
0x5a, 0x36, 0x4a, 0x78, 0x41, 0x7a, 0x63, 0x49, 0x69, 0x71, 0x39, 0x30,
0x79, 0x48, 0x2f, 0x64, 0x33, 0x5a, 0x62, 0x74, 0x55, 0x57, 0x70, 0x79,
0x56, 0x33, 0x38, 0x76, 0x6e, 0x78, 0x4d, 0x2b, 0x4d, 0x43, 0x67, 0x59,
0x42, 0x35, 0x50, 0x4f, 0x69, 0x74, 0x52, 0x70, 0x6f, 0x47, 0x36, 0x4f,
0x6a, 0x38, 0x69, 0x63, 0x53, 0x37, 0x48, 0x41, 0x75, 0x63, 0x0a, 0x41,
0x6c, 0x6b, 0x43, 0x68, 0x78, 0x2f, 0x61, 0x49, 0x63, 0x6d, 0x65, 0x32,
0x51, 0x6f, 0x39, 0x6e, 0x51, 0x2f, 0x34, 0x2b, 0x44, 0x6c, 0x56, 0x2b,
0x73, 0x38, 0x39, 0x56, 0x79, 0x64, 0x65, 0x33, 0x65, 0x6a, 0x30, 0x78,
0x64, 0x44, 0x49, 0x7a, 0x46, 0x4e, 0x6c, 0x38, 0x45, 0x33, 0x73, 0x2b,
0x54, 0x75, 0x44, 0x37, 0x65, 0x30, 0x34, 0x52, 0x4d, 0x68, 0x39, 0x66,
0x6f, 0x6d, 0x79, 0x0a, 0x36, 0x72, 0x2b, 0x4b, 0x58, 0x55, 0x4b, 0x75,
0x6a, 0x6f, 0x74, 0x59, 0x77, 0x63, 0x6f, 0x64, 0x34, 0x31, 0x6d, 0x2f,
0x77, 0x43, 0x34, 0x64, 0x72, 0x4d, 0x68, 0x69, 0x50, 0x51, 0x61, 0x62,
0x35, 0x64, 0x79, 0x45, 0x78, 0x65, 0x48, 0x54, 0x77, 0x5a, 0x51, 0x31,
0x34, 0x43, 0x4c, 0x30, 0x75, 0x67, 0x36, 0x31, 0x35, 0x35, 0x79, 0x48,
0x4d, 0x64, 0x59, 0x4f, 0x62, 0x4b, 0x67, 0x47, 0x0a, 0x78, 0x66, 0x4c,
0x72, 0x6c, 0x50, 0x6c, 0x4d, 0x56, 0x48, 0x71, 0x4b, 0x41, 0x66, 0x47,
0x52, 0x37, 0x54, 0x6f, 0x4b, 0x69, 0x51, 0x3d, 0x3d, 0x0a, 0x2d, 0x2d,
0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44, 0x20, 0x50, 0x52, 0x49, 0x56, 0x41,
0x54, 0x45, 0x20, 0x4b, 0x45, 0x59, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a
};
const size_t privkeysize = sizeof(privkeybuf);
const uint8_t *privkey_bin = privkeybuf;
const uint8_t pubkeybuf[] = {
0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x50,
0x55, 0x42, 0x4c, 0x49, 0x43, 0x20, 0x4b, 0x45, 0x59, 0x2d, 0x2d, 0x2d,
0x2d, 0x2d, 0x0a, 0x4d, 0x49, 0x49, 0x42, 0x49, 0x44, 0x41, 0x4e, 0x42,
0x67, 0x6b, 0x71, 0x68, 0x6b, 0x69, 0x47, 0x39, 0x77, 0x30, 0x42, 0x41,
0x51, 0x45, 0x46, 0x41, 0x41, 0x4f, 0x43, 0x41, 0x51, 0x30, 0x41, 0x4d,
0x49, 0x49, 0x42, 0x43, 0x41, 0x4b, 0x43, 0x41, 0x51, 0x45, 0x41, 0x75,
0x39, 0x76, 0x6e, 0x74, 0x47, 0x57, 0x72, 0x46, 0x31, 0x62, 0x57, 0x42,
0x78, 0x65, 0x67, 0x41, 0x75, 0x46, 0x38, 0x0a, 0x68, 0x45, 0x2f, 0x39,
0x4e, 0x34, 0x41, 0x2b, 0x50, 0x44, 0x67, 0x70, 0x58, 0x36, 0x39, 0x64,
0x74, 0x32, 0x4c, 0x48, 0x54, 0x71, 0x4b, 0x34, 0x49, 0x59, 0x79, 0x6c,
0x52, 0x37, 0x31, 0x41, 0x75, 0x42, 0x4e, 0x49, 0x71, 0x6c, 0x63, 0x39,
0x72, 0x67, 0x39, 0x66, 0x2b, 0x30, 0x73, 0x49, 0x2f, 0x4d, 0x71, 0x66,
0x6f, 0x79, 0x46, 0x6b, 0x75, 0x70, 0x76, 0x56, 0x2f, 0x47, 0x32, 0x2b,
0x0a, 0x37, 0x62, 0x70, 0x51, 0x4c, 0x74, 0x31, 0x47, 0x48, 0x6e, 0x2f,
0x6a, 0x44, 0x4b, 0x53, 0x76, 0x68, 0x64, 0x73, 0x7a, 0x52, 0x55, 0x4b,
0x69, 0x65, 0x35, 0x5a, 0x65, 0x58, 0x69, 0x7a, 0x35, 0x35, 0x6d, 0x36,
0x69, 0x7a, 0x2b, 0x6e, 0x76, 0x6e, 0x4d, 0x56, 0x49, 0x64, 0x49, 0x62,
0x4d, 0x6f, 0x42, 0x4b, 0x4b, 0x44, 0x2b, 0x58, 0x61, 0x46, 0x44, 0x4e,
0x2b, 0x65, 0x76, 0x34, 0x73, 0x0a, 0x49, 0x6e, 0x51, 0x43, 0x4c, 0x7a,
0x75, 0x75, 0x35, 0x58, 0x4e, 0x37, 0x32, 0x72, 0x51, 0x34, 0x79, 0x74,
0x2b, 0x78, 0x34, 0x70, 0x2f, 0x38, 0x37, 0x65, 0x43, 0x51, 0x2f, 0x6e,
0x32, 0x2f, 0x6f, 0x51, 0x75, 0x6c, 0x32, 0x67, 0x54, 0x64, 0x35, 0x65,
0x6e, 0x7a, 0x74, 0x70, 0x65, 0x6f, 0x41, 0x51, 0x62, 0x30, 0x37, 0x71,
0x36, 0x66, 0x79, 0x4b, 0x50, 0x47, 0x76, 0x43, 0x46, 0x33, 0x0a, 0x56,
0x58, 0x41, 0x66, 0x69, 0x59, 0x45, 0x4d, 0x57, 0x61, 0x47, 0x38, 0x56,
0x65, 0x52, 0x45, 0x61, 0x39, 0x66, 0x43, 0x54, 0x32, 0x49, 0x50, 0x75,
0x52, 0x39, 0x76, 0x64, 0x58, 0x55, 0x73, 0x4e, 0x37, 0x44, 0x75, 0x77,
0x74, 0x48, 0x54, 0x4c, 0x4e, 0x51, 0x58, 0x71, 0x63, 0x65, 0x77, 0x39,
0x51, 0x76, 0x53, 0x38, 0x76, 0x71, 0x48, 0x6a, 0x41, 0x36, 0x6a, 0x44,
0x4b, 0x6a, 0x4b, 0x0a, 0x68, 0x4c, 0x48, 0x51, 0x41, 0x50, 0x62, 0x63,
0x5a, 0x6f, 0x53, 0x50, 0x46, 0x42, 0x79, 0x77, 0x57, 0x6a, 0x5a, 0x2b,
0x73, 0x7a, 0x73, 0x45, 0x2f, 0x6a, 0x31, 0x49, 0x39, 0x4b, 0x72, 0x59,
0x4b, 0x61, 0x6d, 0x57, 0x44, 0x31, 0x36, 0x54, 0x59, 0x5a, 0x6d, 0x49,
0x74, 0x68, 0x46, 0x74, 0x52, 0x6e, 0x56, 0x77, 0x6c, 0x56, 0x39, 0x68,
0x51, 0x4d, 0x47, 0x52, 0x4c, 0x5a, 0x51, 0x4d, 0x0a, 0x36, 0x77, 0x49,
0x42, 0x41, 0x77, 0x3d, 0x3d, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45,
0x4e, 0x44, 0x20, 0x50, 0x55, 0x42, 0x4c, 0x49, 0x43, 0x20, 0x4b, 0x45,
0x59, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a
};
const size_t pubkeysize = sizeof(pubkeybuf);
const uint8_t *pubkey_bin = pubkeybuf;
const uint8_t inputbuf[] = {
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,0x38, 0x39, 0x41, 0x42,
0x43, 0x44, 0x45, 0x46, 0x31, 0x32, 0x33, 0x34
};
const size_t inputsize = sizeof(inputbuf);
const uint8_t *input_bin = inputbuf;
const size_t sigsize = sizeof(sigbuf);
uint8_t sig_cmpbuf[sigsize];
uint8_t *sig_cmp = sig_cmpbuf;
size_t sigsize_cmp = sigsize;
/* Initialize the Qcrypto Library */
ret = qcrypto_init(QCRYPTO_INIT_LAZY, NULL);
if (ret != QCRYPTO_R_EOK) {
fprintf(stderr, "qcryto_init() failed (%d:%s)\n", ret, qcrypto_strerror(ret));
goto done;
}
/* Request rsa keygen */
ret = qcrypto_keygen_request("rsa", NULL, 0, &qkeyctx);
if (ret != QCRYPTO_R_EOK) {
fprintf(stderr, "qcrypto_keygen_request() failed (%d:%s)\n", ret, qcrypto_strerror(ret));
goto done;
}
/* Initialize signature arguments */
qcrypto_signature_args_t sargs = {
.mode = QCRYPTO_SIGNATURE_SIGN,
.rsa.pad_mode = QCRYPTO_RSA_PAD_PKCS1v15,
.rsa.saltsize = 0,
};
/* Request rsa-with-sha256 to sign a signature */
ret = qcrypto_signature_request("rsa-with-sha256", NULL, 0, &qctx);
if (ret != QCRYPTO_R_EOK) {
fprintf(stderr, "qcrypto_signature_request() failed (%d:%s)\n", ret, qcrypto_strerror(ret));
goto done;
}
/* Load privkey */
ret = qcrypto_privkey_from_mem(qkeyctx, &qprivkey, privkey_bin, privkeysize, QCRYPTO_KEY_FMT_PEM);
if (ret != QCRYPTO_R_EOK) {
fprintf(stderr, "qcrypto_privkey_from_mem() failed (%d:%s)\n", ret, qcrypto_strerror(ret));
goto done;
}
/* Initialize signature signing */
ret = qcrypto_signature_init(qctx, qprivkey, &sargs);
if (ret != QCRYPTO_R_EOK) {
fprintf(stderr, "qcrypto_signature_init() failed (%d:%s)\n", ret, qcrypto_strerror(ret));
goto done;
}
/* Compare sig size */
sigsize_cmp = qcrypto_signature_sigsize(qctx);
if (sigsize_cmp != sigsize) {
fprintf(stderr, "Computed sigsize failed to match with expected sigsize\n");
goto done;
}
/* Sign the Signature */
qcrypto_memclear(sig_cmp, sigsize_cmp);
ret = qcrypto_signature_sign_oneshot(qctx, input_bin, inputsize, sig_cmp, &sigsize_cmp);
if (ret != QCRYPTO_R_EOK) {
fprintf(stderr, "qcrypto_signature_sign_oneshot() failed (%d:%s)\n", ret, qcrypto_strerror(ret));
goto done;
}
/* Compare the sig results */
sig_result = memcmp(sig_cmp, sigbuf, sigsize);
if (sig_result == 0) {
printf("Computed sig matches with expected sig\n");
} else {
fprintf(stderr, "Computed sig failed to match with expected sig\n");
goto done;
}
/* Switch to verification mode */
sargs.mode = QCRYPTO_SIGNATURE_VERIFY;
/* Load pubkey */
ret = qcrypto_pubkey_from_mem(qkeyctx, &qpubkey, pubkey_bin, pubkeysize, QCRYPTO_KEY_FMT_PEM);
if (ret != QCRYPTO_R_EOK) {
fprintf(stderr, "qcrypto_pubkey_from_mem() failed (%d:%s)\n", ret, qcrypto_strerror(ret));
goto done;
}
/* Initialize signature verification */
ret = qcrypto_signature_init(qctx, qpubkey, &sargs);
if (ret != QCRYPTO_R_EOK) {
fprintf(stderr, "qcrypto_signature_init() failed (%d:%s)\n", ret, qcrypto_strerror(ret));
goto done;
}
/* Verify the Signature */
ret = qcrypto_signature_verify_oneshot(qctx, input_bin, inputsize, sig_cmp, sigsize, &ver_result);
if (ret != QCRYPTO_R_EOK) {
fprintf(stderr, "qcrypto_signature_verify_oneshot() failed (%d:%s)\n", ret, qcrypto_strerror(ret));
goto done;
}
/* Check the verification result */
if (ver_result == 1) {
printf("Signature verified\n");
} else {
fprintf(stderr, "Signature verification failed\n");
goto done;
}
goto done;
done:
/* Release all context handles */
qcrypto_release_ctx(qctx);
qcrypto_release_ctx(qkeyctx);
/* Release all key handles */
qcrypto_release_key(qprivkey);
qcrypto_release_key(qpubkey);
/* Uninitialize the Qcrypto Library */
qcrypto_uninit();
return ret;
}
Page updated: