2

I am trying to make a signature verification and then check the content of the message with openssl and EVP functions. I sign with such a code :

bool RSASign( RSA* rsa, 
              const unsigned char* Msg, 
              size_t MsgLen,
              unsigned char** EncMsg, 
              size_t* MsgLenEnc) {
  EVP_MD_CTX* m_RSASignCtx = EVP_MD_CTX_create(); //- cоздает текущий контекст подписи
  EVP_PKEY* priKey  = EVP_PKEY_new(); //- аллоцирует память под новый приватный ключ
  EVP_PKEY_assign_RSA(priKey, rsa);
  if (EVP_DigestSignInit(m_RSASignCtx,NULL, EVP_sha384(), NULL,priKey)<=0) {//- задает использование текущего контекста с таким то ключом
      return false;
  }
  if (EVP_DigestSignUpdate(m_RSASignCtx, Msg, MsgLen) <= 0) {//- хэширует указанное число байт в текущий контекст
      return false;
  }
  if (EVP_DigestSignFinal(m_RSASignCtx, NULL, MsgLenEnc) <=0) {// - с NULL параметром получается достать максимальную длину для аллокации буфера
      return false;
  }
  *EncMsg = (unsigned char*)malloc(*MsgLenEnc);//-аллоцируем буфер
  if (EVP_DigestSignFinal(m_RSASignCtx, *EncMsg, MsgLenEnc) <= 0) {//- подписываем сообщение и кладем в буфер, в длину записывается реальное число байт
      return false;
  }
  EVP_MD_CTX_cleanup(m_RSASignCtx);
  return true;
}

How do EVP functions, connected with signatures, work? Do they encrypt the message on server and send to client and only on the client side compute hash? It is not mentioned in official sources. I need to verify signature and then verify some parts of it's content.

Skotti Bendler
  • 753
  • 1
  • 6
  • 17
  • Also see [EVP Signing and Verifying](https://wiki.openssl.org/index.php/EVP_Signing_and_Verifying), [How does RSA signature verification work?](https://crypto.stackexchange.com/questions/9896/how-does-rsa-signature-verification-work), [What is the difference between encrypting and signing in asymmetric encryption?](http://stackoverflow.com/q/454048/608639), [Digital signature](https://en.wikipedia.org/wiki/Digital_signature), etc.A good docs is Bernstein's [RSA signatures and Rabin–Williams signatures: the state of the art](https://cr.yp.to/sigs/rwsota-20080131.pdf). – jww May 17 '17 at 13:25

0 Answers0