deps/libssh-0.6.3/src/packet_crypt.c
int packet_hmac_verify(ssh_session session, ssh_buffer buffer,
    unsigned char *mac) {
  unsigned char hmacbuf[EVP_MAX_MD_SIZE] = {0};
  HMACCTX ctx;
  unsigned int len;
  uint32_t seq;

  ctx = hmac_init(session->current_crypto->decryptMAC, 20, SSH_HMAC_SHA1);
  if (ctx == NULL) {
    return -1;
  }

  seq = htonl(session->recv_seq);

  hmac_update(ctx, (unsigned char *) &seq, sizeof(uint32_t));
  hmac_update(ctx, buffer_get_rest(buffer), buffer_get_rest_len(buffer));
  hmac_final(ctx, hmacbuf, &len);

#ifdef DEBUG_CRYPTO
  ssh_print_hexa("received mac",mac,len);
  ssh_print_hexa("Computed mac",hmacbuf,len);
  ssh_print_hexa("seq",(unsigned char *)&seq,sizeof(uint32_t));
#endif
  if (memcmp(mac, hmacbuf, len) == 0) {
    return 0;
  }

  return -1;
}
/**
 * @internal
 *
 * @brief Verify the hmac of a packet
 *
 * @param  session      The session to use.
 * @param  buffer       The buffer to verify the hmac from.
 * @param  mac          The mac to compare with the hmac.
 *
 * @return              0 if hmac and mac are equal, < 0 if not or an error
 *                      occurred.
 */
@internal
@brief Verify the hmac of a packet

@param  session      The session to use.
@param  buffer       The buffer to verify the hmac from.
@param  mac          The mac to compare with the hmac.

@return              0 if hmac and mac are equal, < 0 if not or an error
occurred.
@internal @brief Verify the hmac of a packet @param session The session to use . @param buffer The buffer to verify the hmac from . @param mac The mac to compare with the hmac . @return 0 if hmac and mac are equal < 0 if not or an error occurred .
int packet_hmac_verify(ssh_session session, ssh_buffer buffer,
    unsigned char *mac) {
  unsigned char hmacbuf[EVP_MAX_MD_SIZE] = {0};
  HMACCTX ctx;
  unsigned int len;
  uint32_t seq;
  ctx = hmac_init(session->current_crypto->decryptMAC, 20, SSH_HMAC_SHA1);
  if (ctx == NULL) {
    return -1;
  }
  seq = htonl(session->recv_seq);
  hmac_update(ctx, (unsigned char *) &seq, sizeof(uint32_t));
  hmac_update(ctx, buffer_get_rest(buffer), buffer_get_rest_len(buffer));
  hmac_final(ctx, hmacbuf, &len);
#ifdef DEBUG_CRYPTO
  ssh_print_hexa("received mac",mac,len);
  ssh_print_hexa("Computed mac",hmacbuf,len);
  ssh_print_hexa("seq",(unsigned char *)&seq,sizeof(uint32_t));
#endif
  if (memcmp(mac, hmacbuf, len) == 0) {
    return 0;
  }
  return -1;
}
int packet_hmac_verify ( ssh_session session , ssh_buffer buffer , unsigned char * mac ) { unsigned char hmacbuf [ EVP_MAX_MD_SIZE ] = { 0 } ; HMACCTX ctx ; unsigned int len ; uint32_t seq ; ctx = hmac_init ( session -> current_crypto -> decryptMAC , 20 , SSH_HMAC_SHA1 ) ; if ( ctx == NULL ) { return -1 ; } seq = htonl ( session -> recv_seq ) ; hmac_update ( ctx , ( unsigned char * ) & seq , sizeof ( uint32_t ) ) ; hmac_update ( ctx , buffer_get_rest ( buffer ) , buffer_get_rest_len ( buffer ) ) ; hmac_final ( ctx , hmacbuf , & len ) ; #ifdef DEBUG_CRYPTO ssh_print_hexa ( " " , mac , len ) ; ssh_print_hexa ( " " , hmacbuf , len ) ; ssh_print_hexa ( " " , ( unsigned char * ) & seq , sizeof ( uint32_t ) ) ; #endif if ( memcmp ( mac , hmacbuf , len ) == 0 ) { return 0 ; } return -1 ; }
@internal
 @brief Verify the hmac of a packet
@internal @brief Verify the hmac of a packet