int crypto_aead_encrypt(
	unsigned char *c,unsigned long long *clen,
	const unsigned char *m,unsigned long long mlen,
	const unsigned char *ad,unsigned long long adlen,
	const unsigned char *nsec,
	const unsigned char *npub,
	const unsigned char *k )
{
    ICESTATE S;
    unsigned int frameBit;
    
    /* initialize the state with secret key and nonce */
    initState256a(S, k, npub);

    /* ciphertext length is plaintext len + size of tag and nsec */
    *clen = mlen + ICEPOLETAGLEN; 
    
    /* secret message number is zero length */
    processDataBlock(S, NULL, NULL, 0, 0);
    
    /* process auth-only associated data blocks */
    do {
        unsigned long long blocklen = ICEPOLEDATABLOCKLEN;
        frameBit = (adlen <= blocklen ? 1 : 0); /* is it the last block? */
        if (adlen < blocklen) {
            blocklen = adlen;
        }
        /* apply the permutation to the state */
        P6(S,S);
        /* absorb a data block */
        processDataBlock(S, ad, NULL, blocklen, frameBit);
        ad += blocklen;
        adlen -= blocklen;
    } while (adlen > 0);

    /* process plaintext blocks to get the ciphertext */
    do {
        unsigned long long blocklen = ICEPOLEDATABLOCKLEN;
        frameBit = (mlen <=blocklen ? 0 : 1);
        if (mlen < blocklen) {
            blocklen = mlen;
        }
        /* apply the permutation to the state */
        P6(S,S);
        /* absorb a data block and produce a ciphertext block */
        processDataBlock(S, m, &c, blocklen, frameBit);
        m += blocklen;
        mlen -= blocklen;    
    } while (mlen > 0);

    /* store authentication tag at the end of the ciphertext */
    generateTag(S, c);
    return 0;
}
int crypto_aead_decrypt(
	unsigned char *m,unsigned long long *mlen,
	unsigned char *nsec,
	const unsigned char *c,unsigned long long clen,
	const unsigned char *ad,unsigned long long adlen,
	const unsigned char *npub,
	const unsigned char *k
)
{
    ICESTATE S;
    unsigned char Tcomp[ICEPOLETAGLEN]; /* computed authentication tag */
    unsigned int frameBit;
    
    /* ciphertext cannot be shorter than the tag length */
    if (clen < ICEPOLETAGLEN) {
        return -1;
    }
    
    initState256a(S, k, npub);

    /* secret message number is zero-length */
    frameBit = 0;
    processDataBlockRev(S, NULL, NULL, 0, frameBit);
   
    /* process associated data blocks */
    do {
        unsigned long long blocklen = ICEPOLEDATABLOCKLEN;
        frameBit = (adlen <= blocklen ? 1 : 0);
        if (adlen < blocklen) {
            blocklen = adlen;
        }
        /* apply the permutation to the state */
        P6(S,S);
        /* absorb a data block */
        processDataBlock(S, ad, NULL, blocklen, frameBit);
        ad += blocklen;
        adlen -= blocklen;
    } while (adlen > 0);
    
    /* process ciphertext blocks to get auth tag */
    *mlen = 0;
    clen -= ICEPOLETAGLEN; /* need to stop before auth tag*/
    do {
        unsigned long long blocklen = ICEPOLEDATABLOCKLEN;
        frameBit = (clen <= blocklen ? 0 : 1);
        if (clen < blocklen) {
            blocklen = clen;
        }
        /* apply the permutation to the state */
        P6(S,S);
        /* absorb a ciphertext block and produce a plaintext block */
        processDataBlockRev(S, c, &m, blocklen, frameBit);
        c += blocklen;
        *mlen += blocklen;
        clen -= blocklen;    
    } while (clen > 0);

    /* compare computed and received auth tags */
    generateTag(S, Tcomp);
    if (memcmp(Tcomp, c, ICEPOLETAGLEN)) {
        *mlen = 0;
        return -1;
    }
    
    return 0;
}
Exemplo n.º 3
0
int main() {

  Point center(41,29);

  // The numbering of the nodes corresponds to gslib's output order
  Node P5(38,28,0.5740);
  Node P8(45,29,1.2110);
  Node P4(41,26,2.1270);
  Node P3(39,31,8.3400);
  Node P6(38,31,18.6420);
  Node P2(39,30,7.9380);
  Node P7(39,32,2.2840);
  Node P1(40,31,2.5090);
  Node P9(37,20,0.5740);
  Node P10(25,28,1.2110);
  Node P11(39,26,2.1270);
  Node P12(32,31,8.3400);
  Node P13(30,34,18.6420);
  Node P14(33,35,7.9380);
  Node P15(42,32,2.2840);
  Node P16(31,23,2.5090);

  neighborhood voisin;
  voisin.add_node(P1);
  voisin.add_node(P2);
  voisin.add_node(P3);
  voisin.add_node(P4);
  voisin.add_node(P5);
  voisin.add_node(P6);
  voisin.add_node(P7);
  voisin.add_node(P8);
  voisin.add_node(P9);
  voisin.add_node(P10);
  voisin.add_node(P11);
  voisin.add_node(P12);
  voisin.add_node(P13);
  voisin.add_node(P14);
  voisin.add_node(P15);
  voisin.add_node(P16);
  


  

  typedef matrix_lib_traits<TNT_lib<double> >::Vector TNTvector;

  covariance covar;
  
  //______________________________
  // Simple Kriging
  //______________________________

  std::cout << std::endl <<std::endl;
  std::cout << "____________________________________________" 
	    << std::endl
	    << "Simple kriging"
	    << std::endl << std::endl;

  TNTvector SK_weights;
  SK_constraints SK;
  OK_constraints OK;
  double sk_variance;
  

  TNT::stopwatch chrono;
  chrono.start();
  for(int count = 0 ; count < 50000 ; count ++) {
    int change=1;
    if(drand48() <0.5) change = -1;
    (voisin[0].location())[0] += change;
    kriging_weights<GSTL_TNT_lib>(SK_weights,
				  center, voisin,
				  covar, OK );
  }

  chrono.stop();
  std::cout << "time elapsed using Gauss: " << chrono.read() << std::endl;
  
  chrono.reset();
  chrono.start();
  for(int count = 0 ; count < 50000 ; count ++) {
    int change=1;
    if(drand48() <0.5) change = -1;
    voisin[0].property_value() = 0.5*count;
    kriging_weights(SK_weights, 
		    center, voisin,
		    covar, OK );
  }

  chrono.stop();
  std::cout << "time elapsed using LU: " << chrono.read() << std::endl;
  
  
  /*
  //______________________________
  // Ordinary Kriging
  //______________________________

  std::cout << std::endl <<std::endl;
  std::cout << "____________________________________________" 
	    << std::endl
	    << "Ordinary kriging"
	    << std::endl << std::endl;

  TNTvector OK_weights;
  OK_constraints OK;
  double ok_variance;
  status = kriging_weights(OK_weights, ok_variance,
			   center, voisin,
			   covar, OK);
						   
  std::cout << "Here are the weights:" << std::endl
	    << OK_weights << std::endl;

  
  

  //______________________________
  // Kriging with Trend
  //______________________________

  std::cout << std::endl <<std::endl;
  std::cout << "____________________________________________" 
	    << std::endl
	    << "Kriging with Trend"
	    << std::endl << std::endl;
  
  TNTvector KT_weights;
  KT_constraints<functIter> KT(functArray.begin(),functArray.end());
  double kt_variance;
  status = kriging_weights(KT_weights, kt_variance,
			   center, voisin,
			   covar, KT);

						  
  std::cout << "Here are the weights:" << std::endl
	    << KT_weights << std::endl;

  */

  return 0;


}
Exemplo n.º 4
0
int main() {

  Node center_node(41,29,-99);

  // The numbering of the nodes corresponds to gslib's output order
  Node P5(38,28,0.5740);
  Node P8(45,29,1.2110);
  Node P4(41,26,2.1270);
  Node P3(39,31,8.3400);
  Node P6(38,31,18.6420);
  Node P2(39,30,7.9380);
  Node P7(39,32,2.2840);
  Node P1(40,31,2.5090);


  neighborhood voisin;
  voisin.add_node(P1);
  voisin.add_node(P2);
  voisin.add_node(P3);
  voisin.add_node(P4);
  voisin.add_node(P5);
  voisin.add_node(P6);
  voisin.add_node(P7);
  voisin.add_node(P8);

 

  
  typedef TNT_lib<double> TNT;
  typedef matrix_lib_traits<TNT>::Vector TNTvector;
  typedef matrix_lib_traits<TNT>::Symmetric_matrix TNTMatrix;

  covariance covar;


  
  //_____________________________
  // gaussian cdf estimator 
  //_____________________________

  std::cout << std::endl <<std::endl;
  std::cout << "____________________________________________" 
	    << std::endl
	    << "estimating gaussian cdf with SK"
	    << std::endl << std::endl;

  Gaussian_cdf g_ccdf;

  typedef Kriging_combiner<std::vector<double>::const_iterator,
                           neighborhood>   KCombiner;
  KCombiner sk_combiner( new SK_combiner<std::vector<double>::const_iterator,
                                          neighborhood>( 9.0 )   );
  typedef Kriging_constraints<neighborhood, Point, TNT> KConstraints;
  KConstraints constraints( new SKConstraints_impl<neighborhood, Point,TNT> );


  Gaussian_cdf_Kestimator<covariance,
    neighborhood,KConstraints,TNT>  gK_estimator( covar, constraints, sk_combiner ); 
  
  gK_estimator(center_node, voisin, g_ccdf);
  
  std::cout << "gaussian cdf : mean= " << g_ccdf.mean() << "   variance= " 
	    << g_ccdf.variance() << std::endl;


  /*  
  Gaussian_cdf g_ccdf2;
  
  Gaussian_cdf_Kestimator<covariance,
    neighborhood, SK_constraints>  gK_estimator2( covar, SK_constraints(), sk_combiner2 ); 
  gK_estimator2(center, voisin, g_ccdf2);
  
  std::cout << "gaussian cdf : mean= " << g_ccdf2.mean() << "   variance= " 
       << g_ccdf2.variance() << std::endl;
  */
}