Skip to content
This repository
Browse code

Merge branch 'dev'

  • Loading branch information...
commit 41fa3db0752fd8d23db688c5959f1e90d2a8b3f9 2 parents 9d02f4e + ecdb312
Christina Garman ChristinaLGarman authored
22 charm/core/math/pairing/relic/relic_interface.c
@@ -24,7 +24,7 @@
24 24 * @brief charm interface over RELIC's pairing-based crypto module
25 25 *
26 26 * @author ayo.akinyele@charm-crypto.com
27   -* @status not complete: g2_map and modular division operations not working correctly (as of 8/6/12)
  27 +* @status not complete: modular division operations not working correctly (as of 8/6/12)
28 28 *
29 29 ************************************************************************/
30 30
@@ -279,6 +279,8 @@ status_t element_sub(element_t c, element_t a, element_t b)
279 279 if(type == ZR) {
280 280 bn_sub(c->bn, a->bn, b->bn);
281 281 bn_mod(c->bn, c->bn, c->order);
  282 + if(bn_sign(c->bn) == BN_NEG) bn_add(c->bn, c->bn, a->order);
  283 +
282 284 }
283 285 else if(type == G1) {
284 286 g1_sub(c->g1, a->g1, b->g1);
@@ -508,6 +510,7 @@ status_t element_neg(element_t c, element_t a)
508 510
509 511 if(type == ZR) {
510 512 bn_neg(c->bn, a->bn);
  513 + bn_add(c->bn, c->bn, a->order);
511 514 }
512 515 else if(type == G1) {
513 516 g1_neg(c->g1, a->g1);
@@ -701,8 +704,14 @@ status_t element_from_hash(element_t e, unsigned char *data, int len)
701 704 memset(digest, 0, digest_len);
702 705 SHA_FUNC(digest, data, len);
703 706
  707 +#ifdef DEBUG
  708 + printf("%s: digest: ", __FUNCTION__);
  709 + print_as_hex(digest, digest_len);
  710 +#endif
  711 +
704 712 switch(type) {
705 713 case ZR: bn_read_bin(e->bn, digest, digest_len);
  714 + if(bn_cmp(e->bn, e->order) == CMP_GT) bn_mod(e->bn, e->bn, e->order);
706 715 break;
707 716 case G1: g1_map(e->g1, digest, digest_len);
708 717 break;
@@ -1057,13 +1066,20 @@ status_t hash_buffer_to_bytes(uint8_t *input, int input_len, uint8_t *output, in
1057 1066 {
1058 1067 LEAVE_IF(input == NULL || output == NULL, "uninitialized argument.");
1059 1068 // adds an extra null byte by default - will use this last byte for the label
1060   - int digest_len = SHA_LEN;
  1069 + int digest_len = SHA_LEN, i;
1061 1070
1062 1071 if(digest_len <= output_len) {
1063 1072 // hash buf using md_map_sh256 and store data_len bytes in data
1064 1073 uint8_t digest[digest_len + 1];
  1074 + uint8_t input2[input_len + 2];
  1075 + memset(input2, 0, input_len + 1);
  1076 + // set prefix
  1077 + input2[0] = 0xFF & label;
  1078 + // copy remaining bytes
  1079 + for(i = 1; i <= input_len; i++)
  1080 + input2[i] = input[i];
1065 1081 memset(digest, 0, digest_len);
1066   - SHA_FUNC(digest, input, input_len);
  1082 + SHA_FUNC(digest, input2, input_len+1);
1067 1083 memcpy(output, digest, digest_len);
1068 1084 #ifdef DEBUG
1069 1085 printf("%s: digest: ", __FUNCTION__);
9 charm/toolbox/ecgroup.py
... ... @@ -1,6 +1,9 @@
1   -#from charm.core.math.elliptic_curve import *
2   -from charm.core.math.elliptic_curve import elliptic_curve,ZR,G,init,random,order,getGenerator,bitsize,serialize,deserialize,hashEC,encode,decode,getXY
3   -#from charm.core.math.elliptic_curve import InitBenchmark,StartBenchmark,EndBenchmark,GetBenchmak,GetGeneralBenchmarks,ClearBenchmark
  1 +try:
  2 + from charm.core.math.elliptic_curve import elliptic_curve,ZR,G,init,random,order,getGenerator,bitsize,serialize,deserialize,hashEC,encode,decode,getXY
  3 + #from charm.core.math.elliptic_curve import InitBenchmark,StartBenchmark,EndBenchmark,GetBenchmark,GetGeneralBenchmarks,ClearBenchmark
  4 +except Exception as err:
  5 + print(err)
  6 + exit(-1)
4 7
5 8 class ECGroup():
6 9 def __init__(self, builtin_cv):
22 charm/toolbox/hash_module.py
... ... @@ -1,9 +1,13 @@
1   -import charm.core.crypto.cryptobase
2   -from charm.core.math.pairing import pairing,ZR
3   -from charm.core.math.integer import integer,int2Bytes
4   -from charm.toolbox.conversion import Conversion
5   -from charm.toolbox.bitstring import Bytes
6   -import hashlib, base64
  1 +try:
  2 + import charm.core.crypto.cryptobase
  3 + from charm.core.math.pairing import pairing,ZR
  4 + from charm.core.math.integer import integer,int2Bytes
  5 + from charm.toolbox.conversion import Conversion
  6 + from charm.toolbox.bitstring import Bytes
  7 + import hashlib, base64
  8 +except Exception as err:
  9 + print(err)
  10 + exit(-1)
7 11
8 12 class Hash():
9 13 def __init__(self, htype='sha1', pairingElement=None, integerElement=None):
@@ -23,9 +27,9 @@ def hashToZn(self, value):
23 27 # do something related to that
24 28 if type(value) == integer:
25 29 str_value = int2Bytes(value)
26   -# print("str_value =>", str_value)
27   -# val = self.group.hash(str_value, ZR)
28   -# print("hash =>", val)
  30 + #print("str_value =>", str_value)
  31 + #val = self.group.hash(str_value, ZR)
  32 + #print("hash =>", val)
29 33 return integer(int(self.group.hash(str_value, ZR)))
30 34 return None
31 35
9 charm/toolbox/integergroup.py
... ... @@ -1,5 +1,10 @@
1   -from charm.core.math.integer import integer,randomBits,random,randomPrime,isPrime,encode,decode,hashInt,bitsize,legendre,gcd,lcm,serialize,deserialize,int2Bytes,toInt
2   -
  1 +try:
  2 + from charm.core.math.integer import integer,randomBits,random,randomPrime,isPrime,encode,decode,hashInt,bitsize,legendre,gcd,lcm,serialize,deserialize,int2Bytes,toInt
  3 + #from charm.core.math.integer import InitBenchmark,StartBenchmark,EndBenchmark,GetBenchmark,GetGeneralBenchmarks,ClearBenchmark
  4 +except Exception as err:
  5 + print(err)
  6 + exit(-1)
  7 +
3 8 class IntegerGroup:
4 9 def __init__(self, start=0):
5 10 pass
8 charm/toolbox/pairinggroup.py
... ... @@ -1,5 +1,9 @@
1   -from charm.toolbox.pairingcurves import params as param_info
2   -from charm.core.math.pairing import pairing,ZR,G1,G2,GT,init,pair,hashPair,H,random,serialize,deserialize,ismember,order
  1 +try:
  2 + from charm.toolbox.pairingcurves import params as param_info
  3 + from charm.core.math.pairing import pairing,ZR,G1,G2,GT,init,pair,hashPair,H,random,serialize,deserialize,ismember,order
  4 +except Exception as err:
  5 + print(err)
  6 + exit(-1)
3 7
4 8 class PairingGroup():
5 9 def __init__(self, param_id, param_file=False, secparam=512):
0  charm/toolbox/policytree.py 100755 → 100644
File mode changed
0  charm/toolbox/zknode.py 100755 → 100644
File mode changed

0 comments on commit 41fa3db

Please sign in to comment.
Something went wrong with that request. Please try again.