Skip to content

Commit

Permalink
2023-11-20 17:14 UTC+0100 Aleksander Czajczynski (hb fki.pl)
Browse files Browse the repository at this point in the history
  * contrib/hbcrypto/hbcrypto.hbp
    * fix hbmk2's .hbx specifier after merge by Eric Lendvai
  * ChangeLog.txt
    * merged in hbcrypto related log entries from Harbour 3.4
  * src/rtl/sha1.c
  * src/rtl/sha1.h
  * src/rtl/sha1hmac.c
  * src/rtl/sha1hmac.h
  * src/rtl/hbsha1.c
  * src/rtl/hbsha1hm.c
    * merged SHA1 cleanups from Harbour 3.4, many thanks Viktor

2023-11-20 08:14 UTC-0800 Eric Lendvai (eric/at/lendvai.us)
  + contrib/hbcrypto/*
  * contrib/hbplist.txt
  * contrib/hbrun/hbrun.hbp
  * include/Makefile
  * include/hbcrypto.h
  * include/hbdefs.h
  * package/harbour.spec
  * src/rtl/sha2.c
  * src/rtl/sha2hmac.c
  * src/rtl/hbsha2hm.c
  * src/rtl/hbsha2.c
    + incorporated contrib/hbcrypto from Viktor Szakats repo

2017-10-06 16:11 UTC Viktor Szakats (vszakats users.noreply.github.com)
  * contrib/hbcrypto/3rd/ed25519/ed25519.hbp
  + contrib/hbcrypto/3rd/ed25519/add_scalar.c
    + sync public API with upstream

2017-05-15 15:28 UTC Viktor Szakats (vszakats users.noreply.github.com)
  * contrib/hbcrypto/3rd/scrypt/_compat.h
    ! fix to define `SIZE_MAX`. Required in certain Linux environments
      Thanks to Aleksander Czajczynski for the patch.

  * contrib/hbcrypto/hbcrypto.hbp
  * contrib/rddads/rddads.hbp
    ! respect `HB_BUILD_3RDEXT=no`

2017-04-08 00:01 UTC Viktor Szakats (vszakats users.noreply.github.com)
  * contrib/hbcrypto/sha3.c
    * silence 64-bit msvc warnings
    ! fix parameter size for 64-bit Windows

  * src/rtl/sha1.c
    ! fix 64-bit msvc warning

2017-02-19 21:20 UTC Viktor Szakats (vszakats users.noreply.github.com)
  * contrib/hbcrypto/3rd/scrypt/crypto_scrypt.h
  * contrib/hbcrypto/3rd/scrypt/scrypt.diff
    ! fix another C99 issue. Thanks to Alex Strickland.
      Ref:
https://github.com/vszakats/hb/issues/270#issuecomment-280947348

2017-03-21 18:25 UTC Viktor Szakats (vszakats users.noreply.github.com)
  * contrib/hbcrypto/3rd/ed25519/ed25519.diff
  * contrib/hbcrypto/3rd/ed25519/ed25519.hbp
  * contrib/hbcrypto/3rd/ed25519/ge.c
  * contrib/hbcrypto/3rd/ed25519/key_exch.c ->
contrib/hbcrypto/3rd/ed25519/key_exchange.c
  * contrib/hbcrypto/3rd/ed25519/LICENSE.txt ->
contrib/hbcrypto/3rd/ed25519/license.txt
  * contrib/hbcrypto/3rd/ed25519/precompd.h ->
contrib/hbcrypto/3rd/ed25519/precomp_data.h
    * use original (non-short) filenames
      to reduce local differences of vendored code

2017-02-19 17:38 UTC Viktor Szakats (vszakats users.noreply.github.com)
  * contrib/hbcrypto/3rd/scrypt/insecure_memzero.c
  * contrib/hbcrypto/3rd/scrypt/scrypt.diff
  * contrib/hbcrypto/3rd/scrypt/sha256.c
  * contrib/hbcrypto/3rd/scrypt/sha256.h
  + contrib/hbcrypto/3rd/scrypt/_compat.h
    ! rework patch to make old MSVC versions (MSVC 2008) happy,
      fixing another instance of C99-ism.
      My last effort into this, from this point I'd like to kindly
      ask for patches to support this compiler.

2017-02-19 14:18 UTC Viktor Szakats (vszakats users.noreply.github.com)
  * contrib/hbcrypto/3rd/scrypt/insecure_memzero.c
  * contrib/hbcrypto/3rd/scrypt/insecure_memzero.h
  * contrib/hbcrypto/3rd/scrypt/scrypt.diff
  * contrib/hbcrypto/3rd/scrypt/sha256.c
    ! avoid another C99 #include <stdint.h>
    ! replace 'inline' with _HB_INLINE_ and
      make sure to #include "hbdef.h" before it.
      Ref:
https://github.com/vszakats/hb/issues/270#issuecomment-280918348

2017-02-17 12:52 UTC Viktor Szakats (vszakats users.noreply.github.com)
  * include/hbdefs.h
    + add HB_C99_STATIC and HB_C99_RESTRICT type qualifiers
      currently enabled for gcc/clang family

  * contrib/hbcrypto/3rd/scrypt/scrypt.diff
  * contrib/hbcrypto/3rd/scrypt/sha256.c
    % restore C99 static/restrict qualifiers on compilers that support
it

2017-02-17 12:24 UTC Viktor Szakats (vszakats users.noreply.github.com)
  * contrib/hbcrypto/3rd/scrypt/crypto_scrypt.h
    * cleanup

  * contrib/hbcrypto/3rd/scrypt/scrypt.diff
  * contrib/hbcrypto/3rd/scrypt/sha256.c
  * contrib/hbcrypto/3rd/scrypt/sha256.h
  * contrib/hbcrypto/hbcrypto.hbp
    + make sha256.{c,h} compatible with C compilers not supporting C99
      (untested though)
      Ref:
https://github.com/vszakats/hb/issues/270#issuecomment-280623411

2017-02-13 12:34 UTC Viktor Szakats (vszakats users.noreply.github.com)
  * contrib/hbcrypto/3rd/scrypt/scrypt.diff
  * contrib/hbcrypto/3rd/scrypt/scrypt.hbp
  * contrib/hbcrypto/3rd/scrypt/sha256.c
  + contrib/hbcrypto/3rd/scrypt/config.h
  + contrib/hbcrypto/3rd/scrypt/insecure_memzero.c
  + contrib/hbcrypto/3rd/scrypt/insecure_memzero.h
  * contrib/hbcrypto/3rd/scrypt/c_scrypt.h ->
contrib/hbcrypto/3rd/scrypt/crypto_scrypt.h
  * contrib/hbcrypto/3rd/scrypt/c_scrypt.c ->
contrib/hbcrypto/3rd/scrypt/crypto_scrypt-ref.c
    * update to scrypt 1.2.1 (from 1.1.6)
    * restore to use its own implementation of SHA256 and HMAC-SHA256
      This makes patch smaller, final binaries somewhat smaller, but
      this appears to be a more polished SHA256 implementation than
      core one. WARNING: C build fallouts possible.
    * use original filenames

  * contrib/hbcrypto/hbcrypto.hbp
    * use original scrypt public header filename in dependency
detection.
      This makes envvar HB_WITH_SCRYPT actually useful to point to
      non-vendored scrypt package.

2017-01-31 15:07 UTC Viktor Szakats (vszakats users.noreply.github.com)
  * contrib/hbrun/hbrun.hbp
    + link hbcrypto lib by default

2016-08-19 13:17 UTC+0200 Viktor Szakats (vszakats
users.noreply.github.com)
  * contrib/hbcrypto/tests/pbkdf2.prg
  * contrib/hbcrypto/tests/scrypt.prg
    * update/add finalized RFC for test vectors

2016-01-20 12:20 UTC+0100 Viktor Szakats (vszakats users.noreply.github.com)
  * contrib/hbcrypto/3rd/ed25519/ed25519.dif
  * contrib/hbcrypto/3rd/ed25519/fixedint.h
    ! fix (hopefully) for msvc 2010 and above builds
      Closes https://github.com/vszakats/hb/issues/170
      Tests:
         MSVC 2015:
https://ci.appveyor.com/project/vszakats/hb/build/3.4.1004
         MSVC 2013:
https://ci.appveyor.com/project/vszakats/hb/build/3.4.1005
    * remove old fix attempt

  * contrib/hbcrypto/hbcrypto.hbp
    + reenable for msvc

2015-08-27 22:05 UTC+0200 Viktor Szakats (vszakats users.noreply.github.com)
  * contrib/hbcrypto/3rd/ed25519/ed25519.dif
  * contrib/hbcrypto/3rd/ed25519/fixedint.h
    ! fix build error with MSVC 2010. This compiler offers <stdint.h>
      but it seems to miss type 'int32_t' anyway. This is a hack to
      address this specific problem, it may need further updates
      to form a general solution.
      Fixes https://github.com/vszakats/hb/issues/158

2015-08-24 19:05 UTC+0200 Viktor Szakats (vszakats users.noreply.github.com)
  * contrib/hbcrypto/3rd/scrypt/c_scrypt.c
  * contrib/hbcrypto/3rd/scrypt/scrypt.dif
    * eliminate reliance on 'errno' making this code
      more portable (to wce e.g.)
      Fixes https://github.com/vszakats/hb/issues/156

2015-08-20 03:07 UTC+0200 Viktor Szakats (vszakats users.noreply.github.com)
  + contrib/hbcrypto/sha3.c
  * contrib/hbcrypto/hbcrypto.hbp
  * contrib/hbcrypto/hbcrypto.hbx
  + contrib/hbcrypto/tests/sha3.prg
    + add SHA3 functions:
      hb_SHA3224( <cData>, [<lBinary=.F.>] ) -> <cHash>
      hb_SHA3256( <cData>, [<lBinary=.F.>] ) -> <cHash>
      hb_SHA3384( <cData>, [<lBinary=.F.>] ) -> <cHash>
      hb_SHA3512( <cData>, [<lBinary=.F.>] ) -> <cHash>
      hb_SHAKE128( <cData>, [<nHashBytes=32>], [<lBinary=.F.> ] ) ->
<cHash>
      hb_SHAKE256( <cData>, [<nHashBytes=64>], [<lBinary=.F.> ] ) ->
<cHash>

2015-08-08 14:50 UTC+0200 Viktor Szakats (vszakats users.noreply.github.com)
  * contrib/hbcrypto/3rd/ed25519/ed25519.dif
  * contrib/hbcrypto/3rd/ed25519/fixedint.h
    ! silence msvc64 (msvs 2015) redefinition warnings

  * contrib/hbcrypto/blake2s.c
    ! silence msvc64 warnings:
      warning C4244: '+=': conversion from 'HB_SIZE' to 'HB_U32',
possible loss of data

2015-08-08 13:48 UTC+0200 Viktor Szakats (vszakats users.noreply.github.com)
  * contrib/hbcrypto/scrypt.c
    ! fix extern declarations when built in C++ mode

  * contrib/hbcrypto/3rd/ed25519/ed25519.dif
  * contrib/hbcrypto/3rd/ed25519/fe.c
    ! fix msvc64 warning:
      warning C4146: unary minus operator applied to unsigned type,
result still unsigned

  * contrib/hbcrypto/bcrypt.c
    ! fix msvc64 warnings:
      warning C4267: 'argument': conversion from 'size_t' to 'HB_U16',
possible loss of data

  * src/rtl/sha1.c
    * silence msvc warning:
      conversion from 'HB_SIZE' to 'sha1_quadbyte', possible loss of
data

2015-07-23 11:32 UTC+0200 Viktor Szakats (vszakats users.noreply.github.com)
  * contrib/hbcrypto/bcrypt.c
    * silence msvc warning
      Closes https://github.com/vszakats/hb/issues/145

2015-07-19 15:15 UTC+0200 Viktor Szakats (vszakats users.noreply.github.com)
  - contrib/hbcrypto/3rd/scrypt/sha256.h
  * contrib/hbcrypto/3rd/scrypt/c_scrypt.c
  * contrib/hbcrypto/3rd/scrypt/c_scrypt.h
  * contrib/hbcrypto/3rd/scrypt/scrypt.dif
  * contrib/hbcrypto/3rd/scrypt/scrypt.hbp
  * contrib/hbcrypto/3rd/scrypt/sha256.c
  * contrib/hbcrypto/hbcrypto.hbp
  * contrib/hbcrypto/pbkdf2.c
    * use more Harbour types for better portability
    * enable the contrib for all platforms

  * contrib/hbcrypto/3rd/ed25519/ed25519.dif
  * contrib/hbcrypto/3rd/ed25519/precompd.h
  * contrib/hbcrypto/3rd/ed25519/sc.h
    * add ending newlines to silence watcom warning

2015-07-17 21:31 UTC+0200 Viktor Szakats (vszakats users.noreply.github.com)
  * contrib/hbcrypto/hbcrypto.hbp
  * contrib/hbcrypto/hbcrypto.hbx
  + contrib/hbcrypto/scryptcf.prg
    + add helper function:
        hb_scrypt_setup( <nOpsLimit>, <nMemLimit>, @<N>, @<r>, @<p> ) ->
NIL

2015-07-17 01:22 UTC+0200 Viktor Szakats (vszakats users.noreply.github.com)
  * contrib/hbcrypto/3rd/ed25519/ed25519.h
  * contrib/hbcrypto/3rd/ed25519/sign.c
    + add function ed25519_get_pubkey()
      Related Issue: orlp/ed25519#1
      Related PR: orlp/ed25519#5

  * contrib/hbcrypto/ed25519.c
  * contrib/hbcrypto/hbcrypto.hbx
  * contrib/hbcrypto/tests/ed25519.prg
    + add wrapper HB_ED25519_GET_PUBKEY() to derive
      public key from secret key
    * modify HB_ED25519_SIGN() and HB_ED25519_KEY_EXCHANGE()
      to return value directly (was: by reference)

  * contrib/hbcrypto/bcrypt.c
    * cleanups

2015-07-16 20:12 UTC+0200 Viktor Szakats (vszakats users.noreply.github.com)
  + contrib/hbcrypto/bcrypt.c
  * contrib/hbcrypto/hbcrypto.hbp
  * contrib/hbcrypto/hbcrypto.hbx
  + contrib/hbcrypto/tests/bcrypt.prg
    + add new secure hash function:
         hb_bcrypt( <cPassword>, <cSalt>, <nRounds>, <nKeyLen> ) ->
<cKey>
      Useful for interoparibility, other than that hb_scrypt()
      is superior. See inside for code authors and licenses.
      TODO: deduplicate Blowfish code against core

  * contrib/hbcrypto/scrypt.c
    * minor

2015-07-16 02:06 UTC+0200 Viktor Szakats (vszakats users.noreply.github.com)
  * contrib/hbcrypto/blake2b.c
  * contrib/hbcrypto/blake2s.c
    ! fix HB_BLAKE2*() to return correct length when
      passing a 3rd length parameter and passing .T. as 4th

2015-07-15 13:12 UTC+0200 Viktor Szakats (vszakats users.noreply.github.com)
  - contrib/hbcrypto/3rd/scrypt/config.h
  - contrib/hbcrypto/3rd/scrypt/scrypt_p.h
  - contrib/hbcrypto/3rd/scrypt/u_sysend.h
  * contrib/hbcrypto/3rd/scrypt/c_scrypt.c
  * contrib/hbcrypto/3rd/scrypt/scrypt.dif
  * contrib/hbcrypto/3rd/scrypt/scrypt.hbp
  * contrib/hbcrypto/3rd/scrypt/sha256.c
  * contrib/hbcrypto/hbcrypto.hbp
    * rely more on Harbour macros and drop
      redundant code

  * contrib/hbcrypto/pbkdf2.c
    ! do not strip 'const'

  + contrib/hbcrypto/tests/pbkdf2.prg
  * contrib/hbcrypto/tests/scrypt.prg
    * split into two

2015-07-14 00:23 UTC+0200 Viktor Szakats (vszakats users.noreply.github.com)
  * contrib/hbcrypto/3rd/scrypt/scrypt.dif
  * contrib/hbcrypto/3rd/scrypt/sha256.c
  * contrib/hbcrypto/3rd/scrypt/sha256.h
    % use core SHA256/HMAC implementations instead
      of local duplicates

  * src/rtl/hbsha2.c
  * src/rtl/hbsha2hm.c
    * minor cleanups

2015-07-13 23:54 UTC+0200 Viktor Szakats (vszakats users.noreply.github.com)
  * contrib/hbcrypto/ed25519.c
  * contrib/hbcrypto/hbcrypto.hbp
  * contrib/hbcrypto/hbcrypto.hbx
  * contrib/hbcrypto/tests/ed25519.prg
    * finalizing ed25519 functions

2015-07-13 23:47 UTC+0200 Viktor Szakats (vszakats users.noreply.github.com)
  + contrib/hbcrypto/3rd/ed25519
  + contrib/hbcrypto/ed25519.c
  + contrib/hbcrypto/tests/ed25519.prg
    + add ed25519 public-key signature functionality
         https://ed25519.cr.yp.to
      uses low-level code from:
         https://github.com/orlp/ed25519

  * contrib/hbcrypto
    * merge hbblake2 into hbcrypto

2015-07-13 23:12 UTC+0200 Viktor Szakats (vszakats users.noreply.github.com)
  * include/hbcrypto.h
  * src/rtl/hbsha1.c
  * src/rtl/hbsha1hm.c
  * src/rtl/hbsha2.c
  * src/rtl/hbsha2hm.c
  * src/rtl/sha1.c
  * src/rtl/sha1.h
  * src/rtl/sha1hmac.c
  * src/rtl/sha1hmac.h
  * src/rtl/sha2.c
  * src/rtl/sha2hmac.c
    + use Harbour index type in low-level SHA code
    % drop high-level hack compensating for fixed sized
      low-level indexes in 64-bit builds
    ! fix an unused variable in conditional code
    ! fix a wrong header reference after prev updates

2015-07-13 19:39 UTC+0200 Viktor Szakats (vszakats users.noreply.github.com)
  + include/hbcrypto.h
  * include/Makefile
  * src/rtl/sha2.c
  * src/rtl/sha2hmac.c
    + move sha2 and hmac/sha2 related headers to Harbour
      header directory so they can be used by other components.
    + export sha2 and hmac/sha2 low-level functions from Harbour dynlib
    % use HB_ULL() macro instead of local replica in sha2.c
    % drop unused #include <strings.h> from sha2.c and sha2hmac.c

2013-11-26 00:51 UTC+0100 Viktor Szakats (vszakats users.noreply.github.com)
  + contrib/hbcrypto/3rd/scrypt/*
  + contrib/hbcrypto/3rd/scrypt/scrypt.dif
  + contrib/hbcrypto/3rd/scrypt/scrypt.hbc
  + contrib/hbcrypto/3rd/scrypt/scrypt.hbp
    + added 3rd party code from:
         https://www.tarsnap.com/scrypt/
      The work of Colin Percival, implementing safe password
      hashing function scrypt and PBKDF2 which it depends on.
      Plus Harbour build glue and patches to work with some
      other compilers than gcc and better work with Harbour.

  * contrib/hbplist.txt
  + contrib/hbcrypto/pbkdf2.c
  + contrib/hbcrypto/scrypt.c
  + contrib/hbcrypto/strcmpc.c
  + contrib/hbcrypto/tests/hbmk.hbm
  + contrib/hbcrypto/tests/test.prg
    + added hbcrypto package implementing following password
      hashing wrapper functions:
         hb_scrypt( <cPassword>, <cSalt>, <nCPU>, <nMem>, <nParallel>,
<nKeyLen> ) -> <cKey>
         hb_pbkdf2_sha256( <cPassword>, <cSalt>, <nCount>, <nKeyLen> )
-> <cKey>
    + added function for length-constant time string comparison:
         hb_strcmpc( <cString1>, <cString2> ) -> <lEqual>
  • Loading branch information
vszakats authored and EricLendvai committed Nov 20, 2023
1 parent 0000838 commit 37b742a
Show file tree
Hide file tree
Showing 67 changed files with 9,802 additions and 644 deletions.
355 changes: 355 additions & 0 deletions ChangeLog.txt

Large diffs are not rendered by default.

69 changes: 69 additions & 0 deletions contrib/hbcrypto/3rd/ed25519/add_scalar.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include "ed25519.h"
#include "ge.h"
#include "sc.h"
#include "sha512.h"


/* see http://crypto.stackexchange.com/a/6215/4697 */
void ed25519_add_scalar(unsigned char *public_key, unsigned char *private_key, const unsigned char *scalar) {
const unsigned char SC_1[32] = {1}; /* scalar with value 1 */

unsigned char n[32];
ge_p3 nB;
ge_p1p1 A_p1p1;
ge_p3 A;
ge_p3 public_key_unpacked;
ge_cached T;

sha512_context hash;
unsigned char hashbuf[64];

int i;

/* copy the scalar and clear highest bit */
for (i = 0; i < 31; ++i) {
n[i] = scalar[i];
}
n[31] = scalar[31] & 127;

/* private key: a = n + t */
if (private_key) {
sc_muladd(private_key, SC_1, n, private_key);

// https://github.com/orlp/ed25519/issues/3
sha512_init(&hash);
sha512_update(&hash, private_key + 32, 32);
sha512_update(&hash, scalar, 32);
sha512_final(&hash, hashbuf);
for (i = 0; i < 32; ++i) {
private_key[32 + i] = hashbuf[i];
}
}

/* public key: A = nB + T */
if (public_key) {
/* if we know the private key we don't need a point addition, which is faster */
/* using a "timing attack" you could find out wether or not we know the private
key, but this information seems rather useless - if this is important pass
public_key and private_key seperately in 2 function calls */
if (private_key) {
ge_scalarmult_base(&A, private_key);
} else {
/* unpack public key into T */
ge_frombytes_negate_vartime(&public_key_unpacked, public_key);
fe_neg(public_key_unpacked.X, public_key_unpacked.X); /* undo negate */
fe_neg(public_key_unpacked.T, public_key_unpacked.T); /* undo negate */
ge_p3_to_cached(&T, &public_key_unpacked);

/* calculate n*B */
ge_scalarmult_base(&nB, n);

/* A = n*B + T */
ge_add(&A_p1p1, &nB, &T);
ge_p1p1_to_p3(&A, &A_p1p1);
}

/* pack public key */
ge_p3_tobytes(public_key, &A);
}
}
97 changes: 97 additions & 0 deletions contrib/hbcrypto/3rd/ed25519/ed25519.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
diff --strip-trailing-cr -urN ed25519.orig/ed25519.h ed25519/ed25519.h
--- ed25519.orig/ed25519.h 2017-02-10 19:47:44.000000000 +0000
+++ ed25519/ed25519.h 2022-06-30 12:06:22.000000000 +0000
@@ -25,7 +25,8 @@
#endif

void ED25519_DECLSPEC ed25519_create_keypair(unsigned char *public_key, unsigned char *private_key, const unsigned char *seed);
-void ED25519_DECLSPEC ed25519_sign(unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *public_key, const unsigned char *private_key);
+void ED25519_DECLSPEC ed25519_get_pubkey(unsigned char *public_key, const unsigned char *private_key);
+void ED25519_DECLSPEC ed25519_sign(unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *unused, const unsigned char *private_key);
int ED25519_DECLSPEC ed25519_verify(const unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *public_key);
void ED25519_DECLSPEC ed25519_add_scalar(unsigned char *public_key, unsigned char *private_key, const unsigned char *scalar);
void ED25519_DECLSPEC ed25519_key_exchange(unsigned char *shared_secret, const unsigned char *public_key, const unsigned char *private_key);
diff --strip-trailing-cr -urN ed25519.orig/fixedint.h ed25519/fixedint.h
--- ed25519.orig/fixedint.h 2017-02-10 19:47:44.000000000 +0000
+++ ed25519/fixedint.h 2022-06-30 12:06:22.000000000 +0000
@@ -4,7 +4,7 @@
Not a compatible replacement for <stdint.h>, do not blindly use it as such.
*/

-#if ((defined(__STDC__) && __STDC__ && __STDC_VERSION__ >= 199901L) || (defined(__WATCOMC__) && (defined(_STDINT_H_INCLUDED) || __WATCOMC__ >= 1250)) || (defined(__GNUC__) && (defined(_STDINT_H) || defined(_STDINT_H_) || defined(__UINT_FAST64_TYPE__)) )) && !defined(FIXEDINT_H_INCLUDED)
+#if ((defined(__STDC__) && __STDC__ && __STDC_VERSION__ >= 199901L) || (defined(_MSC_VER) && _MSC_VER >= 1600) || (defined(__WATCOMC__) && (defined(_STDINT_H_INCLUDED) || __WATCOMC__ >= 1250)) || (defined(__GNUC__) && (defined(_STDINT_H) || defined(_STDINT_H_) || defined(__UINT_FAST64_TYPE__)) )) && !defined(FIXEDINT_H_INCLUDED)
#include <stdint.h>
#define FIXEDINT_H_INCLUDED

@@ -66,7 +66,11 @@
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;

+ #ifndef UINT64_C
#define UINT64_C(v) v ##UI64
+ #endif
+ #ifndef INT64_C
#define INT64_C(v) v ##I64
+ #endif
#endif
#endif
diff --strip-trailing-cr -urN ed25519.orig/sha512.h ed25519/sha512.h
--- ed25519.orig/sha512.h 2017-02-10 19:47:44.000000000 +0000
+++ ed25519/sha512.h 2022-06-30 12:06:22.000000000 +0000
@@ -1,11 +1,20 @@
#ifndef SHA512_H
#define SHA512_H

-#include <stddef.h>
+#include "hbdefs.h"

#include "fixedint.h"

/* state */
+#if defined( HB_USE_CORE_SHA512 )
+# include "hbcrypto.h"
+# define sha512_context hb_sha512_ctx
+# define sha512_init hb_sha512_init
+# define sha512_final hb_sha512_final
+# define sha512_update hb_sha512_update
+# define sha512 hb_sha512
+#else
+# define uint64_t HB_U64
typedef struct sha512_context_ {
uint64_t length, state[8];
size_t curlen;
@@ -17,5 +26,6 @@
int sha512_final(sha512_context * md, unsigned char *out);
int sha512_update(sha512_context * md, const unsigned char *in, size_t inlen);
int sha512(const unsigned char *message, size_t message_len, unsigned char *out);
+#endif

#endif
diff --strip-trailing-cr -urN ed25519.orig/sign.c ed25519/sign.c
--- ed25519.orig/sign.c 2017-02-10 19:47:44.000000000 +0000
+++ ed25519/sign.c 2022-06-30 12:06:22.000000000 +0000
@@ -3,13 +3,23 @@
#include "ge.h"
#include "sc.h"

+void ed25519_get_pubkey(unsigned char *public_key, const unsigned char *private_key) {
+ ge_p3 A;

-void ed25519_sign(unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *public_key, const unsigned char *private_key) {
+ ge_scalarmult_base(&A, private_key);
+ ge_p3_tobytes(public_key, &A);
+}
+
+void ed25519_sign(unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *unused, const unsigned char *private_key) {
sha512_context hash;
unsigned char hram[64];
unsigned char r[64];
ge_p3 R;
+ unsigned char public_key[ 32 ];
+
+ (void)unused;

+ ed25519_get_pubkey(public_key, private_key);

sha512_init(&hash);
sha512_update(&hash, private_key + 32, 32);
39 changes: 39 additions & 0 deletions contrib/hbcrypto/3rd/ed25519/ed25519.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef ED25519_H
#define ED25519_H

#include <stddef.h>

#if defined(_WIN32)
#if defined(ED25519_BUILD_DLL)
#define ED25519_DECLSPEC __declspec(dllexport)
#elif defined(ED25519_DLL)
#define ED25519_DECLSPEC __declspec(dllimport)
#else
#define ED25519_DECLSPEC
#endif
#else
#define ED25519_DECLSPEC
#endif


#ifdef __cplusplus
extern "C" {
#endif

#ifndef ED25519_NO_SEED
int ED25519_DECLSPEC ed25519_create_seed(unsigned char *seed);
#endif

void ED25519_DECLSPEC ed25519_create_keypair(unsigned char *public_key, unsigned char *private_key, const unsigned char *seed);
void ED25519_DECLSPEC ed25519_get_pubkey(unsigned char *public_key, const unsigned char *private_key);
void ED25519_DECLSPEC ed25519_sign(unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *unused, const unsigned char *private_key);
int ED25519_DECLSPEC ed25519_verify(const unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *public_key);
void ED25519_DECLSPEC ed25519_add_scalar(unsigned char *public_key, unsigned char *private_key, const unsigned char *scalar);
void ED25519_DECLSPEC ed25519_key_exchange(unsigned char *shared_secret, const unsigned char *public_key, const unsigned char *private_key);


#ifdef __cplusplus
}
#endif

#endif
1 change: 1 addition & 0 deletions contrib/hbcrypto/3rd/ed25519/ed25519.hbc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
libs=${_HB_3RDPREF}${hb_name}${_HB_3RDSUFF}
44 changes: 44 additions & 0 deletions contrib/hbcrypto/3rd/ed25519/ed25519.hbp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
-stop{hbdyn&!(HB_BUILD_3RD_DYN='yes')} -env:__HB_3RD_DYN=yes{hbdyn}

-hblib
-inc

-o${hb_name}

-warn=low
-cpp=no
-pic

fe.c
ge.c
keypair.c
key_exchange.c
sc.c
sign.c
verify.c
sha512.c{hbdyn}

# Use Harbour core SHA-512 implementation only when building static lib.
# This way the dynamic lib won't depend on Harbour dynlib.
-cflag=-DHB_USE_CORE_SHA512{!hbdyn}

# URL https://github.com/orlp/ed25519/archive/7fa6712ef5d581a6981ec2b08ee623314cd1d1c4.tar.gz
# DIFF ed25519.diff
#
# MAP license.txt
# MAP src/add_scalar.c add_scalar.c
# MAP src/fe.c fe.c
# MAP src/ge.c ge.c
# MAP src/key_exchange.c key_exchange.c
# MAP src/keypair.c keypair.c
# MAP src/sc.c sc.c
# MAP src/sign.c sign.c
# MAP src/verify.c verify.c
# MAP src/ed25519.h ed25519.h
# MAP src/fe.h fe.h
# MAP src/fixedint.h fixedint.h
# MAP src/ge.h ge.h
# MAP src/precomp_data.h precomp_data.h
# MAP src/sc.h sc.h
# MAP src/sha512.h sha512.h
# MAP src/sha512.c sha512.c
Loading

0 comments on commit 37b742a

Please sign in to comment.