c - Difference between 2 vs "\2" -
while trying implement ike session key generation algorithms came across following code snippets following algorithm implementation algorithm generating session key
skeyid_e = hmac (skeyid, skeyid_a || gxy || cky-i || cky-r || 2)
implementation last concatenation hmac of digit 2
hmac_update(ctx, (unsigned char *) "\2", 1)
here hmac_update api used concatenate buffer hmac before finalizing digest , ctx hmac context "\2" adding digit 2 , 1 size of buffer.
my question difference between , escaped unsigned char *
"\2"
, char
/uint8_t
value 2
the difference char
numeric value 2 , string "\2"
former char
, second literal representing character array containing char
numeric value 2 , char
numeric value 0. in other words:
(char)2
single character. typechar
. value 2."\2"
array of characters. type decaysconst char*
. first entry 2 , second entry 0.
since hmac_update
expects second argument pointer bytes use in update, can't provide 2
or (char)2
argument, since doing try convert integer pointer (oops). using "\2"
solves problem providing pointer byte in question. this:
const char value = 2; hmac_update(ctx, &value, 1);
Comments
Post a Comment