Contents

# Example of Using Prime Number Generation Functions

Check Primality
```int PrimeGen_sample(void){PrimeGen   int error = 0;

int ctxSize;
// define 256-bit Prime Generator
int maxBitSize = 256;
ippsPrimeGetSize(256, &ctxSize);
IppsPrimeState* pPrimeG = (IppsPrimeState*)( new Ipp8u [ctxSize] );
ippsPrimeInit(256, pPrimeG);

// define Pseudo Random Generator (default settings)
ippsPRNGGetSize(&ctxSize);
IppsPRNGState* pRand = (IppsPRNGState*)(new Ipp8u [ctxSize] );
ippsPRNGInit(160, pRand);

do {
Ipp32u result;

// test primality of the value (known in advance)
ippsPrimeTest_BN(P1, 50, &result, pPrimeG, ippsPRNGen, pRand);
error = IPP_IS_PRIME!=result;
if(error) {
cout <<"Primality of the known prime isn't confirmed\n";
break;
}
else cout <<"Primality of the known prime is confirmed\n";

// generate 256-bit prime
BigNumber P(0, 256/8);
while( ippStsNoErr != ippsPrimeGen_BN(P, 256, 50, pPrimeG, ippsPRNGen, pRand) ) ;
// and test it
ippsPrimeTest_BN(P, 50, &result, pPrimeG, ippsPRNGen, pRand);
error = IPP_IS_PRIME!=result;
if(error) {
cout <<"Primality of the generated number isn't confirmed\n";
break;
}
else cout <<"Primality of the generated number  is confirmed\n";
} while(0);

delete [] (Ipp8u*)pRand;
delete [] (Ipp8u*)pPrimeG;

return 0==error;
}
```

#### Product and Performance Information

1

Performance varies by use, configuration and other factors. Learn more at www.Intel.com/PerformanceIndex.