Beispiel #1
0
int main()
{
	Prime p;
	RSA s;
	int m = 3200;
	//initPrime(&p);
	//findPrime(&p,10000000);
	//printPrime(&p);
	GenerateRSA(&s,9999937,9999943,17);
	PrintRSA(&s);
	for (m=1;m<s.n;m++)
	{
		m = encryptRSA(&s,m);
		m = decryptRSA(&s,m);
	}

}
Beispiel #2
0
/* \brief receives a session key from the client
 * Protocol: Client generates an AES key which is sent
 * encrypted by RSA. Use the private key to decrypt the
 * AES key and use the AES key for the rest of the session
 */
unsigned char *getSessionKey(int client_sock){
    unsigned char client_message[MAX_MSG_SZ];
    int read_size;
    
    // get encrypted AES key from client
    if ( (read_size = recv(client_sock, client_message, MAX_MSG_SZ, 0)) < 0){
        perror("receive failed");
        exit(1);
    }

    // decrypt AES key using server private key
    RSA * privateKey;
    privateKey = readPrivateKey(server_key);
    if (privateKey == NULL){
        //key file not found
        exit(1); //fatal
    }
    unsigned char *session_key;
    session_key = (unsigned char *) malloc(KEYLEN*sizeof(char));
    int keylen = 
        decryptRSA(
                client_message,
                read_size,
                session_key,
                privateKey
        );

    printf("Session key:\n");
    int i;
    for (i = 0; i < keylen; i++){
        printf("0x%02x ", session_key[i]);
        if (i%8==7) printf("\n");
    }
    memset(client_message, 0, MAX_MSG_SZ); //zero out buffer
    return session_key;
}