forked from irungentoo/toxcore
-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Use
struct
s for extended public/secret keys.
- Loading branch information
Showing
16 changed files
with
261 additions
and
139 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* SPDX-License-Identifier: GPL-3.0-or-later | ||
* Copyright © 2016-2024 The TokTok team. | ||
* Copyright © 2013 Tox project. | ||
*/ | ||
|
||
#include "crypto_core_pack.h" | ||
|
||
#include <string.h> | ||
|
||
#include "bin_pack.h" | ||
#include "bin_unpack.h" | ||
#include "crypto_core.h" | ||
|
||
bool pack_extended_public_key(const Extended_Public_Key *key, Bin_Pack *bp) | ||
{ | ||
uint8_t ext_key[EXT_PUBLIC_KEY_SIZE]; | ||
memcpy(ext_key, key->enc, CRYPTO_PUBLIC_KEY_SIZE); | ||
memcpy(&ext_key[CRYPTO_PUBLIC_KEY_SIZE], key->sig, CRYPTO_SIGN_PUBLIC_KEY_SIZE); | ||
|
||
return bin_pack_bin(bp, ext_key, EXT_PUBLIC_KEY_SIZE); | ||
} | ||
|
||
bool pack_extended_secret_key(const Extended_Secret_Key *key, Bin_Pack *bp) | ||
{ | ||
uint8_t ext_key[EXT_SECRET_KEY_SIZE]; | ||
memcpy(ext_key, key->enc, CRYPTO_SECRET_KEY_SIZE); | ||
memcpy(&ext_key[CRYPTO_SECRET_KEY_SIZE], key->sig, CRYPTO_SIGN_SECRET_KEY_SIZE); | ||
|
||
return bin_pack_bin(bp, ext_key, EXT_SECRET_KEY_SIZE); | ||
} | ||
|
||
bool unpack_extended_public_key(Extended_Public_Key *key, Bin_Unpack *bu) | ||
{ | ||
uint8_t ext_key[EXT_PUBLIC_KEY_SIZE]; | ||
|
||
if (!bin_unpack_bin_fixed(bu, ext_key, EXT_PUBLIC_KEY_SIZE)) { | ||
return false; | ||
} | ||
|
||
memcpy(key->enc, ext_key, CRYPTO_PUBLIC_KEY_SIZE); | ||
memcpy(key->sig, &ext_key[CRYPTO_PUBLIC_KEY_SIZE], CRYPTO_SIGN_PUBLIC_KEY_SIZE); | ||
|
||
return true; | ||
} | ||
|
||
bool unpack_extended_secret_key(Extended_Secret_Key *key, Bin_Unpack *bu) | ||
{ | ||
uint8_t ext_key[EXT_SECRET_KEY_SIZE]; | ||
|
||
if (!bin_unpack_bin_fixed(bu, ext_key, EXT_SECRET_KEY_SIZE)) { | ||
return false; | ||
} | ||
|
||
memcpy(key->enc, ext_key, CRYPTO_SECRET_KEY_SIZE); | ||
memcpy(key->sig, &ext_key[CRYPTO_SECRET_KEY_SIZE], CRYPTO_SIGN_SECRET_KEY_SIZE); | ||
|
||
return true; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* SPDX-License-Identifier: GPL-3.0-or-later | ||
* Copyright © 2016-2024 The TokTok team. | ||
* Copyright © 2013 Tox project. | ||
*/ | ||
|
||
#ifndef C_TOXCORE_TOXCORE_CRYPTO_CORE_PACK_H | ||
#define C_TOXCORE_TOXCORE_CRYPTO_CORE_PACK_H | ||
|
||
#include <stdbool.h> | ||
#include <stddef.h> | ||
#include <stdint.h> | ||
|
||
#include "attributes.h" | ||
#include "bin_pack.h" | ||
#include "bin_unpack.h" | ||
#include "crypto_core.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
non_null() bool pack_extended_public_key(const Extended_Public_Key *key, Bin_Pack *bp); | ||
non_null() bool pack_extended_secret_key(const Extended_Secret_Key *key, Bin_Pack *bp); | ||
non_null() bool unpack_extended_public_key(Extended_Public_Key *key, Bin_Unpack *bu); | ||
non_null() bool unpack_extended_secret_key(Extended_Secret_Key *key, Bin_Unpack *bu); | ||
|
||
#ifdef __cplusplus | ||
} /* extern "C" */ | ||
#endif | ||
|
||
#endif /* C_TOXCORE_TOXCORE_CRYPTO_CORE_PACK_H */ |
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
Oops, something went wrong.