mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-12-24 16:43:36 +00:00
New function xs_sha256_base64().
This commit is contained in:
parent
8dadbbc78e
commit
9573dbcdb6
2 changed files with 24 additions and 4 deletions
4
http.c
4
http.c
|
@ -43,9 +43,9 @@ d_char *http_signed_request(snac *snac, char *method, char *url,
|
|||
|
||||
/* digest */
|
||||
if (body != NULL)
|
||||
digest = xs_sha256_hex(body, b_size);
|
||||
digest = xs_sha256_base64(body, b_size);
|
||||
else
|
||||
digest = xs_sha256_hex("", 0);
|
||||
digest = xs_sha256_base64("", 0);
|
||||
|
||||
seckey = xs_dict_get(snac->key, "secret");
|
||||
|
||||
|
|
24
xs_openssl.h
24
xs_openssl.h
|
@ -7,6 +7,7 @@
|
|||
d_char *xs_md5_hex(const void *input, int size);
|
||||
d_char *xs_sha1_hex(const void *input, int size);
|
||||
d_char *xs_sha256_hex(const void *input, int size);
|
||||
d_char *xs_sha256_base64(const void *input, int size);
|
||||
d_char *xs_rsa_genkey(int bits);
|
||||
d_char *xs_rsa_sign(char *secret, char *mem, int size);
|
||||
int xs_rsa_verify(char *pubkey, char *mem, int size, char *b64sig);
|
||||
|
@ -45,19 +46,38 @@ d_char *xs_sha1_hex(const void *input, int size)
|
|||
}
|
||||
|
||||
|
||||
d_char *xs_sha256_hex(const void *input, int size)
|
||||
unsigned char *_xs_sha256(const void *input, int size, unsigned char *sha256)
|
||||
{
|
||||
unsigned char sha256[32];
|
||||
SHA256_CTX ctx;
|
||||
|
||||
SHA256_Init(&ctx);
|
||||
SHA256_Update(&ctx, input, size);
|
||||
SHA256_Final(sha256, &ctx);
|
||||
|
||||
return sha256;
|
||||
}
|
||||
|
||||
|
||||
d_char *xs_sha256_hex(const void *input, int size)
|
||||
{
|
||||
unsigned char sha256[32];
|
||||
|
||||
_xs_sha256(input, size, sha256);
|
||||
|
||||
return xs_hex_enc((char *)sha256, sizeof(sha256));
|
||||
}
|
||||
|
||||
|
||||
d_char *xs_sha256_base64(const void *input, int size)
|
||||
{
|
||||
unsigned char sha256[32];
|
||||
|
||||
_xs_sha256(input, size, sha256);
|
||||
|
||||
return xs_base64_enc((char *)sha256, sizeof(sha256));
|
||||
}
|
||||
|
||||
|
||||
d_char *xs_rsa_genkey(int bits)
|
||||
/* generates an RSA keypair */
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue