Skip to content

Commit

Permalink
Added key conversion function ref10->orlp-ed25519.
Browse files Browse the repository at this point in the history
Related to issue [orlp#10](orlp#10) from the orlp/ed25519 repository.
  • Loading branch information
GlitchedPolygons committed Oct 9, 2020
1 parent a89df47 commit 11ccdd0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ set(ORLP_ED25519_SRC
${CMAKE_CURRENT_LIST_DIR}/src/verify.c
${CMAKE_CURRENT_LIST_DIR}/src/add_scalar.c
${CMAKE_CURRENT_LIST_DIR}/src/key_exchange.c
${CMAKE_CURRENT_LIST_DIR}/src/key_convert.c
)

add_library(${PROJECT_NAME} ${ORLP_ED25519_SRC})
Expand Down
2 changes: 1 addition & 1 deletion include/orlp-ed25519/ed25519.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void ORLP_ED25519_DECLSPEC ed25519_sign(unsigned char *signature, const unsigned
int ORLP_ED25519_DECLSPEC ed25519_verify(const unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *public_key);
void ORLP_ED25519_DECLSPEC ed25519_add_scalar(unsigned char *public_key, unsigned char *private_key, const unsigned char *scalar);
void ORLP_ED25519_DECLSPEC ed25519_key_exchange(unsigned char *shared_secret, const unsigned char *public_key, const unsigned char *private_key);

void ORLP_ED25519_DECLSPEC ed25519_key_convert_ref10_to_orlp(const unsigned char *private_key_ref10, unsigned char *private_key_orlp);

#ifdef __cplusplus
}
Expand Down
9 changes: 9 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ shared secret. It is recommended to hash the shared secret before using it.
`shared_secret` must be a 32 byte writable buffer where the shared secret will
be stored.

```c
void ed25519_key_convert_ref10_to_orlp(const unsigned char *private_key_ref10,
unsigned char *private_key_orlp);
```
Converts a private key generated in the ref10 format (e.g. via libsodium) into this library's private key format.
`private_key_ref10` needs to be a 32B readable byte buffer containing the ref10 ed25519 private key.
`private_key_orlp` must be a writable 64B output byte buffer into which the converted key shall be written.
Example
-------
Expand Down
9 changes: 9 additions & 0 deletions src/key_convert.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "../include/orlp-ed25519/ed25519.h"
#include "../include/orlp-ed25519/sha512.h"

void ed25519_key_convert_ref10_to_orlp(const unsigned char *private_key_ref10, unsigned char *private_key_orlp) {
sha512(private_key_ref10, 32, private_key_orlp);
private_key_orlp[0] &= 248;
private_key_orlp[31] &= 63;
private_key_orlp[31] |= 64;
}

0 comments on commit 11ccdd0

Please sign in to comment.