mpt-crypto
Confidential Multi-Purpose Tokens Cryptographic Library
Loading...
Searching...
No Matches
mpt_scalar.c
Go to the documentation of this file.
1
34
35#include "secp256k1_mpt.h"
36#include <string.h>
37#include <openssl/crypto.h>
38
39/* 1. Backend Configuration Definitions */
40#ifndef USE_SCALAR_8X32
41#define USE_SCALAR_8X32
42#endif
43#ifndef USE_FIELD_10X26
44#define USE_FIELD_10X26
45#endif
46
47/* 2. Include low-level utilities first.
48 On ARM64/Apple Silicon, the scalar math depends on 128-bit
49 integer helpers defined in these headers. */
50#include "util.h"
51#include "int128.h"
52#include "int128_impl.h"
53
54/* 3. Include the actual scalar implementations */
55#include "scalar.h"
56#include "scalar_impl.h"
57
58/* --- Implementation --- */
59
60void secp256k1_mpt_scalar_add(unsigned char *res, const unsigned char *a, const unsigned char *b) {
61 secp256k1_scalar s_res, s_a, s_b;
62 secp256k1_scalar_set_b32(&s_a, a, NULL);
63 secp256k1_scalar_set_b32(&s_b, b, NULL);
64 secp256k1_scalar_add(&s_res, &s_a, &s_b);
65 secp256k1_scalar_get_b32(res, &s_res);
66
67 /* SECURE CLEANUP */
68 OPENSSL_cleanse(&s_a, sizeof(s_a));
69 OPENSSL_cleanse(&s_b, sizeof(s_b));
70 OPENSSL_cleanse(&s_res, sizeof(s_res));
71}
72
73void secp256k1_mpt_scalar_mul(unsigned char *res, const unsigned char *a, const unsigned char *b) {
74 secp256k1_scalar s_res, s_a, s_b;
75 secp256k1_scalar_set_b32(&s_a, a, NULL);
76 secp256k1_scalar_set_b32(&s_b, b, NULL);
77 secp256k1_scalar_mul(&s_res, &s_a, &s_b);
78 secp256k1_scalar_get_b32(res, &s_res);
79
80 /* SECURE CLEANUP */
81 OPENSSL_cleanse(&s_a, sizeof(s_a));
82 OPENSSL_cleanse(&s_b, sizeof(s_b));
83 OPENSSL_cleanse(&s_res, sizeof(s_res));
84}
85
86void secp256k1_mpt_scalar_inverse(unsigned char *res, const unsigned char *in) {
87 secp256k1_scalar s;
88 secp256k1_scalar_set_b32(&s, in, NULL);
89 secp256k1_scalar_inverse(&s, &s);
90 secp256k1_scalar_get_b32(res, &s);
91
92 /* SECURE CLEANUP */
93 OPENSSL_cleanse(&s, sizeof(s));
94}
95
96void secp256k1_mpt_scalar_negate(unsigned char *res, const unsigned char *in) {
97 secp256k1_scalar s;
98 secp256k1_scalar_set_b32(&s, in, NULL);
99 secp256k1_scalar_negate(&s, &s);
100 secp256k1_scalar_get_b32(res, &s);
101
102 /* SECURE CLEANUP */
103 OPENSSL_cleanse(&s, sizeof(s));
104}
105
106void secp256k1_mpt_scalar_reduce32(unsigned char out32[32], const unsigned char in32[32]) {
107 secp256k1_scalar s;
108 secp256k1_scalar_set_b32(&s, in32, NULL);
109 secp256k1_scalar_get_b32(out32, &s);
110
111 /* SECURE CLEANUP */
112 OPENSSL_cleanse(&s, sizeof(s));
113}
void secp256k1_mpt_scalar_negate(unsigned char *res, const unsigned char *in)
Definition mpt_scalar.c:96
void secp256k1_mpt_scalar_mul(unsigned char *res, const unsigned char *a, const unsigned char *b)
Definition mpt_scalar.c:73
void secp256k1_mpt_scalar_reduce32(unsigned char out32[32], const unsigned char in32[32])
Definition mpt_scalar.c:106
void secp256k1_mpt_scalar_add(unsigned char *res, const unsigned char *a, const unsigned char *b)
Definition mpt_scalar.c:60
void secp256k1_mpt_scalar_inverse(unsigned char *res, const unsigned char *in)
Definition mpt_scalar.c:86