예제 #1
0
BOOL 
PRE1_reencrypt(CurveParams &params, ProxyCiphertext_PRE1 &origCiphertext, 
	       DelegationKey_PRE1 &delegationKey, 
	       ProxyCiphertext_PRE1 &newCiphertext)
{
#ifdef BENCHMARKING
  gettimeofday(&gTstart, &gTz);
#endif

  SAFESTATIC ZZn2 res1;

  // Compute the pairing res1 = e(kP, delegation)
  if (ecap(origCiphertext.c1a, delegationKey, params.q, params.cube, res1) == FALSE) {
    // Pairing failed.  Oops.
    PRINT_DEBUG_STRING("Re-encryption pairing failed."); 
    return false;
  }

  // Set the result ciphertext to (res1, c2)
  newCiphertext.set(CIPH_REENCRYPTED, res1, origCiphertext.c2);
  
#ifdef BENCHMARKING
  gettimeofday(&gTend, &gTz);
  gBenchmark.CollectTiming(REENCTIMING, CalculateUsecs(gTstart, gTend));
#endif

  return true;
}
예제 #2
0
BOOL PRE1_level2_encrypt(CurveParams &params, Big &plaintext, ProxyPK_PRE1 &publicKey, ProxyCiphertext_PRE1 &ciphertext)
{
#ifdef BENCHMARKING
  gettimeofday(&gTstart, &gTz);
#endif

  SAFESTATIC Big k;
  SAFESTATIC ECn c1;
  SAFESTATIC ZZn2 temp, c2;
  SAFESTATIC ZZn2 zPlaintext;
  
  // Select a random value k \in Z*q and compute res1 = (k * P)  
  k = rand(params.q);
  c1 = k * params.P;

  // Compute res2 = plaintext * Zpub1^k
  zPlaintext.set(plaintext, 0);
  temp = pow(publicKey.Zpub1, k);
  c2 = zPlaintext * temp;
  
  // Set the ciphertext structure with (c1, c2)
  ciphertext.set(CIPH_SECOND_LEVEL, c1, c2);

#ifdef BENCHMARKING
  gettimeofday(&gTend, &gTz);
  gBenchmark.CollectTiming(LEVELTWOENCTIMING, CalculateUsecs(gTstart, gTend));
#endif

  return true;
}
예제 #3
0
BOOL 
PRE1_level1_encrypt(CurveParams &params, Big &plaintext, ProxyPK_PRE1 &publicKey, ProxyCiphertext_PRE1 &ciphertext)
{
#ifdef BENCHMARKING
  gettimeofday(&gTstart, &gTz);
#endif

  SAFESTATIC Big k;
  SAFESTATIC ZZn2 temp, c1, c2;
  SAFESTATIC ZZn2 zPlaintext;

  // Select a random value k \in Z*q, and compute res1 = Zpub1^k
  k = rand(params.q);
  c1 = pow(publicKey.Zpub1, k);
  
  // Compute res2 = plaintext * Z^k
  temp = pow(params.Z, k);
  //cout << "encrypt: params.Z = " << params.Z << endl;
  //cout << "encrypt: temp = " << temp << endl;
  zPlaintext.set(plaintext, 0);
  //cout << "encrypt: plaintext = " << zPlaintext << endl;
  c2 = zPlaintext * temp;
  //cout << "encrypt: c1 = " << c1 << endl;
  //cout << "encrypt: c2 = " << c2 << endl;

  // Set the ciphertext data structure with (c1, c2)
  ciphertext.set(CIPH_FIRST_LEVEL, c1, c2);

#ifdef BENCHMARKING
  gettimeofday(&gTend, &gTz);
  gBenchmark.CollectTiming(LEVELONEENCTIMING, CalculateUsecs(gTstart, gTend));
#endif

  return true;
}
예제 #4
0
BOOL PRE1_delegate(CurveParams &params, ProxyPK_PRE1 &delegatee, ProxySK_PRE1 &delegator, DelegationKey_PRE1 &reskey)
{
#ifdef BENCHMARKING
  gettimeofday(&gTstart, &gTz);
#endif
 
  // Compute reskey = delegator.a1 * delegatee.Ppub2
  reskey = delegator.a1 * (delegatee.Ppub2);

#ifdef BENCHMARKING
  gettimeofday(&gTend, &gTz);
  gBenchmark.CollectTiming(DELEGATETIMING, CalculateUsecs(gTstart, gTend));
#endif

  return true;
}
예제 #5
0
BOOL PRE1_decrypt(CurveParams &params, ProxyCiphertext_PRE1 &ciphertext, ProxySK_PRE1 &secretKey, Big &plaintext)
{
#ifdef BENCHMARKING
  gettimeofday(&gTstart, &gTz);
#endif

  SAFESTATIC ECn del;
  SAFESTATIC ZZn2 temp;
  SAFESTATIC ZZn2 result;

 // Handle each type of ciphertext
 switch(ciphertext.type) {
 case CIPH_FIRST_LEVEL:
   // temp = c1^inv(a1)
   temp = pow(ciphertext.c1b, inverse(secretKey.a1, params.qsquared));
   //cout << "decrypt: temp = " << temp << endl;
   break;
 case CIPH_REENCRYPTED:
   // temp = c1^inv(a2)
   temp = pow(ciphertext.c1b, inverse(secretKey.a2, params.qsquared));
   break;
 case CIPH_SECOND_LEVEL:
   // temp = e(c1, a1 * P)
   del = secretKey.a1 * params.P;
   if (ecap(ciphertext.c1a, del, params.q, params.cube, temp) == FALSE) {
     PRINT_DEBUG_STRING("Decryption pairing failed.");
     return FALSE;
   }
   break;
 default:
   PRINT_DEBUG_STRING("Decryption failed: invalid ciphertext type.");
   break;
 }
 
 // Compute plaintext = c2 / temp
 result = ciphertext.c2 / temp;
 result.get(plaintext);

#ifdef BENCHMARKING
  gettimeofday(&gTend, &gTz);
  gBenchmark.CollectTiming(LEVELONEDECTIMING, CalculateUsecs(gTstart, gTend));
#endif

  return true;
}
예제 #6
0
BOOL PRE2_delegate(CurveParams &params, ProxyPK_PRE2 &delegatee,
		   ProxySK_PRE2 &delegator, DelegationKey_PRE2 &reskey)
{
#ifdef BENCHMARKING
  gettimeofday(&gTstart, &gTz);
#endif
 
  // Compute reskey = delegator.a1 * delegatee.Ppub2
  Big a1inv = inverse(delegator.a1, params.q);
  reskey = a1inv * (delegatee.Ppub2);

  ECn Q = delegator.a1 * params.P;
 
  ZZn2 res1;
  
#ifdef BENCHMARKING
  gettimeofday(&gTend, &gTz);
  gBenchmark.CollectTiming(DELEGATETIMING, CalculateUsecs(gTstart, gTend));
#endif

  return true;
}