mirror of https://github.com/hashcat/hashcat.git
parent
52e83c2292
commit
d07f002337
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Author......: See docs/credits.txt
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
#ifndef _INC_ECC_SECP256K1_H
|
||||
#define _INC_ECC_SECP256K1_H
|
||||
|
||||
// y^2 = x^3 + ax + b with a = 0 and b = 7 => y^2 = x^3 + 7:
|
||||
|
||||
#define SECP256K1_B 7
|
||||
|
||||
#define SECP256K1_P0 0xfffffc2f
|
||||
#define SECP256K1_P1 0xfffffffe
|
||||
#define SECP256K1_P2 0xffffffff
|
||||
#define SECP256K1_P3 0xffffffff
|
||||
#define SECP256K1_P4 0xffffffff
|
||||
#define SECP256K1_P5 0xffffffff
|
||||
#define SECP256K1_P6 0xffffffff
|
||||
#define SECP256K1_P7 0xffffffff
|
||||
|
||||
#define SECP256K1_N0 0xd0364141
|
||||
#define SECP256K1_N1 0xbfd25e8c
|
||||
#define SECP256K1_N2 0xaf48a03b
|
||||
#define SECP256K1_N3 0xbaaedce6
|
||||
#define SECP256K1_N4 0xfffffffe
|
||||
#define SECP256K1_N5 0xffffffff
|
||||
#define SECP256K1_N6 0xffffffff
|
||||
#define SECP256K1_N7 0xffffffff
|
||||
|
||||
typedef struct secp256k1
|
||||
{
|
||||
u32 xy[48]; // all 3 pairs of 32+32 bytes: x,y, x1,y1, x2,y2
|
||||
|
||||
} secp256k1_t;
|
||||
|
||||
DECLSPEC u32 parse_public (secp256k1_t *r, const u32 k[9]);
|
||||
DECLSPEC void point_mul (u32 *r, const u32 k[8], GLOBAL_AS const secp256k1_t *tmps);
|
||||
|
||||
#endif // _INC_ECC_SECP256K1_H
|
@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Author......: See docs/credits.txt
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
#ifndef _EMU_INC_ECC_SECP256K1_H
|
||||
#define _EMU_INC_ECC_SECP256K1_H
|
||||
|
||||
#include "emu_general.h"
|
||||
|
||||
#include "inc_vendor.h"
|
||||
#include "inc_ecc_secp256k1.h"
|
||||
|
||||
#endif // _EMU_INC_ECC_SECP256K1_H
|
@ -1,13 +0,0 @@
|
||||
/**
|
||||
* Author......: See docs/credits.txt
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
#ifndef _EXT_SECP256K1_H
|
||||
|
||||
#include "secp256k1.h"
|
||||
|
||||
bool hc_secp256k1_pubkey_parse (secp256k1_pubkey *pubkey, u8 *buf, size_t length);
|
||||
bool hc_secp256k1_pubkey_tweak_mul (secp256k1_pubkey *pubkey, u8 *buf, size_t length);
|
||||
|
||||
#endif // _EXT_SECP256K1_H
|
@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Author......: See docs/credits.txt
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
#include "types.h"
|
||||
#include "common.h"
|
||||
#include "emu_general.h"
|
||||
|
||||
#include "inc_vendor.h"
|
||||
#include "inc_platform.h"
|
||||
#include "inc_ecc_secp256k1.cl"
|
||||
|
@ -1,151 +0,0 @@
|
||||
/**
|
||||
* Author......: See docs/credits.txt
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
#include "types.h"
|
||||
#include "common.h"
|
||||
|
||||
#include "ext_secp256k1.h"
|
||||
|
||||
|
||||
#if !defined (WITH_LIBSECP256K1)
|
||||
|
||||
// some macros needed for secp256k1 header and source code includes:
|
||||
|
||||
// is this a good 64-bit support check ?
|
||||
#if !defined (__LP64__) && !defined (_WIN64) && !defined (__x86_64__)
|
||||
|
||||
#define USE_SCALAR_8X32
|
||||
#define USE_FIELD_10X26
|
||||
|
||||
#else
|
||||
|
||||
#define HAVE___INT128
|
||||
#define USE_ASM_X86_64
|
||||
// doesn't change speed much: #define USE_ECMULT_STATIC_PRECOMPUTATION
|
||||
|
||||
#define USE_SCALAR_4X64
|
||||
#define USE_FIELD_5X52
|
||||
|
||||
#endif
|
||||
|
||||
#define USE_SCALAR_INV_BUILTIN
|
||||
#define USE_FIELD_INV_BUILTIN
|
||||
|
||||
#define ECMULT_WINDOW_SIZE 15
|
||||
#define ECMULT_GEN_PREC_BITS 4
|
||||
|
||||
#define USE_NUM_NONE
|
||||
|
||||
#include "secp256k1.c"
|
||||
|
||||
#endif
|
||||
|
||||
bool hc_secp256k1_pubkey_parse (secp256k1_pubkey *pubkey, u8 *buf, size_t length)
|
||||
{
|
||||
secp256k1_context *t_ctx = secp256k1_context_create (SECP256K1_CONTEXT_NONE);
|
||||
|
||||
if (secp256k1_ec_pubkey_parse (t_ctx, pubkey, buf, length) == 0)
|
||||
{
|
||||
secp256k1_context_destroy (t_ctx);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
secp256k1_context_destroy (t_ctx);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool hc_secp256k1_pubkey_tweak_mul (secp256k1_pubkey *pubkey, u8 *buf, size_t length)
|
||||
{
|
||||
#if !defined (WITH_LIBSECP256K1)
|
||||
|
||||
secp256k1_context *sctx = secp256k1_context_create (SECP256K1_CONTEXT_NONE);
|
||||
|
||||
secp256k1_gej res;
|
||||
secp256k1_ge pt;
|
||||
|
||||
// load the public key and 32 byte scalar:
|
||||
|
||||
secp256k1_pubkey_load (sctx, &pt, pubkey);
|
||||
|
||||
int overflow = 0;
|
||||
|
||||
secp256k1_scalar s;
|
||||
|
||||
secp256k1_scalar_set_b32 (&s, buf, &overflow);
|
||||
|
||||
if (overflow != 0)
|
||||
{
|
||||
secp256k1_scalar_clear (&s);
|
||||
|
||||
secp256k1_context_destroy (sctx);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (secp256k1_scalar_is_zero (&s))
|
||||
{
|
||||
secp256k1_scalar_clear (&s);
|
||||
|
||||
secp256k1_context_destroy (sctx);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// main multiply operation:
|
||||
|
||||
const size_t scalar_size = (length - 1) * 8;
|
||||
|
||||
secp256k1_ecmult_const (&res, &pt, &s, scalar_size);
|
||||
secp256k1_ge_set_gej (&pt, &res);
|
||||
secp256k1_fe_normalize (&pt.x);
|
||||
secp256k1_fe_normalize (&pt.y);
|
||||
|
||||
|
||||
// output:
|
||||
|
||||
buf[0] = 0x02 | secp256k1_fe_is_odd (&pt.y);
|
||||
|
||||
secp256k1_fe_get_b32 (buf + 1, &pt.x);
|
||||
|
||||
|
||||
// cleanup:
|
||||
|
||||
secp256k1_scalar_clear (&s);
|
||||
|
||||
secp256k1_context_destroy (sctx);
|
||||
|
||||
#else
|
||||
|
||||
// ATTENTION: this way to multiply was much slower in our tests
|
||||
|
||||
secp256k1_context *sctx = secp256k1_context_create (SECP256K1_CONTEXT_VERIFY);
|
||||
|
||||
|
||||
// main multiply operation:
|
||||
|
||||
if (secp256k1_ec_pubkey_tweak_mul (sctx, pubkey, buf) == 0)
|
||||
{
|
||||
secp256k1_context_destroy (sctx);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// output:
|
||||
|
||||
secp256k1_ec_pubkey_serialize (sctx, buf, &length, pubkey, SECP256K1_EC_COMPRESSED);
|
||||
|
||||
|
||||
// cleanup:
|
||||
|
||||
secp256k1_context_destroy (sctx);
|
||||
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
Loading…
Reference in new issue