-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add utilities from uncompressed Bulletproofs PR
- Loading branch information
1 parent
a27160f
commit e9491da
Showing
3 changed files
with
60 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/********************************************************************** | ||
* Copyright (c) 2020 Andrew Poelstra * | ||
* Distributed under the MIT software license, see the accompanying * | ||
* file COPYING or http://www.opensource.org/licenses/mit-license.php.* | ||
**********************************************************************/ | ||
|
||
#ifndef _SECP256K1_MODULE_BULLETPROOFS_UTIL_ | ||
#define _SECP256K1_MODULE_BULLETPROOFS_UTIL_ | ||
|
||
#include "field.h" | ||
#include "group.h" | ||
#include "hash.h" | ||
|
||
/* Outputs a pair of points, amortizing the parity byte between them | ||
* Assumes both points' coordinates have been normalized. | ||
*/ | ||
static void secp256k1_bulletproofs_serialize_points(unsigned char *output, const secp256k1_ge *lpt, const secp256k1_ge *rpt) { | ||
output[0] = (secp256k1_fe_is_odd(&lpt->y) << 1) + secp256k1_fe_is_odd(&rpt->y); | ||
secp256k1_fe_get_b32(&output[1], &lpt->x); | ||
secp256k1_fe_get_b32(&output[33], &rpt->x); | ||
} | ||
|
||
/* Initializes SHA256 with fixed midstate. This midstate was computed by applying | ||
* SHA256 to SHA256("Bulletproofs/commitment")||SHA256("Bulletproofs/commitment"). */ | ||
static void secp256k1_bulletproofs_sha256_tagged_commitment(secp256k1_sha256 *sha) { | ||
secp256k1_sha256_initialize(sha); | ||
sha->s[0] = 0x50b6a879ul; | ||
sha->s[1] = 0x0d9a7470ul; | ||
sha->s[2] = 0xb4400e54ul; | ||
sha->s[3] = 0x32d29ac7ul; | ||
sha->s[4] = 0xde938408ul; | ||
sha->s[5] = 0x923fc797ul; | ||
sha->s[6] = 0x29f973a6ul; | ||
sha->s[7] = 0xa25e1a1cul; | ||
|
||
sha->bytes = 64; | ||
} | ||
|
||
/* little-endian encodes a uint64 */ | ||
static void secp256k1_bulletproofs_le64(unsigned char *output, const uint64_t n) { | ||
output[0] = n; | ||
output[1] = n >> 8; | ||
output[2] = n >> 16; | ||
output[3] = n >> 24; | ||
output[4] = n >> 32; | ||
output[5] = n >> 40; | ||
output[6] = n >> 48; | ||
output[7] = n >> 56; | ||
} | ||
|
||
#endif |
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