Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int8_t check_param_nonce(unsigned char* message, uint16_t full_message_length, mpz_t B, uint8_t *nonce, RSA_key *key) {
- uint16_t position = 0, data_length = 0, i = 0;
- unsigned char nonce_hex[33] = {"\x00"};
- uint8_t ok = 1;
- ok &= check_input_and_copy_str_to_bignum(message, B, &position, 5, "OK:B=", full_message_length);
- if (strncmp(message + position + 1, "nonce=", 6) != 0) {
- return 0;
- }
- position += 7;
- if ((full_message_length - position < 32) || (message[position + 32] != 124)) {
- return 0;
- }
- memcpy(nonce_hex, &message[position], 32);
- ok &= hex_to_bytes(nonce, nonce_hex);
- if (!ok) {
- return 0;
- }
- return 1;
- }
- unsigned char *bytes_to_hex(uint8_t *bytes, uint8_t length) {
- unsigned char chr[3] = {0};
- unsigned char *hex;
- hex = malloc(2 * length + 1);
- if (hex == NULL) {
- return NULL;
- }
- memset(hex, 0, 2 * length + 1);
- for (int8_t i = 0; i < length; i++) {
- if (bytes[i] == 0) {
- memcpy(hex + 2 * i, "00", 2);
- }
- else {
- sprintf(chr, "%x", bytes[i]);
- if (chr[1] == 0) {
- chr[1] = chr[0];
- chr[0] = '0';
- }
- memcpy(hex + 2 * i, chr, 2);
- }
- }
- return hex;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement