Skip to content

Commit d664623

Browse files
committed
secp256k1: add scalar internals PoC functions (taken from secp256k1-zkp)
note that this is intentionally added to the main module (secp256k1.{h,c}) in order to keep things simple and avoid bothering with the build system source: BlockstreamResearch/secp256k1-zkp#153
1 parent 3d255df commit d664623

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/secp256k1/include/secp256k1.h

+14
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,20 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_tagged_sha256(
902902
size_t msglen
903903
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(5);
904904

905+
906+
/*****************************************************/
907+
/** INTERNALS / HAZMAT functions (proof-of-concept) **/
908+
/*****************************************************/
909+
910+
/* Caller is responsible for allocating a maximally-aligned space of size
911+
secp256k1_internals_scalar_size */
912+
typedef struct secp256k1_internals_scalar_struct secp256k1_internals_scalar;
913+
914+
SECP256K1_API size_t secp256k1_internals_scalar_size(void);
915+
SECP256K1_API void secp256k1_internals_scalar_set_b32(secp256k1_internals_scalar *r, const unsigned char *bin, int *overflow);
916+
SECP256K1_API void secp256k1_internals_scalar_get_b32(unsigned char *bin, const secp256k1_internals_scalar* a);
917+
SECP256K1_API int secp256k1_internals_scalar_add(secp256k1_internals_scalar *r, const secp256k1_internals_scalar *a, const secp256k1_internals_scalar *b);
918+
905919
#ifdef __cplusplus
906920
}
907921
#endif

src/secp256k1/src/secp256k1.c

+25
Original file line numberDiff line numberDiff line change
@@ -815,3 +815,28 @@ int secp256k1_tagged_sha256(const secp256k1_context* ctx, unsigned char *hash32,
815815
#ifdef ENABLE_MODULE_ELLSWIFT
816816
# include "modules/ellswift/main_impl.h"
817817
#endif
818+
819+
820+
/*****************************************************/
821+
/** INTERNALS / HAZMAT functions (proof-of-concept) **/
822+
/*****************************************************/
823+
824+
struct secp256k1_internals_scalar_struct {
825+
secp256k1_scalar s;
826+
};
827+
828+
size_t secp256k1_internals_scalar_size() {
829+
return sizeof(struct secp256k1_internals_scalar_struct);
830+
}
831+
832+
void secp256k1_internals_scalar_set_b32(secp256k1_internals_scalar *r, const unsigned char *bin, int *overflow) {
833+
secp256k1_scalar_set_b32(&r->s, bin, overflow);
834+
}
835+
836+
void secp256k1_internals_scalar_get_b32(unsigned char *bin, const secp256k1_internals_scalar* a) {
837+
secp256k1_scalar_get_b32(bin, &a->s);
838+
}
839+
840+
int secp256k1_internals_scalar_add(secp256k1_internals_scalar *r, const secp256k1_internals_scalar *a, const secp256k1_internals_scalar *b) {
841+
return secp256k1_scalar_add(&r->s, &a->s, &b->s);
842+
}

0 commit comments

Comments
 (0)