Mixe for Privacy and Anonymity in the Internet
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
CAASymCipher Class Reference

#include <CAASymCipher.hpp>

Collaboration diagram for CAASymCipher:

Public Member Functions

 CAASymCipher ()
 
 ~CAASymCipher ()
 
SINT32 destroy ()
 
SINT32 decrypt (const UINT8 *from, UINT8 *to)
 Decrypts exactly one block which is stored in from. More...
 
SINT32 decryptOAEP (const UINT8 *from, UINT8 *to, UINT32 *len)
 Decrypts one OAEP encoded block which is stored in from. More...
 
SINT32 encrypt (const UINT8 *from, UINT8 *to)
 Encrypts exactly one block which is stored in from. More...
 
SINT32 encryptOAEP (const UINT8 *from, UINT32 fromlen, UINT8 *to, UINT32 *len)
 Encrypts one block of plain text using OAEP padding. More...
 
SINT32 encryptPKCS1 (const UINT8 *from, UINT32 fromlen, UINT8 *to, UINT32 *len)
 Encrypts one block of plain text using PKCS1 padding. More...
 
SINT32 generateKeyPair (UINT32 size)
 Generates a new random key-pair of size bits. More...
 
SINT32 getPublicKeyAsDOMElement (DOMElement *&elemRoot, XERCES_CPP_NAMESPACE::DOMDocument *docOwner)
 
SINT32 getPublicKeyAsXML (UINT8 *buff, UINT32 *len)
 Stores the public key in buff. More...
 
SINT32 setPublicKey (const CACertificate *pCert)
 Sets the public key which is used for encryption to the contained in the provided certificate. More...
 
SINT32 setPublicKeyAsXML (const UINT8 *buff, UINT32 len)
 Sets the public key to the values stored in key. More...
 
SINT32 setPublicKeyAsDOMNode (DOMNode *node)
 
SINT32 setPublicKey (const UINT8 *modulus, UINT32 moduluslen, const UINT8 *exponent, UINT32 exponentlen)
 

Static Public Member Functions

static SINT32 testSpeed ()
 

Private Member Functions

SINT32 addKeyPart (DOMElement *elemRoot, XERCES_CPP_NAMESPACE::DOMDocument *docOwner, const char *partName, BIGNUM *part)
 
SINT32 getKeyPart (BIGNUM **part, DOMNode *node)
 

Private Attributes

RSA * m_pRSA
 

Detailed Description

Definition at line 47 of file CAASymCipher.hpp.

Constructor & Destructor Documentation

◆ CAASymCipher()

CAASymCipher::CAASymCipher ( )

Definition at line 46 of file CAASymCipher.cpp.

47 {
48  m_pRSA = NULL;
49 }

References m_pRSA.

Referenced by testSpeed().

Here is the caller graph for this function:

◆ ~CAASymCipher()

CAASymCipher::~CAASymCipher ( )

Definition at line 51 of file CAASymCipher.cpp.

52 {
53  destroy();
54 }
SINT32 destroy()

References destroy().

Here is the call graph for this function:

Member Function Documentation

◆ addKeyPart()

SINT32 CAASymCipher::addKeyPart ( DOMElement *  elemRoot,
XERCES_CPP_NAMESPACE::DOMDocument *  docOwner,
const char *  partName,
BIGNUM *  part 
)
private

Definition at line 853 of file CAASymCipher.cpp.

856 {
857  DOMElement *node = createDOMElement(docOwner, partName);
858  elemRoot->appendChild(node);
859  UINT8 tmpBuff[256];
860  UINT32 size = 256;
861  BN_bn2bin(part, tmpBuff);
862  CABase64::encode(tmpBuff, BN_num_bytes(part), tmpBuff, &size);
863  tmpBuff[size] = 0;
864  DOMText *tmpTextNode = createDOMText(docOwner, (const char *const)tmpBuff);
865  node->appendChild(tmpTextNode);
866  return E_SUCCESS;
867 }
DOMText * createDOMText(XERCES_CPP_NAMESPACE::DOMDocument *pOwnerDoc, const char *const text)
Creates a new DOMText with the given value which belongs to the DOMDocument owernDoc.
Definition: CAUtil.cpp:822
DOMElement * createDOMElement(XERCES_CPP_NAMESPACE::DOMDocument *pOwnerDoc, const char *const name)
Creates a new DOMElement with the given name which belongs to the DOMDocument owernDoc.
Definition: CAUtil.cpp:814
unsigned char UINT8
Definition: basetypedefs.h:135
unsigned int UINT32
Definition: basetypedefs.h:131
static SINT32 encode(const UINT8 *in, UINT32 len, UINT8 *out, UINT32 *outlen)
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff...
Definition: CABase64.cpp:102
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2

References createDOMElement(), createDOMText(), E_SUCCESS, and CABase64::encode().

Referenced by getPublicKeyAsDOMElement().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decrypt()

SINT32 CAASymCipher::decrypt ( const UINT8 from,
UINT8 to 
)

Decrypts exactly one block which is stored in from.

The result of the decryption is stored in to.

Parameters
fromone block of cipher text
tothe decrypted plain text
Return values
E_UNKNOWNin case of an error
E_SUCCESSotherwise

Definition at line 88 of file CAASymCipher.cpp.

89 {
90  if (RSA_private_decrypt(RSA_SIZE, from, to, m_pRSA, RSA_NO_PADDING) == -1)
91  return E_UNKNOWN;
92  else
93  return E_SUCCESS;
94 }
#define RSA_SIZE
#define E_UNKNOWN
Definition: errorcodes.hpp:3

References E_SUCCESS, E_UNKNOWN, m_pRSA, and RSA_SIZE.

Referenced by decodeXMLEncryptedKey(), and CALastMixB::loop().

Here is the caller graph for this function:

◆ decryptOAEP()

SINT32 CAASymCipher::decryptOAEP ( const UINT8 from,
UINT8 to,
UINT32 len 
)

Decrypts one OAEP encoded block which is stored in from.

Parameters
fromone OAEP encoded block of cipher text
tothe plain text
lenon return contains the size of the plaintext
Return values
E_UNKNOWNin case of an error
E_SUCCESSotherwise

Definition at line 103 of file CAASymCipher.cpp.

104  {
105  SINT32 ret =RSA_private_decrypt(RSA_SIZE, from, to, m_pRSA, RSA_PKCS1_OAEP_PADDING);
106  if (ret < 0)
107  return E_UNKNOWN;
108  *len = ret;
109  return E_SUCCESS;
110  }
signed int SINT32
Definition: basetypedefs.h:132
UINT16 len
Definition: typedefs.hpp:0

References E_SUCCESS, E_UNKNOWN, len, m_pRSA, and RSA_SIZE.

Referenced by decryptXMLElement(), CALastMixA::loop(), and testSpeed().

Here is the caller graph for this function:

◆ destroy()

SINT32 CAASymCipher::destroy ( )

Definition at line 56 of file CAASymCipher.cpp.

57 {
58  RSA_free(m_pRSA);
59  m_pRSA = NULL;
60  return E_SUCCESS;
61 }

References E_SUCCESS, and m_pRSA.

Referenced by ~CAASymCipher().

Here is the caller graph for this function:

◆ encrypt()

SINT32 CAASymCipher::encrypt ( const UINT8 from,
UINT8 to 
)

Encrypts exactly one block which is stored in from.

The result of the encrpytion is stored in to.

Parameters
fromone block of plain text
tothe encrypted cipher text
Return values
E_UNKNOWNin case of an error
E_SUCCESSotherwise

Definition at line 157 of file CAASymCipher.cpp.

158 {
159  if (RSA_public_encrypt(RSA_SIZE, from, to, m_pRSA, RSA_NO_PADDING) == -1)
160  return E_UNKNOWN;
161  else
162  return E_SUCCESS;
163 }

References E_SUCCESS, E_UNKNOWN, m_pRSA, and RSA_SIZE.

Referenced by __encryptKey(), CALocalProxy::loop(), CAMsg::openEncryptedLog(), and CALocalProxy::processKeyExchange().

Here is the caller graph for this function:

◆ encryptOAEP()

SINT32 CAASymCipher::encryptOAEP ( const UINT8 from,
UINT32  fromlen,
UINT8 to,
UINT32 len 
)

Encrypts one block of plain text using OAEP padding.

Parameters
frompointer to one block of plain text
fromlensize of the plain text
tothe OAEP encoded cipher text
lenon return contains the size of the ciphertext
Return values
E_UNKNOWNin case of an error
E_SUCCESSotherwise

Definition at line 120 of file CAASymCipher.cpp.

122 {
123  SINT32 ret =
124  RSA_public_encrypt(fromlen, from, to, m_pRSA, RSA_PKCS1_OAEP_PADDING);
125  if (ret < 0)
126  return E_UNKNOWN;
127  *len = ret;
128  return E_SUCCESS;
129 }

References E_SUCCESS, E_UNKNOWN, len, and m_pRSA.

Referenced by encryptXMLElement(), CALocalProxy::loop(), and testSpeed().

Here is the caller graph for this function:

◆ encryptPKCS1()

SINT32 CAASymCipher::encryptPKCS1 ( const UINT8 from,
UINT32  fromlen,
UINT8 to,
UINT32 len 
)

Encrypts one block of plain text using PKCS1 padding.

Parameters
frompointer to one block of plain text
fromlensize of the plain text
tothe OAEP encoded cipher text
lenon return contains the size of the ciphertext
Return values
E_UNKNOWNin case of an error
E_SUCCESSotherwise Temporarly will be removed soon.

Definition at line 140 of file CAASymCipher.cpp.

142 {
143  SINT32 ret = RSA_public_encrypt(fromlen, from, to, m_pRSA, RSA_PKCS1_PADDING);
144  if (ret < 0)
145  return E_UNKNOWN;
146  *len = ret;
147  return E_SUCCESS;
148 }

References E_SUCCESS, E_UNKNOWN, len, and m_pRSA.

◆ generateKeyPair()

SINT32 CAASymCipher::generateKeyPair ( UINT32  size)

Generates a new random key-pair of size bits.

Parameters
sizekeysize of the new keypair
Return values
E_UNKNOWNin case of an error
E_SUCCESSotherwise

Definition at line 170 of file CAASymCipher.cpp.

171 {
172  RSA_free(m_pRSA);
173  m_pRSA = NULL;
174 #if OPENSSL_VERSION_NUMBER >= 0x1000204fL
175  m_pRSA=::RSA_new();
176  BIGNUM* e = BN_new();
177  BN_set_word(e, 65537);
178  SINT32 ret=::RSA_generate_key_ex(m_pRSA,size, e, NULL);
179  if (ret != 1)
180  {
181  RSA_free(m_pRSA);
182  m_pRSA = NULL;
183  }
184 #else
185  m_pRSA = ::RSA_generate_key(size, 65537, NULL, NULL);
186 #endif
187  if (m_pRSA == NULL)
188  return E_UNKNOWN;
190  return E_SUCCESS;
191 }
void setRSAFlags(RSA *pRSA)

References E_SUCCESS, E_UNKNOWN, m_pRSA, and setRSAFlags().

Referenced by CALastMix::init(), CAMiddleMix::init(), and testSpeed().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getKeyPart()

SINT32 CAASymCipher::getKeyPart ( BIGNUM **  part,
DOMNode *  node 
)
private

Definition at line 642 of file CAASymCipher.cpp.

643 {
644  if (*part != NULL)
645  BN_free(*part);
646  UINT8 *tmpStr = new UINT8[4096];
647  UINT32 tmpStrLen = 4096;
648  getDOMElementValue(node, tmpStr, &tmpStrLen);
649  UINT8 decBuff[4096];
650  UINT32 decLen = 4096;
651  CABase64::decode(tmpStr, tmpStrLen, decBuff, &decLen);
652  delete[] tmpStr;
653  tmpStr = NULL;
654  *part = BN_bin2bn(decBuff, decLen, NULL);
655  return E_SUCCESS;
656 }
SINT32 getDOMElementValue(const DOMNode *const pElem, UINT8 *value, UINT32 *valuelen)
Returns the content of the text node(s) under elem as null-terminated C String.
Definition: CAUtil.cpp:746
static SINT32 decode(const UINT8 *in, UINT32 len, UINT8 *out, UINT32 *outlen)
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff...
Definition: CABase64.cpp:41

References CABase64::decode(), E_SUCCESS, and getDOMElementValue().

Referenced by setPublicKeyAsDOMNode().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPublicKeyAsDOMElement()

SINT32 CAASymCipher::getPublicKeyAsDOMElement ( DOMElement *&  elemRoot,
XERCES_CPP_NAMESPACE::DOMDocument *  docOwner 
)

Definition at line 870 of file CAASymCipher.cpp.

871 {
872  if (m_pRSA == NULL)
873  return E_UNKNOWN;
874  elemRoot = createDOMElement(docOwner, "RSAKeyValue");
875  BIGNUM* n = NULL;
876  BIGNUM* e = NULL;
877 #if OPENSSL_VERSION_NUMBER > 0x100020cfL
878  RSA_get0_key(m_pRSA,(const BIGNUM**) &n,(const BIGNUM**) &e, NULL );
879 #else
880  n = m_pRSA->n;
881  e = m_pRSA->e;
882 #endif
883  addKeyPart(elemRoot, docOwner, "Modulus", n);
884  addKeyPart(elemRoot, docOwner, "Exponent", e);
885 
886  return E_SUCCESS;
887 }
SINT32 addKeyPart(DOMElement *elemRoot, XERCES_CPP_NAMESPACE::DOMDocument *docOwner, const char *partName, BIGNUM *part)

References addKeyPart(), createDOMElement(), E_SUCCESS, E_UNKNOWN, and m_pRSA.

Referenced by getPublicKeyAsXML(), CALastMix::processKeyExchange(), and CAMiddleMix::processKeyExchange().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPublicKeyAsXML()

SINT32 CAASymCipher::getPublicKeyAsXML ( UINT8 buff,
UINT32 len 
)

Stores the public key in buff.

The format is as follows:

  \li \c SIZE-N [2 bytes] - number of bytes which are needed for the

modulus n (in network byte order..)

  • N [SIZE-N bytes] - the modulus n as integer (in network byte order)
  • SIZE-E [2 bytes] - number of bytes which are needed for the exponent e (in network byte order..)
  • E [SIZE-E bytes] - the exponent e as integer (in network byte order)
      @param buff byte array in which the public key should be stored
      @param len on input holds the size of \c buff, on return it contains
    
    the number of bytes needed to store the public key
    Return values
    E_UNKNOWNin case of an error
    E_SUCCESSotherwise
    See also
    getPublicKeySize()
    setPublicKey() Returns the number of bytes needed to store we public key. This is the number of bytes needed for a call of getPublicKey().
    Returns
    E_UNKOWN in case of an error number of bytes otherwise
    See also
    getPublicKey Sets the public key to the vaules stored in key. The format must match the format described for getPublicKey().
    Parameters
    keybyte array which holds the new public key
    lenon input,size of key byte array, on successful return number of bytes 'consumed'
    Return values
    E_UNKNOWNin case of an error, the cipher is the uninitialized (no key is set)
    E_SUCCESSotherwise
    See also
    getPublicKey Stores the public key in buff as XML. The format is as follows:
      \verbatim
    <RSAKeyValue>
      <Modulus>
        the modulus of the Key as ds::CryptoBinary
      </Modulus>
      <Exponent>
        the exponent of the key as ds::CryptoBinary
      </Exponent>
    <RSAKeyValue>
    There is NO \0 at the end.
    Parameters
    buffbyte array in which the public key should be stored
    lenon input holds the size of buff, on return it contains the number of bytes needed to store the public key
    Return values
    E_UNKNOWNin case of an error
    E_SUCCESSotherwise
    See also
    setPublicKeyAsXML()

Definition at line 333 of file CAASymCipher.cpp.

334 {
335  if (m_pRSA == NULL || buff == NULL)
336  return E_UNKNOWN;
337  XERCES_CPP_NAMESPACE::DOMDocument *pDoc = createDOMDocument();
338  DOMElement *elemRoot = NULL;
339  getPublicKeyAsDOMElement(elemRoot, pDoc);
340  DOM_Output::dumpToMem(elemRoot, buff, len);
341  if (pDoc != NULL)
342  {
343  pDoc->release();
344  pDoc = NULL;
345  }
346  return E_SUCCESS;
347 }
XERCES_CPP_NAMESPACE::DOMDocument * createDOMDocument()
Parses a timestamp in JDBC timestamp escape format (as it comes from the BI) and outputs the value in...
Definition: CAUtil.cpp:1568
SINT32 getPublicKeyAsDOMElement(DOMElement *&elemRoot, XERCES_CPP_NAMESPACE::DOMDocument *docOwner)
static SINT32 dumpToMem(const DOMNode *node, UINT8 *buff, UINT32 *size)
Dumps the node and all childs into buff.
Definition: DOM_Output.hpp:161

References createDOMDocument(), DOM_Output::dumpToMem(), E_SUCCESS, E_UNKNOWN, getPublicKeyAsDOMElement(), len, and m_pRSA.

Here is the call graph for this function:

◆ setPublicKey() [1/2]

SINT32 CAASymCipher::setPublicKey ( const CACertificate pCert)

Sets the public key which is used for encryption to the contained in the provided certificate.

The key has to be a RSA public key.

Return values
E_SUCCESSif successful
E_UNKNOWNotherwise (in this case the key leaves untouched)

Definition at line 710 of file CAASymCipher.cpp.

711 {
712  if (pCert == NULL)
713  return E_UNKNOWN;
714  EVP_PKEY *pubkey = X509_get_pubkey(pCert->m_pCert);
715  int keyType = 0;
716 #if OPENSSL_VERSION_NUMBER >= 0x1000204fL
717  keyType = EVP_PKEY_id(pubkey);
718 #else
719  keyType = pubkey->type;
720 #endif
721 
722  if (pubkey == NULL || (keyType != EVP_PKEY_RSA && keyType != EVP_PKEY_RSA2))
723  return E_UNKNOWN;
724  RSA *r = NULL;
725 #if OPENSSL_VERSION_NUMBER >= 0x1000204fL
726  r = EVP_PKEY_get1_RSA(pubkey);
727 #else
728  r = pubkey->pkey.rsa;
729 #endif
730 
731  if (RSA_size(r) != 128)
732  return E_UNKNOWN;
733  if (m_pRSA != NULL)
734  RSA_free(m_pRSA);
735  m_pRSA = r;
737  return E_SUCCESS;
738 }

References E_SUCCESS, E_UNKNOWN, CACertificate::m_pCert, m_pRSA, and setRSAFlags().

Referenced by CAMsg::openEncryptedLog().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setPublicKey() [2/2]

SINT32 CAASymCipher::setPublicKey ( const UINT8 modulus,
UINT32  moduluslen,
const UINT8 exponent,
UINT32  exponentlen 
)

Definition at line 741 of file CAASymCipher.cpp.

742 {
743  RSA *tmpRSA = RSA_new();
744  UINT32 decLen = 4096;
745  UINT8 decBuff[4096];
746  CABase64::decode(m, mlen, decBuff, &decLen);
747  BIGNUM* bnE = BN_bin2bn(decBuff, decLen, NULL);
748  decLen = 4096;
749  CABase64::decode(e, elen, decBuff, &decLen);
750  BIGNUM* bnN = BN_bin2bn(decBuff, decLen, NULL);
751  if (bnN != NULL && bnE != NULL)
752  {
753  if (m_pRSA != NULL)
754  RSA_free(m_pRSA);
755  m_pRSA = tmpRSA;
756  #if OPENSSL_VERSION_NUMBER > 0x100020cfL
757  RSA_set0_key(m_pRSA,bnN,bnE, NULL );
758  #else
759  m_pRSA->n=bnN;
760  m_pRSA->e=bnE;
761  #endif
763  return E_SUCCESS;
764  }
765  RSA_free(tmpRSA);
766  return E_UNKNOWN;
767 }

References CABase64::decode(), E_SUCCESS, E_UNKNOWN, m_pRSA, and setRSAFlags().

Here is the call graph for this function:

◆ setPublicKeyAsDOMNode()

SINT32 CAASymCipher::setPublicKeyAsDOMNode ( DOMNode *  node)

Definition at line 658 of file CAASymCipher.cpp.

659 {
660  DOMNode *root = node;
661  while (root != NULL)
662  {
663  if (equals(root->getNodeName(), "RSAKeyValue"))
664  {
665  RSA *tmpRSA = RSA_new();
666  BIGNUM* n = NULL;
667  BIGNUM* e = NULL;
668  DOMNode *child = root->getFirstChild();
669  while (child != NULL)
670  {
671  if (equals(child->getNodeName(), "Modulus"))
672  {
673  getKeyPart(&n, child);
674  }
675  else if (equals(child->getNodeName(), "Exponent"))
676  {
677  getKeyPart(&e, child);
678  }
679  child = child->getNextSibling();
680  }
681  if (n != NULL && e != NULL)
682  {
683  if (m_pRSA != NULL)
684  RSA_free(m_pRSA);
685  m_pRSA = tmpRSA;
686  #if OPENSSL_VERSION_NUMBER > 0x100020cfL
687  RSA_set0_key(m_pRSA,n,e, NULL );
688  #else
689  m_pRSA->n=n;
690  m_pRSA->e=e;
691  #endif
693  return E_SUCCESS;
694  }
695  RSA_free(tmpRSA);
696  return E_UNKNOWN;
697  }
698  root = root->getNextSibling();
699  }
700  return E_UNKNOWN;
701 }
bool equals(const XMLCh *const e1, const char *const e2)
Definition: CAUtil.cpp:645
SINT32 getKeyPart(BIGNUM **part, DOMNode *node)

References E_SUCCESS, E_UNKNOWN, equals(), getKeyPart(), m_pRSA, and setRSAFlags().

Referenced by CAMiddleMix::processKeyExchange(), and setPublicKeyAsXML().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setPublicKeyAsXML()

SINT32 CAASymCipher::setPublicKeyAsXML ( const UINT8 key,
UINT32  len 
)

Sets the public key to the values stored in key.

The format must match the format XML described for getPublicKeyAsXML().

Parameters
keybyte array which holds the new public key
lenon input,size of key byte array, on successful return number of bytes 'consumed'
Return values
E_UNKNOWNin case of an error, the cipher is the uninitialized (no key is set)
E_SUCCESSotherwise
See also
getPublicKeyAsXML

Definition at line 622 of file CAASymCipher.cpp.

623 {
624  if (key == NULL)
625  return E_UNKNOWN;
626 
627  XERCES_CPP_NAMESPACE::DOMDocument *doc = parseDOMDocument(key, len);
628  if (doc == NULL)
629  {
630  return E_UNKNOWN;
631  }
632  DOMElement *root = doc->getDocumentElement();
633  if (root == NULL)
634  {
635  return E_UNKNOWN;
636  }
637  return setPublicKeyAsDOMNode(root);
638 }
XERCES_CPP_NAMESPACE::DOMDocument * parseDOMDocument(const UINT8 *const buff, UINT32 len)
Parses a buffer containing an XML document and returns this document.
Definition: CAUtil.cpp:663
SINT32 setPublicKeyAsDOMNode(DOMNode *node)

References E_UNKNOWN, len, parseDOMDocument(), and setPublicKeyAsDOMNode().

Referenced by CAMiddleMix::init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ testSpeed()

SINT32 CAASymCipher::testSpeed ( )
static

Definition at line 778 of file CAASymCipher.cpp.

779 {
780  const UINT32 runs = 10000;
781  UINT8 *inBuff = new UINT8[128];
782  UINT8 *outBuff = new UINT8[128];
783  getRandom(inBuff, 128);
784  inBuff[0] &= 0x7F;
785 #ifdef INTEL_IPP_CRYPTO
786  int size = 0;
787  ippsRSAGetSize(1024, 512, IppRSAprivate, &size);
788  IppsRSAState *pCtx = (IppsRSAState *)new UINT8[size];
789  IppStatus ret = ippsRSAInit(1024, 512, IppRSAprivate, pCtx);
790  if (ret != ippStsNoErr)
791  {
792  printf("Error in RSA init!\n");
793  return E_UNKNOWN;
794  }
795  ippsBigNumGetSize(1, &size);
796  IppsBigNumState *pE = (IppsBigNumState *)(new UINT8[size]);
797  ippsBigNumInit(1, pE);
798  UINT32 pEValue[] = {0x010001};
799  ret = ippsSet_BN(IppsBigNumPOS, 1, pEValue, pE);
800  if (ret != ippStsNoErr)
801  {
802  printf("Error in setBN(e)!\n");
803  return E_UNKNOWN;
804  }
805  ippsRSAGenerate(pE, 1024, 512, 1024, pCtx, myIppBitSupplier, NULL);
806  if (ret != ippStsNoErr)
807  {
808  printf("Error in RSA generate key!\n");
809  return E_UNKNOWN;
810  }
811 
812  ippsBigNumGetSize(32, &size);
813  IppsBigNumState *pY = (IppsBigNumState *)(new UINT8[size]);
814  ippsBigNumInit(32, pY);
815 
816  IppsBigNumState *pX = (IppsBigNumState *)(new UINT8[size]);
817  ippsBigNumInit(32, pX);
818  UINT32 *pXValue = new UINT32[32];
819  memcpy(pXValue, inBuff, 128);
820  pXValue[0] &= 0x7FFFFFFF;
821  ippsSet_BN(IppsBigNumPOS, 32, pXValue, pX);
822 
823 #else
824  CAASymCipher *pCipher = new CAASymCipher();
825  pCipher->generateKeyPair(1024);
826  UINT32 iLen = 128;
827  pCipher->encryptOAEP(inBuff, 86, inBuff, &iLen);
828 #endif
829  UINT64 start, end;
830  getcurrentTimeMillis(start);
831  for (UINT32 i = 0; i < runs; i++)
832  {
833 #ifdef INTEL_IPP_CRYPTO
834  IppStatus ret = ippsRSADecrypt(pX, pY, pCtx);
835  if (ret != ippStsNoErr)
836  {
837  printf("Error in RSADEcrypt %i!\n", ret);
838  return E_UNKNOWN;
839  }
840 #else
841  pCipher->decryptOAEP(inBuff, outBuff, &iLen);
842 // pCipher->decrypt(inBuff,outBuff);
843 #endif
844  }
846  UINT32 d = diff64(end, start);
847  printf("CAASymCiper::testSpeed() takes %u ms for %u decrypts!\n", d, runs);
848  return E_SUCCESS;
849 }
SINT32 getcurrentTimeMillis(UINT64 &u64Time)
Gets the current Systemtime in milli seconds.
Definition: CAUtil.cpp:252
SINT32 getRandom(UINT32 *val)
Gets 32 random bits.
Definition: CAUtil.cpp:346
UINT32 diff64(const UINT64 &bigop, const UINT64 &smallop)
Definition: CAUtil.hpp:398
SINT32 generateKeyPair(UINT32 size)
Generates a new random key-pair of size bits.
SINT32 decryptOAEP(const UINT8 *from, UINT8 *to, UINT32 *len)
Decrypts one OAEP encoded block which is stored in from.
SINT32 encryptOAEP(const UINT8 *from, UINT32 fromlen, UINT8 *to, UINT32 *len)
Encrypts one block of plain text using OAEP padding.

References CAASymCipher(), decryptOAEP(), diff64(), E_SUCCESS, E_UNKNOWN, encryptOAEP(), generateKeyPair(), getcurrentTimeMillis(), and getRandom().

Here is the call graph for this function:

Member Data Documentation

◆ m_pRSA

RSA* CAASymCipher::m_pRSA
private

The documentation for this class was generated from the following files: