Skip to content

Commit ddfe2e8

Browse files
authored
Merge pull request #597 from sa-kib/ed25519ctx
contextualized extension of the Ed25519 scheme
2 parents 8fd5dad + 23d7091 commit ddfe2e8

13 files changed

+531
-93
lines changed

doc/crypt.tex

+31-7
Original file line numberDiff line numberDiff line change
@@ -5909,25 +5909,49 @@ \subsection{EdDSA Cryptographic Operations}
59095909
To sign and/or verify a message use the following functions:
59105910

59115911
\index{ed25519\_sign}
5912+
\index{ed25519ctx\_sign}
5913+
\index{ed25519ph\_sign}
59125914
\begin{verbatim}
5913-
int ed25519_sign(const unsigned char *msg, unsigned long msglen,
5914-
unsigned char *sig, unsigned long *siglen,
5915+
int ed25519_sign(const unsigned char *msg, unsigned long msglen,
5916+
unsigned char *sig, unsigned long *siglen,
59155917
const curve25519_key *private_key);
5918+
int ed25519ctx_sign(const unsigned char *msg, unsigned long msglen,
5919+
unsigned char *sig, unsigned long *siglen,
5920+
const unsigned char *ctx, unsigned long ctxlen,
5921+
const curve25519_key *private_key);
5922+
int ed25519ph_sign(const unsigned char *msg, unsigned long msglen,
5923+
unsigned char *sig, unsigned long *siglen,
5924+
const unsigned char *ctx, unsigned long ctxlen,
5925+
const curve25519_key *private_key);
59165926
\end{verbatim}
59175927

5918-
This function will EdDSA sign the message stored in the array pointed to by \textit{msg} of length \textit{msglen} octets. The signature
5919-
will be stored in the array pointed to by \textit{sig} of length \textit{siglen} octets.
5928+
These functions will EdDSA sign the message stored in the array pointed to by \textit{msg} of length \textit{msglen} octets. The signature
5929+
will be stored in the array pointed to by \textit{sig} of length \textit{siglen} octets. The \texttt{ctx} and \texttt{ph} variants also
5930+
allow passing a context \textit{ctx} of length \textit{ctxlen} octets. This context is allowed to be max. 255 octets long.
59205931

59215932
\index{ed25519\_verify}
5933+
\index{ed25519ctx\_verify}
5934+
\index{ed25519ph\_verify}
59225935
\begin{verbatim}
59235936
int ed25519_verify(const unsigned char *msg, unsigned long msglen,
59245937
const unsigned char *sig, unsigned long siglen,
5925-
int *stat, const curve25519_key *public_key);
5938+
int *stat,
5939+
const curve25519_key *public_key);
5940+
int ed25519ctx_verify(const unsigned char *msg, unsigned long msglen,
5941+
const unsigned char *sig, unsigned long siglen,
5942+
const unsigned char *ctx, unsigned long ctxlen,
5943+
int *stat,
5944+
const curve25519_key *public_key);
5945+
int ed25519ph_verify(const unsigned char *msg, unsigned long msglen,
5946+
const unsigned char *sig, unsigned long siglen,
5947+
const unsigned char *ctx, unsigned long ctxlen,
5948+
int *stat,
5949+
const curve25519_key *public_key);
59265950
\end{verbatim}
59275951

5928-
This function will verify the EdDSA signature in the array pointed to by \textit{sig} of length \textit{siglen} octets, against the message
5952+
These functions will verify the EdDSA signature in the array pointed to by \textit{sig} of length \textit{siglen} octets, against the message
59295953
pointed to by the array \textit{msg} of length \textit{msglen}. It will store a non--zero value in \textit{stat} if the signature is valid. Note:
5930-
the function will not return an error if the signature is invalid. It will return an error, if the actual signature payload is an invalid format.
5954+
the function will not return an error if the signature is invalid. It will only return an error if the actual signature payload is an invalid format.
59315955

59325956

59335957
\chapter{Digital Signature Algorithm}

libtomcrypt_VS2008.vcproj

+4
Original file line numberDiff line numberDiff line change
@@ -2326,6 +2326,10 @@
23262326
<Filter
23272327
Name="ec25519"
23282328
>
2329+
<File
2330+
RelativePath="src\pk\ec25519\ec25519_crypto_ctx.c"
2331+
>
2332+
</File>
23292333
<File
23302334
RelativePath="src\pk\ec25519\ec25519_export.c"
23312335
>

makefile.mingw

+11-11
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,17 @@ src/pk/dsa/dsa_decrypt_key.o src/pk/dsa/dsa_encrypt_key.o src/pk/dsa/dsa_export.
179179
src/pk/dsa/dsa_generate_key.o src/pk/dsa/dsa_generate_pqg.o src/pk/dsa/dsa_import.o \
180180
src/pk/dsa/dsa_make_key.o src/pk/dsa/dsa_set.o src/pk/dsa/dsa_set_pqg_dsaparam.o \
181181
src/pk/dsa/dsa_shared_secret.o src/pk/dsa/dsa_sign_hash.o src/pk/dsa/dsa_verify_hash.o \
182-
src/pk/dsa/dsa_verify_key.o src/pk/ec25519/ec25519_export.o src/pk/ec25519/ec25519_import_pkcs8.o \
183-
src/pk/ec25519/tweetnacl.o src/pk/ecc/ecc.o src/pk/ecc/ecc_ansi_x963_export.o \
184-
src/pk/ecc/ecc_ansi_x963_import.o src/pk/ecc/ecc_decrypt_key.o src/pk/ecc/ecc_encrypt_key.o \
185-
src/pk/ecc/ecc_export.o src/pk/ecc/ecc_export_openssl.o src/pk/ecc/ecc_find_curve.o \
186-
src/pk/ecc/ecc_free.o src/pk/ecc/ecc_get_key.o src/pk/ecc/ecc_get_oid_str.o src/pk/ecc/ecc_get_size.o \
187-
src/pk/ecc/ecc_import.o src/pk/ecc/ecc_import_openssl.o src/pk/ecc/ecc_import_pkcs8.o \
188-
src/pk/ecc/ecc_import_x509.o src/pk/ecc/ecc_make_key.o src/pk/ecc/ecc_recover_key.o \
189-
src/pk/ecc/ecc_set_curve.o src/pk/ecc/ecc_set_curve_internal.o src/pk/ecc/ecc_set_key.o \
190-
src/pk/ecc/ecc_shared_secret.o src/pk/ecc/ecc_sign_hash.o src/pk/ecc/ecc_sizes.o \
191-
src/pk/ecc/ecc_ssh_ecdsa_encode_name.o src/pk/ecc/ecc_verify_hash.o src/pk/ecc/ltc_ecc_export_point.o \
192-
src/pk/ecc/ltc_ecc_import_point.o src/pk/ecc/ltc_ecc_is_point.o \
182+
src/pk/dsa/dsa_verify_key.o src/pk/ec25519/ec25519_crypto_ctx.o src/pk/ec25519/ec25519_export.o \
183+
src/pk/ec25519/ec25519_import_pkcs8.o src/pk/ec25519/tweetnacl.o src/pk/ecc/ecc.o \
184+
src/pk/ecc/ecc_ansi_x963_export.o src/pk/ecc/ecc_ansi_x963_import.o src/pk/ecc/ecc_decrypt_key.o \
185+
src/pk/ecc/ecc_encrypt_key.o src/pk/ecc/ecc_export.o src/pk/ecc/ecc_export_openssl.o \
186+
src/pk/ecc/ecc_find_curve.o src/pk/ecc/ecc_free.o src/pk/ecc/ecc_get_key.o src/pk/ecc/ecc_get_oid_str.o \
187+
src/pk/ecc/ecc_get_size.o src/pk/ecc/ecc_import.o src/pk/ecc/ecc_import_openssl.o \
188+
src/pk/ecc/ecc_import_pkcs8.o src/pk/ecc/ecc_import_x509.o src/pk/ecc/ecc_make_key.o \
189+
src/pk/ecc/ecc_recover_key.o src/pk/ecc/ecc_set_curve.o src/pk/ecc/ecc_set_curve_internal.o \
190+
src/pk/ecc/ecc_set_key.o src/pk/ecc/ecc_shared_secret.o src/pk/ecc/ecc_sign_hash.o \
191+
src/pk/ecc/ecc_sizes.o src/pk/ecc/ecc_ssh_ecdsa_encode_name.o src/pk/ecc/ecc_verify_hash.o \
192+
src/pk/ecc/ltc_ecc_export_point.o src/pk/ecc/ltc_ecc_import_point.o src/pk/ecc/ltc_ecc_is_point.o \
193193
src/pk/ecc/ltc_ecc_is_point_at_infinity.o src/pk/ecc/ltc_ecc_map.o src/pk/ecc/ltc_ecc_mul2add.o \
194194
src/pk/ecc/ltc_ecc_mulmod.o src/pk/ecc/ltc_ecc_mulmod_timing.o src/pk/ecc/ltc_ecc_points.o \
195195
src/pk/ecc/ltc_ecc_projective_add_point.o src/pk/ecc/ltc_ecc_projective_dbl_point.o \

makefile.msvc

+11-11
Original file line numberDiff line numberDiff line change
@@ -172,17 +172,17 @@ src/pk/dsa/dsa_decrypt_key.obj src/pk/dsa/dsa_encrypt_key.obj src/pk/dsa/dsa_exp
172172
src/pk/dsa/dsa_generate_key.obj src/pk/dsa/dsa_generate_pqg.obj src/pk/dsa/dsa_import.obj \
173173
src/pk/dsa/dsa_make_key.obj src/pk/dsa/dsa_set.obj src/pk/dsa/dsa_set_pqg_dsaparam.obj \
174174
src/pk/dsa/dsa_shared_secret.obj src/pk/dsa/dsa_sign_hash.obj src/pk/dsa/dsa_verify_hash.obj \
175-
src/pk/dsa/dsa_verify_key.obj src/pk/ec25519/ec25519_export.obj src/pk/ec25519/ec25519_import_pkcs8.obj \
176-
src/pk/ec25519/tweetnacl.obj src/pk/ecc/ecc.obj src/pk/ecc/ecc_ansi_x963_export.obj \
177-
src/pk/ecc/ecc_ansi_x963_import.obj src/pk/ecc/ecc_decrypt_key.obj src/pk/ecc/ecc_encrypt_key.obj \
178-
src/pk/ecc/ecc_export.obj src/pk/ecc/ecc_export_openssl.obj src/pk/ecc/ecc_find_curve.obj \
179-
src/pk/ecc/ecc_free.obj src/pk/ecc/ecc_get_key.obj src/pk/ecc/ecc_get_oid_str.obj src/pk/ecc/ecc_get_size.obj \
180-
src/pk/ecc/ecc_import.obj src/pk/ecc/ecc_import_openssl.obj src/pk/ecc/ecc_import_pkcs8.obj \
181-
src/pk/ecc/ecc_import_x509.obj src/pk/ecc/ecc_make_key.obj src/pk/ecc/ecc_recover_key.obj \
182-
src/pk/ecc/ecc_set_curve.obj src/pk/ecc/ecc_set_curve_internal.obj src/pk/ecc/ecc_set_key.obj \
183-
src/pk/ecc/ecc_shared_secret.obj src/pk/ecc/ecc_sign_hash.obj src/pk/ecc/ecc_sizes.obj \
184-
src/pk/ecc/ecc_ssh_ecdsa_encode_name.obj src/pk/ecc/ecc_verify_hash.obj src/pk/ecc/ltc_ecc_export_point.obj \
185-
src/pk/ecc/ltc_ecc_import_point.obj src/pk/ecc/ltc_ecc_is_point.obj \
175+
src/pk/dsa/dsa_verify_key.obj src/pk/ec25519/ec25519_crypto_ctx.obj src/pk/ec25519/ec25519_export.obj \
176+
src/pk/ec25519/ec25519_import_pkcs8.obj src/pk/ec25519/tweetnacl.obj src/pk/ecc/ecc.obj \
177+
src/pk/ecc/ecc_ansi_x963_export.obj src/pk/ecc/ecc_ansi_x963_import.obj src/pk/ecc/ecc_decrypt_key.obj \
178+
src/pk/ecc/ecc_encrypt_key.obj src/pk/ecc/ecc_export.obj src/pk/ecc/ecc_export_openssl.obj \
179+
src/pk/ecc/ecc_find_curve.obj src/pk/ecc/ecc_free.obj src/pk/ecc/ecc_get_key.obj src/pk/ecc/ecc_get_oid_str.obj \
180+
src/pk/ecc/ecc_get_size.obj src/pk/ecc/ecc_import.obj src/pk/ecc/ecc_import_openssl.obj \
181+
src/pk/ecc/ecc_import_pkcs8.obj src/pk/ecc/ecc_import_x509.obj src/pk/ecc/ecc_make_key.obj \
182+
src/pk/ecc/ecc_recover_key.obj src/pk/ecc/ecc_set_curve.obj src/pk/ecc/ecc_set_curve_internal.obj \
183+
src/pk/ecc/ecc_set_key.obj src/pk/ecc/ecc_shared_secret.obj src/pk/ecc/ecc_sign_hash.obj \
184+
src/pk/ecc/ecc_sizes.obj src/pk/ecc/ecc_ssh_ecdsa_encode_name.obj src/pk/ecc/ecc_verify_hash.obj \
185+
src/pk/ecc/ltc_ecc_export_point.obj src/pk/ecc/ltc_ecc_import_point.obj src/pk/ecc/ltc_ecc_is_point.obj \
186186
src/pk/ecc/ltc_ecc_is_point_at_infinity.obj src/pk/ecc/ltc_ecc_map.obj src/pk/ecc/ltc_ecc_mul2add.obj \
187187
src/pk/ecc/ltc_ecc_mulmod.obj src/pk/ecc/ltc_ecc_mulmod_timing.obj src/pk/ecc/ltc_ecc_points.obj \
188188
src/pk/ecc/ltc_ecc_projective_add_point.obj src/pk/ecc/ltc_ecc_projective_dbl_point.obj \

makefile.unix

+11-11
Original file line numberDiff line numberDiff line change
@@ -189,17 +189,17 @@ src/pk/dsa/dsa_decrypt_key.o src/pk/dsa/dsa_encrypt_key.o src/pk/dsa/dsa_export.
189189
src/pk/dsa/dsa_generate_key.o src/pk/dsa/dsa_generate_pqg.o src/pk/dsa/dsa_import.o \
190190
src/pk/dsa/dsa_make_key.o src/pk/dsa/dsa_set.o src/pk/dsa/dsa_set_pqg_dsaparam.o \
191191
src/pk/dsa/dsa_shared_secret.o src/pk/dsa/dsa_sign_hash.o src/pk/dsa/dsa_verify_hash.o \
192-
src/pk/dsa/dsa_verify_key.o src/pk/ec25519/ec25519_export.o src/pk/ec25519/ec25519_import_pkcs8.o \
193-
src/pk/ec25519/tweetnacl.o src/pk/ecc/ecc.o src/pk/ecc/ecc_ansi_x963_export.o \
194-
src/pk/ecc/ecc_ansi_x963_import.o src/pk/ecc/ecc_decrypt_key.o src/pk/ecc/ecc_encrypt_key.o \
195-
src/pk/ecc/ecc_export.o src/pk/ecc/ecc_export_openssl.o src/pk/ecc/ecc_find_curve.o \
196-
src/pk/ecc/ecc_free.o src/pk/ecc/ecc_get_key.o src/pk/ecc/ecc_get_oid_str.o src/pk/ecc/ecc_get_size.o \
197-
src/pk/ecc/ecc_import.o src/pk/ecc/ecc_import_openssl.o src/pk/ecc/ecc_import_pkcs8.o \
198-
src/pk/ecc/ecc_import_x509.o src/pk/ecc/ecc_make_key.o src/pk/ecc/ecc_recover_key.o \
199-
src/pk/ecc/ecc_set_curve.o src/pk/ecc/ecc_set_curve_internal.o src/pk/ecc/ecc_set_key.o \
200-
src/pk/ecc/ecc_shared_secret.o src/pk/ecc/ecc_sign_hash.o src/pk/ecc/ecc_sizes.o \
201-
src/pk/ecc/ecc_ssh_ecdsa_encode_name.o src/pk/ecc/ecc_verify_hash.o src/pk/ecc/ltc_ecc_export_point.o \
202-
src/pk/ecc/ltc_ecc_import_point.o src/pk/ecc/ltc_ecc_is_point.o \
192+
src/pk/dsa/dsa_verify_key.o src/pk/ec25519/ec25519_crypto_ctx.o src/pk/ec25519/ec25519_export.o \
193+
src/pk/ec25519/ec25519_import_pkcs8.o src/pk/ec25519/tweetnacl.o src/pk/ecc/ecc.o \
194+
src/pk/ecc/ecc_ansi_x963_export.o src/pk/ecc/ecc_ansi_x963_import.o src/pk/ecc/ecc_decrypt_key.o \
195+
src/pk/ecc/ecc_encrypt_key.o src/pk/ecc/ecc_export.o src/pk/ecc/ecc_export_openssl.o \
196+
src/pk/ecc/ecc_find_curve.o src/pk/ecc/ecc_free.o src/pk/ecc/ecc_get_key.o src/pk/ecc/ecc_get_oid_str.o \
197+
src/pk/ecc/ecc_get_size.o src/pk/ecc/ecc_import.o src/pk/ecc/ecc_import_openssl.o \
198+
src/pk/ecc/ecc_import_pkcs8.o src/pk/ecc/ecc_import_x509.o src/pk/ecc/ecc_make_key.o \
199+
src/pk/ecc/ecc_recover_key.o src/pk/ecc/ecc_set_curve.o src/pk/ecc/ecc_set_curve_internal.o \
200+
src/pk/ecc/ecc_set_key.o src/pk/ecc/ecc_shared_secret.o src/pk/ecc/ecc_sign_hash.o \
201+
src/pk/ecc/ecc_sizes.o src/pk/ecc/ecc_ssh_ecdsa_encode_name.o src/pk/ecc/ecc_verify_hash.o \
202+
src/pk/ecc/ltc_ecc_export_point.o src/pk/ecc/ltc_ecc_import_point.o src/pk/ecc/ltc_ecc_is_point.o \
203203
src/pk/ecc/ltc_ecc_is_point_at_infinity.o src/pk/ecc/ltc_ecc_map.o src/pk/ecc/ltc_ecc_mul2add.o \
204204
src/pk/ecc/ltc_ecc_mulmod.o src/pk/ecc/ltc_ecc_mulmod_timing.o src/pk/ecc/ltc_ecc_points.o \
205205
src/pk/ecc/ltc_ecc_projective_add_point.o src/pk/ecc/ltc_ecc_projective_dbl_point.o \

makefile_include.mk

+11-11
Original file line numberDiff line numberDiff line change
@@ -350,17 +350,17 @@ src/pk/dsa/dsa_decrypt_key.o src/pk/dsa/dsa_encrypt_key.o src/pk/dsa/dsa_export.
350350
src/pk/dsa/dsa_generate_key.o src/pk/dsa/dsa_generate_pqg.o src/pk/dsa/dsa_import.o \
351351
src/pk/dsa/dsa_make_key.o src/pk/dsa/dsa_set.o src/pk/dsa/dsa_set_pqg_dsaparam.o \
352352
src/pk/dsa/dsa_shared_secret.o src/pk/dsa/dsa_sign_hash.o src/pk/dsa/dsa_verify_hash.o \
353-
src/pk/dsa/dsa_verify_key.o src/pk/ec25519/ec25519_export.o src/pk/ec25519/ec25519_import_pkcs8.o \
354-
src/pk/ec25519/tweetnacl.o src/pk/ecc/ecc.o src/pk/ecc/ecc_ansi_x963_export.o \
355-
src/pk/ecc/ecc_ansi_x963_import.o src/pk/ecc/ecc_decrypt_key.o src/pk/ecc/ecc_encrypt_key.o \
356-
src/pk/ecc/ecc_export.o src/pk/ecc/ecc_export_openssl.o src/pk/ecc/ecc_find_curve.o \
357-
src/pk/ecc/ecc_free.o src/pk/ecc/ecc_get_key.o src/pk/ecc/ecc_get_oid_str.o src/pk/ecc/ecc_get_size.o \
358-
src/pk/ecc/ecc_import.o src/pk/ecc/ecc_import_openssl.o src/pk/ecc/ecc_import_pkcs8.o \
359-
src/pk/ecc/ecc_import_x509.o src/pk/ecc/ecc_make_key.o src/pk/ecc/ecc_recover_key.o \
360-
src/pk/ecc/ecc_set_curve.o src/pk/ecc/ecc_set_curve_internal.o src/pk/ecc/ecc_set_key.o \
361-
src/pk/ecc/ecc_shared_secret.o src/pk/ecc/ecc_sign_hash.o src/pk/ecc/ecc_sizes.o \
362-
src/pk/ecc/ecc_ssh_ecdsa_encode_name.o src/pk/ecc/ecc_verify_hash.o src/pk/ecc/ltc_ecc_export_point.o \
363-
src/pk/ecc/ltc_ecc_import_point.o src/pk/ecc/ltc_ecc_is_point.o \
353+
src/pk/dsa/dsa_verify_key.o src/pk/ec25519/ec25519_crypto_ctx.o src/pk/ec25519/ec25519_export.o \
354+
src/pk/ec25519/ec25519_import_pkcs8.o src/pk/ec25519/tweetnacl.o src/pk/ecc/ecc.o \
355+
src/pk/ecc/ecc_ansi_x963_export.o src/pk/ecc/ecc_ansi_x963_import.o src/pk/ecc/ecc_decrypt_key.o \
356+
src/pk/ecc/ecc_encrypt_key.o src/pk/ecc/ecc_export.o src/pk/ecc/ecc_export_openssl.o \
357+
src/pk/ecc/ecc_find_curve.o src/pk/ecc/ecc_free.o src/pk/ecc/ecc_get_key.o src/pk/ecc/ecc_get_oid_str.o \
358+
src/pk/ecc/ecc_get_size.o src/pk/ecc/ecc_import.o src/pk/ecc/ecc_import_openssl.o \
359+
src/pk/ecc/ecc_import_pkcs8.o src/pk/ecc/ecc_import_x509.o src/pk/ecc/ecc_make_key.o \
360+
src/pk/ecc/ecc_recover_key.o src/pk/ecc/ecc_set_curve.o src/pk/ecc/ecc_set_curve_internal.o \
361+
src/pk/ecc/ecc_set_key.o src/pk/ecc/ecc_shared_secret.o src/pk/ecc/ecc_sign_hash.o \
362+
src/pk/ecc/ecc_sizes.o src/pk/ecc/ecc_ssh_ecdsa_encode_name.o src/pk/ecc/ecc_verify_hash.o \
363+
src/pk/ecc/ltc_ecc_export_point.o src/pk/ecc/ltc_ecc_import_point.o src/pk/ecc/ltc_ecc_is_point.o \
364364
src/pk/ecc/ltc_ecc_is_point_at_infinity.o src/pk/ecc/ltc_ecc_map.o src/pk/ecc/ltc_ecc_mul2add.o \
365365
src/pk/ecc/ltc_ecc_mulmod.o src/pk/ecc/ltc_ecc_mulmod_timing.o src/pk/ecc/ltc_ecc_points.o \
366366
src/pk/ecc/ltc_ecc_projective_add_point.o src/pk/ecc/ltc_ecc_projective_dbl_point.o \

src/headers/tomcrypt_pk.h

+22-4
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,31 @@ int ed25519_import_pkcs8(const unsigned char *in, unsigned long inlen,
355355
const void *pwd, unsigned long pwdlen,
356356
curve25519_key *key);
357357

358-
int ed25519_sign(const unsigned char *msg, unsigned long msglen,
359-
unsigned char *sig, unsigned long *siglen,
358+
int ed25519_sign(const unsigned char *msg, unsigned long msglen,
359+
unsigned char *sig, unsigned long *siglen,
360360
const curve25519_key *private_key);
361-
361+
int ed25519ctx_sign(const unsigned char *msg, unsigned long msglen,
362+
unsigned char *sig, unsigned long *siglen,
363+
const unsigned char *ctx, unsigned long ctxlen,
364+
const curve25519_key *private_key);
365+
int ed25519ph_sign(const unsigned char *msg, unsigned long msglen,
366+
unsigned char *sig, unsigned long *siglen,
367+
const unsigned char *ctx, unsigned long ctxlen,
368+
const curve25519_key *private_key);
362369
int ed25519_verify(const unsigned char *msg, unsigned long msglen,
363370
const unsigned char *sig, unsigned long siglen,
364-
int *stat, const curve25519_key *public_key);
371+
int *stat,
372+
const curve25519_key *public_key);
373+
int ed25519ctx_verify(const unsigned char *msg, unsigned long msglen,
374+
const unsigned char *sig, unsigned long siglen,
375+
const unsigned char *ctx, unsigned long ctxlen,
376+
int *stat,
377+
const curve25519_key *public_key);
378+
int ed25519ph_verify(const unsigned char *msg, unsigned long msglen,
379+
const unsigned char *sig, unsigned long siglen,
380+
const unsigned char *ctx, unsigned long ctxlen,
381+
int *stat,
382+
const curve25519_key *public_key);
365383

366384
/** X25519 Key-Exchange API */
367385
int x25519_make_key(prng_state *prng, int wprng, curve25519_key *key);

src/headers/tomcrypt_private.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -331,16 +331,19 @@ int dsa_int_validate_primes(const dsa_key *key, int *stat);
331331
int tweetnacl_crypto_sign(
332332
unsigned char *sm,unsigned long long *smlen,
333333
const unsigned char *m,unsigned long long mlen,
334-
const unsigned char *sk, const unsigned char *pk);
334+
const unsigned char *sk,const unsigned char *pk,
335+
const unsigned char *ctx,unsigned long long cs);
335336
int tweetnacl_crypto_sign_open(
336337
int *stat,
337338
unsigned char *m,unsigned long long *mlen,
338339
const unsigned char *sm,unsigned long long smlen,
340+
const unsigned char *ctx, unsigned long cs,
339341
const unsigned char *pk);
340342
int tweetnacl_crypto_sign_keypair(prng_state *prng, int wprng, unsigned char *pk,unsigned char *sk);
341343
int tweetnacl_crypto_sk_to_pk(unsigned char *pk, const unsigned char *sk);
342344
int tweetnacl_crypto_scalarmult(unsigned char *q, const unsigned char *n, const unsigned char *p);
343345
int tweetnacl_crypto_scalarmult_base(unsigned char *q,const unsigned char *n);
346+
int tweetnacl_crypto_ph(unsigned char *out, const unsigned char *msg, unsigned long msglen);
344347

345348
typedef int (*sk_to_pk)(unsigned char *pk ,const unsigned char *sk);
346349
int ec25519_import_pkcs8(const unsigned char *in, unsigned long inlen,
@@ -350,6 +353,9 @@ int ec25519_import_pkcs8(const unsigned char *in, unsigned long inlen,
350353
int ec25519_export( unsigned char *out, unsigned long *outlen,
351354
int which,
352355
const curve25519_key *key);
356+
int ec25519_crypto_ctx( unsigned char *out, unsigned long *outlen,
357+
unsigned char flag,
358+
const unsigned char *ctx, unsigned long ctxlen);
353359
#endif /* LTC_CURVE25519 */
354360

355361
#ifdef LTC_DER

src/pk/ec25519/ec25519_crypto_ctx.c

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
2+
/* SPDX-License-Identifier: Unlicense */
3+
#include "tomcrypt_private.h"
4+
5+
/**
6+
@file ec25519_crypto_ctx.c
7+
curve25519 crypto context helper
8+
*/
9+
10+
#ifdef LTC_CURVE25519
11+
12+
int ec25519_crypto_ctx(unsigned char *out, unsigned long *outlen, unsigned char flag, const unsigned char *ctx, unsigned long ctxlen)
13+
{
14+
unsigned char *buf = out;
15+
16+
const char *prefix = "SigEd25519 no Ed25519 collisions";
17+
const unsigned long prefix_len = XSTRLEN(prefix);
18+
const unsigned char ctxlen8 = (unsigned char)ctxlen;
19+
20+
if (ctxlen > 255u) return CRYPT_INPUT_TOO_LONG;
21+
if (*outlen < prefix_len + 2u + ctxlen) return CRYPT_BUFFER_OVERFLOW;
22+
23+
XMEMCPY(buf, prefix, prefix_len);
24+
buf += prefix_len;
25+
XMEMCPY(buf, &flag, 1);
26+
buf++;
27+
XMEMCPY(buf, &ctxlen8, 1);
28+
buf++;
29+
30+
if (ctxlen > 0u) {
31+
XMEMCPY(buf, ctx, ctxlen);
32+
buf += ctxlen;
33+
}
34+
35+
*outlen = buf-out;
36+
37+
return CRYPT_OK;
38+
}
39+
40+
#endif

0 commit comments

Comments
 (0)