Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.31 KB | None | 0 0
  1. int8_t check_param_nonce(unsigned char* message, uint16_t full_message_length, mpz_t B, uint8_t *nonce, RSA_key *key) {
  2.     uint16_t position = 0, data_length = 0, i = 0;
  3.     unsigned char nonce_hex[33] = {"\x00"};
  4.     uint8_t ok = 1;
  5.     ok &= check_input_and_copy_str_to_bignum(message, B, &position, 5, "OK:B=", full_message_length);
  6.     if (strncmp(message + position + 1, "nonce=", 6) != 0) {
  7.         return 0;
  8.     }
  9.     position += 7;
  10.     if ((full_message_length - position < 32) || (message[position + 32] != 124)) {
  11.         return 0;
  12.     }
  13.     memcpy(nonce_hex, &message[position], 32);
  14.     ok &= hex_to_bytes(nonce, nonce_hex);
  15.     if (!ok) {
  16.         return 0;
  17.     }
  18.     return 1;
  19. }
  20.  
  21. unsigned char *bytes_to_hex(uint8_t *bytes, uint8_t length) {
  22.     unsigned char chr[3] = {0};
  23.     unsigned char *hex;
  24.     hex = malloc(2 * length + 1);
  25.     if (hex == NULL) {
  26.         return NULL;
  27.     }
  28.     memset(hex, 0, 2 * length + 1);
  29.     for (int8_t i = 0; i < length; i++) {
  30.         if (bytes[i] == 0) {
  31.             memcpy(hex + 2 * i, "00", 2);
  32.             }
  33.         else {
  34.             sprintf(chr, "%x", bytes[i]);
  35.             if (chr[1] == 0) {
  36.                 chr[1] = chr[0];
  37.                 chr[0] = '0';
  38.             }
  39.             memcpy(hex + 2 * i, chr, 2);
  40.         }
  41.     }
  42.     return hex;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement