c-libp2p/include/libp2p/crypto/rsa.h

56 lines
1.3 KiB
C
Raw Normal View History

2016-11-03 16:15:18 +00:00
//
// rsa.h
// c-libp2p
//
// Created by John Jones on 11/3/16.
// Copyright © 2016 JMJAtlanta. All rights reserved.
//
#ifndef rsa_h
#define rsa_h
struct RsaPublicKey {
unsigned long long modulus;
unsigned long long exponent;
};
struct CRTValue {
unsigned long long exponent;
unsigned long long coefficient;
unsigned long long r;
};
struct PrecomputedValues {
unsigned long long dp;
unsigned long long dq;
unsigned long long q_inv;
struct CRTValue** crt_values;
};
struct RsaPrivateKey {
struct RsaPublicKey public_key;
unsigned long long private_exponent;
unsigned long long prime1;
unsigned long long prime2;
struct PrecomputedValues precomputed_values;
};
/**
* generate a new private key
* @param private_key the new private key
* @param num_bits_for_keypair the size of the key (1024 minimum)
* @returns true(1) on success
*/
int crypto_rsa_generate_keypair(struct RsaPrivateKey* private_key, unsigned long num_bits_for_keypair);
2016-11-07 20:11:58 +00:00
/**
* convert a struct RsaPublicKey into a stream of bytes compatible with x509 PKI
* @param public_key the public key struct
* @param bytes the results
* @param bytes_size the length of the results
*/
int crypto_rsa_public_key_bytes(struct RsaPublicKey* public_key, char** bytes, unsigned long long* bytes_size);
2016-11-03 16:15:18 +00:00
#endif /* rsa_h */