Created
August 3, 2015 13:16
-
-
Save iseki-masaya/12b9e33b364e3ac27a33 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Encode (X,Y) using the EdDSA scheme. MINLEN is the required length | |
in bytes for the result. If WITH_PREFIX is set the returned buffer | |
is prefixed with a 0x40 byte. On success 0 is returned and a | |
malloced buffer with the encoded point is stored at R_BUFFER; the | |
length of this buffer is stored at R_BUFLEN. */ | |
static gpg_err_code_t | |
eddsa_encode_x_y (gcry_mpi_t x, gcry_mpi_t y, unsigned int minlen, | |
int with_prefix, | |
unsigned char **r_buffer, unsigned int *r_buflen) | |
{ | |
unsigned char *rawmpi; | |
unsigned int rawmpilen; | |
int off = with_prefix? 1:0; | |
rawmpi = _gcry_mpi_get_buffer_extra (y, minlen, off?-1:0, &rawmpilen, NULL); | |
if (!rawmpi) | |
return gpg_err_code_from_syserror (); | |
if (mpi_test_bit (x, 0) && rawmpilen) | |
rawmpi[off + rawmpilen - 1] |= 0x80; /* Set sign bit. */ | |
if (off) | |
rawmpi[0] = 0x40; | |
*r_buffer = rawmpi; | |
*r_buflen = rawmpilen + off; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment