libtc  20160415
Threshold Cryptography functions library
algorithms_rsa_verify.c
Go to the documentation of this file.
1 /*
2  * algorithms_rsa_verify.c
3  *
4  * Created on: 28-07-2015
5  * Author: franchoco
6  */
7 
8 #include <gmp.h>
9 #include <stdlib.h>
10 
11 #include "tc.h"
12 #include "tc_internal.h"
13 
14 int tc_rsa_verify(bytes_t * signature, bytes_t * doc, key_metainfo_t * info, tc_hash_type_t hashtype) {
15 
16  bytes_t * doc_pkcs1 = tc_prepare_document(doc, hashtype, info);
17 
18  mpz_t c, x, e, n, new_x;
19  mpz_inits(c, x, e, n, new_x, NULL);
20  TC_BYTES_TO_MPZ(x, doc_pkcs1);
21  TC_BYTES_TO_MPZ(c, signature);
22  TC_BYTES_TO_MPZ(e, info->public_key->e);
23  TC_BYTES_TO_MPZ(n, info->public_key->n);
24 
25  mpz_powm(new_x, c, e, n);
26  int cmp = mpz_cmp(x, new_x);
27 
28  tc_clear_bytes(doc_pkcs1);
29  mpz_clears(c, x, e, n, new_x, NULL);
30 
31  return cmp == 0;
32 }
bytes_t * tc_prepare_document(const bytes_t *doc, tc_hash_type_t hash_type, const key_metainfo_t *metainfo)
public_key_t * public_key
Definition: tc_internal.h:14
void tc_clear_bytes(bytes_t *bytes)
Definition: structs_init.c:39
Structure that&#39;s stores a pointer that points to data_len bytes.
Definition: tc.h:14
bytes_t * n
Definition: tc_internal.h:9
Structure that represents the data about a key share, including its public key.
Definition: tc_internal.h:13
#define TC_BYTES_TO_MPZ(z, bytes)
Definition: tc_internal.h:42
enum tc_hash_type tc_hash_type_t
Definition: tc.h:51
int tc_rsa_verify(bytes_t *signature, bytes_t *doc, key_metainfo_t *info, tc_hash_type_t hashtype)
bytes_t * e
Definition: tc_internal.h:10