Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'dev'

  • Loading branch information...
commit 41fa3db0752fd8d23db688c5959f1e90d2a8b3f9 2 parents 9d02f4e + ecdb312
@ChristinaLGarman ChristinaLGarman authored
View
22 charm/core/math/pairing/relic/relic_interface.c
@@ -24,7 +24,7 @@
* @brief charm interface over RELIC's pairing-based crypto module
*
* @author ayo.akinyele@charm-crypto.com
-* @status not complete: g2_map and modular division operations not working correctly (as of 8/6/12)
+* @status not complete: modular division operations not working correctly (as of 8/6/12)
*
************************************************************************/
@@ -279,6 +279,8 @@ status_t element_sub(element_t c, element_t a, element_t b)
if(type == ZR) {
bn_sub(c->bn, a->bn, b->bn);
bn_mod(c->bn, c->bn, c->order);
+ if(bn_sign(c->bn) == BN_NEG) bn_add(c->bn, c->bn, a->order);
+
}
else if(type == G1) {
g1_sub(c->g1, a->g1, b->g1);
@@ -508,6 +510,7 @@ status_t element_neg(element_t c, element_t a)
if(type == ZR) {
bn_neg(c->bn, a->bn);
+ bn_add(c->bn, c->bn, a->order);
}
else if(type == G1) {
g1_neg(c->g1, a->g1);
@@ -701,8 +704,14 @@ status_t element_from_hash(element_t e, unsigned char *data, int len)
memset(digest, 0, digest_len);
SHA_FUNC(digest, data, len);
+#ifdef DEBUG
+ printf("%s: digest: ", __FUNCTION__);
+ print_as_hex(digest, digest_len);
+#endif
+
switch(type) {
case ZR: bn_read_bin(e->bn, digest, digest_len);
+ if(bn_cmp(e->bn, e->order) == CMP_GT) bn_mod(e->bn, e->bn, e->order);
break;
case G1: g1_map(e->g1, digest, digest_len);
break;
@@ -1057,13 +1066,20 @@ status_t hash_buffer_to_bytes(uint8_t *input, int input_len, uint8_t *output, in
{
LEAVE_IF(input == NULL || output == NULL, "uninitialized argument.");
// adds an extra null byte by default - will use this last byte for the label
- int digest_len = SHA_LEN;
+ int digest_len = SHA_LEN, i;
if(digest_len <= output_len) {
// hash buf using md_map_sh256 and store data_len bytes in data
uint8_t digest[digest_len + 1];
+ uint8_t input2[input_len + 2];
+ memset(input2, 0, input_len + 1);
+ // set prefix
+ input2[0] = 0xFF & label;
+ // copy remaining bytes
+ for(i = 1; i <= input_len; i++)
+ input2[i] = input[i];
memset(digest, 0, digest_len);
- SHA_FUNC(digest, input, input_len);
+ SHA_FUNC(digest, input2, input_len+1);
memcpy(output, digest, digest_len);
#ifdef DEBUG
printf("%s: digest: ", __FUNCTION__);
View
9 charm/toolbox/ecgroup.py
@@ -1,6 +1,9 @@
-#from charm.core.math.elliptic_curve import *
-from charm.core.math.elliptic_curve import elliptic_curve,ZR,G,init,random,order,getGenerator,bitsize,serialize,deserialize,hashEC,encode,decode,getXY
-#from charm.core.math.elliptic_curve import InitBenchmark,StartBenchmark,EndBenchmark,GetBenchmak,GetGeneralBenchmarks,ClearBenchmark
+try:
+ from charm.core.math.elliptic_curve import elliptic_curve,ZR,G,init,random,order,getGenerator,bitsize,serialize,deserialize,hashEC,encode,decode,getXY
+ #from charm.core.math.elliptic_curve import InitBenchmark,StartBenchmark,EndBenchmark,GetBenchmark,GetGeneralBenchmarks,ClearBenchmark
+except Exception as err:
+ print(err)
+ exit(-1)
class ECGroup():
def __init__(self, builtin_cv):
View
22 charm/toolbox/hash_module.py
@@ -1,9 +1,13 @@
-import charm.core.crypto.cryptobase
-from charm.core.math.pairing import pairing,ZR
-from charm.core.math.integer import integer,int2Bytes
-from charm.toolbox.conversion import Conversion
-from charm.toolbox.bitstring import Bytes
-import hashlib, base64
+try:
+ import charm.core.crypto.cryptobase
+ from charm.core.math.pairing import pairing,ZR
+ from charm.core.math.integer import integer,int2Bytes
+ from charm.toolbox.conversion import Conversion
+ from charm.toolbox.bitstring import Bytes
+ import hashlib, base64
+except Exception as err:
+ print(err)
+ exit(-1)
class Hash():
def __init__(self, htype='sha1', pairingElement=None, integerElement=None):
@@ -23,9 +27,9 @@ def hashToZn(self, value):
# do something related to that
if type(value) == integer:
str_value = int2Bytes(value)
-# print("str_value =>", str_value)
-# val = self.group.hash(str_value, ZR)
-# print("hash =>", val)
+ #print("str_value =>", str_value)
+ #val = self.group.hash(str_value, ZR)
+ #print("hash =>", val)
return integer(int(self.group.hash(str_value, ZR)))
return None
View
9 charm/toolbox/integergroup.py
@@ -1,5 +1,10 @@
-from charm.core.math.integer import integer,randomBits,random,randomPrime,isPrime,encode,decode,hashInt,bitsize,legendre,gcd,lcm,serialize,deserialize,int2Bytes,toInt
-
+try:
+ from charm.core.math.integer import integer,randomBits,random,randomPrime,isPrime,encode,decode,hashInt,bitsize,legendre,gcd,lcm,serialize,deserialize,int2Bytes,toInt
+ #from charm.core.math.integer import InitBenchmark,StartBenchmark,EndBenchmark,GetBenchmark,GetGeneralBenchmarks,ClearBenchmark
+except Exception as err:
+ print(err)
+ exit(-1)
+
class IntegerGroup:
def __init__(self, start=0):
pass
View
8 charm/toolbox/pairinggroup.py
@@ -1,5 +1,9 @@
-from charm.toolbox.pairingcurves import params as param_info
-from charm.core.math.pairing import pairing,ZR,G1,G2,GT,init,pair,hashPair,H,random,serialize,deserialize,ismember,order
+try:
+ from charm.toolbox.pairingcurves import params as param_info
+ from charm.core.math.pairing import pairing,ZR,G1,G2,GT,init,pair,hashPair,H,random,serialize,deserialize,ismember,order
+except Exception as err:
+ print(err)
+ exit(-1)
class PairingGroup():
def __init__(self, param_id, param_file=False, secparam=512):
View
0  charm/toolbox/policytree.py 100755 → 100644
File mode changed
View
0  charm/toolbox/zknode.py 100755 → 100644
File mode changed
Please sign in to comment.
Something went wrong with that request. Please try again.