Home | History | Annotate | Download | only in nanoapp_sign

Lines Matching refs:rsa

26 #include <nanohub/rsa.h>
124 static bool validateSignature(uint8_t *sigPack, struct RsaData *rsa, bool verbose, uint32_t *refHash, bool preset)
131 rsa->num[i] = le32toh(le32SigPack[i]);
134 printHashRev(stderr, "RSA cyphertext", rsa->num, RSA_LIMBS);
136 memcpy(rsa->modulus, sigPack + RSA_BYTES, RSA_BYTES);
138 //do rsa op
139 rsaResult = rsaPubOp(&rsa->state, rsa->num, rsa->modulus);
143 printHashRev(stderr, "RSA plaintext", rsaResult, RSA_LIMBS);
191 static int handleConvertKey(uint8_t **pbuf, uint32_t bufUsed, FILE *out, struct RsaData *rsa)
207 fprintf(stderr, "Invalid text RSA input data\n");
217 rsa->num[RSA_LIMBS - i - 1] = be32toh(be32Buf[i]);
220 ret = fwrite(rsa->num, 1, RSA_BYTES, out) == RSA_BYTES ? 0 : 2;
226 static int handleVerify(uint8_t **pbuf, uint32_t bufUsed, struct RsaData *rsa, bool verbose, bool bareData)
232 memcpy(masterPubKey, rsa->modulus, RSA_BYTES);
266 if (!validateSignature(sigPack, rsa, verbose, (uint32_t*)sha2finish(&shaState), false)) {
270 if (memcmp(masterPubKey, rsa->modulus, RSA_BYTES) == 0) {
296 if (!validateSignature(sigPack, rsa, verbose, hash, false)) {
316 static int handleSign(uint8_t **pbuf, uint32_t bufUsed, FILE *out, struct RsaData *rsa, bool verbose, bool bareData)
369 memcpy(rsa->num, hash, SHA2_HASH_SIZE);
373 rsa->num[i++] = rand32_no_zero_bytes() << 8; //low byte here must be zero as per padding spec
375 rsa->num[i] = rand32_no_zero_bytes();
376 rsa->num[i] = (rand32_no_zero_bytes() >> 16) | 0x00020000; //as per padding spec
380 printHashRev(stderr, "RSA plaintext", rsa->num, RSA_LIMBS);
382 //do the RSA thing
384 rsaResult = rsaPrivOp(&rsa->state, rsa->num, rsa->exponent, rsa->modulus);
389 printHashRev(stderr, "RSA cyphertext", rsaResult, RSA_LIMBS);
395 ret = (fwrite(rsa->modulus, 1, RSA_BYTES, out) == RSA_BYTES) ? 0 : 2;
414 " -e : RSA binary private key\n"
415 " -m : RSA binary public key\n"
440 struct RsaData rsa;
494 memset(&rsa, 0, sizeof(rsa));
503 if (!readFile(rsa.exponent, sizeof(rsa.exponent), keyPvtFile))
507 printHashRev(stderr, "RSA exponent", rsa.exponent, RSA_LIMBS);
512 if (!readFile(rsa.modulus, sizeof(rsa.modulus), keyPubFile))
515 printHashRev(stderr, "RSA modulus", rsa.modulus, RSA_LIMBS);
542 ret = handleSign(&buf, bufUsed, out, &rsa, verbose, bareData);
544 ret = handleVerify(&buf, bufUsed, &rsa, verbose, bareData);
546 ret = handleConvertKey(&buf, bufUsed, out, &rsa);