Check-in [b42f88c83c]
Overview
Comment:Update argon2 to deal with the amalgamized version of things in monocypher
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: b42f88c83c960eb8aa742df3757fdf14bbe1624c73f67678b37c4b2679a7eeef
User & Date: rkeene on 2019-01-11 17:33:39
Other Links: manifest | tags
Context
2019-01-11
17:35
randomSortList in the internal namespace check-in: 75052adbef user: rkeene tags: trunk
17:33
Update argon2 to deal with the amalgamized version of things in monocypher check-in: b42f88c83c user: rkeene tags: trunk
17:33
When compiling the amalgamized version of Tcl Nano, define a macro that can be used to detect this check-in: 28a8f24de6 user: rkeene tags: trunk
Changes

Modified .fossil-settings/ignore-glob from [e8ee0fb684] to [4bb4e2cfe0].

16
17
18
19
20
21
22


23
24
25
config.sub
configure
install-sh
config.log
config.status
vendor/argon2
build/argon2/out


build/argon2/INST
build/work
build/tcl







>
>



16
17
18
19
20
21
22
23
24
25
26
27
config.sub
configure
install-sh
config.log
config.status
vendor/argon2
build/argon2/out
build/argon2/src-patched
build/argon2/src-patched.new
build/argon2/INST
build/work
build/tcl

Modified build/argon2/Makefile from [2c770458fb] to [44d77b732f].

1
2
3
4

5








6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29


30
31
32
33
34
35
36
37
38
39

40
41
42
43
44
PREFIX := $(shell pwd)/INST

all: out/argon2.c out/argon2.h


out/argon2.c: src/argon2.c src/ref.c src/core.c src/blake2b.c src/encoding.c monocypher-blake2b.h Makefile








	mkdir -p out
	echo '#define ARGON2_NO_THREADS 1' > out/argon2.c.new.1
	echo '#define ARGON2_INTERNAL_ONLY 1' >> out/argon2.c.new.1
	cat monocypher-blake2b.h >> out/argon2.c.new.1
	echo '#include "argon2.h"' >> out/argon2.c.new.1
	sed '/^#include "/ d' src/argon2.c >> out/argon2.c.new.1
	sed '/^#include "/ d' src/encoding.c >> out/argon2.c.new.1
	sed '/^#include "/ d' src/ref.c >> out/argon2.c.new.1
	sed '/#include "/ d;/#include/ b;/Argon2 Team - Begin Code/,/Argon2 Team - End Code/ b;d' src/blake2b.c >> out/argon2.c.new.1
	sed '/^#include "/ d' src/core.c >> out/argon2.c.new.1
	sed -r '/( |\*)argon(2_ctx|2_verify|2_hash|2_type2|2_error_message|2_encodedlen|2i_|2d_|2id_)/ b;/:/ b;/^(static|extern|enum|typedef) / b;s@^[a-z]@static &@'  out/argon2.c.new.1 > out/argon2.c.new.2
	rm -f out/argon2.c.new.1
	sed 's@malloc(@(void *) Tcl_AttemptAlloc(@g;s@free(@Tcl_Free((void *) @g' out/argon2.c.new.2 > out/argon2.c.new.1
	rm -f out/argon2.c.new.2
	mv out/argon2.c.new.1 out/argon2.c

out/argon2.h: src/argon2.h src/blamka-round-ref.h src/core.h src/encoding.h Makefile
	mkdir -p out
	cat src/argon2.h > out/argon2.h.new.1
	echo '#ifdef ARGON2_INTERNAL_ONLY' >> out/argon2.h.new.1
	cat src/blamka-round-ref.h src/core.h src/encoding.h >> out/argon2.h.new.1
	echo '#endif' >> out/argon2.h.new.1
	sed -r '/^extern int FLAG/ d;/#include "/ d;/( |\*)argon(2_ctx|2_verify|2_hash|2_type2|2_error_message|2_encodedlen|2i_|2d_|2id_)/ b;/:/ b;/^(static|extern|enum|typedef) / b;s@^[a-z]@static &@' out/argon2.h.new.1 > out/argon2.h.new.2
	rm -f out/argon2.h.new.1


	mv out/argon2.h.new.2 out/argon2.h

install: out/argon2.c out/argon2.h
	mkdir -p '$(PREFIX)'
	cp out/argon2.c out/argon2.h '$(PREFIX)'

clean:
	rm -f out/argon2.c out/argon2.h
	rm -f out/argon2.c.new.1 out/argon2.c.new.2
	rm -f out/argon2.h.new.1 out/argon2.h.new.2

	-rmdir out

distclean: clean

.PHONY: all install clean distclean




>
|
>
>
>
>
>
>
>
>





|
|
|
|
|


|



|

|

|



>
>
|









>





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
PREFIX := $(shell pwd)/INST

all: out/argon2.c out/argon2.h

src-patched/argon2.c src-patched/argon2.h src-patched/blake2b.c src-patched/blamka-round-ref.h src-patched/core.c src-patched/core.h src-patched/encoding.c src-patched/encoding.h src-patched/ref.c: src-patched Makefile

src-patched: src/argon2.c src/argon2.h src/blake2b.c src/blamka-round-ref.h src/core.c src/core.h src/encoding.c src/encoding.h src/ref.c patches/argon2-20181109-tclamalgamation.diff Makefile
	rm -rf src-patched src-patched.new
	mkdir src-patched.new
	cp $^ src-patched.new/
	cd src-patched.new && patch --batch --posix -p1 < ../patches/argon2-20181109-tclamalgamation.diff
	mv src-patched.new src-patched

out/argon2.c: src-patched/argon2.c src-patched/ref.c src-patched/core.c src-patched/blake2b.c src-patched/encoding.c monocypher-blake2b.h Makefile
	mkdir -p out
	echo '#define ARGON2_NO_THREADS 1' > out/argon2.c.new.1
	echo '#define ARGON2_INTERNAL_ONLY 1' >> out/argon2.c.new.1
	cat monocypher-blake2b.h >> out/argon2.c.new.1
	echo '#include "argon2.h"' >> out/argon2.c.new.1
	sed '/^#include "/ d' src-patched/argon2.c >> out/argon2.c.new.1
	sed '/^#include "/ d' src-patched/encoding.c >> out/argon2.c.new.1
	sed '/^#include "/ d' src-patched/ref.c >> out/argon2.c.new.1
	sed '/#include "/ d;/#include/ b;/Argon2 Team - Begin Code/,/Argon2 Team - End Code/ b;d' src-patched/blake2b.c >> out/argon2.c.new.1
	sed '/^#include "/ d' src-patched/core.c >> out/argon2.c.new.1
	sed -r '/( |\*)argon(2_ctx|2_verify|2_hash|2_type2|2_error_message|2_encodedlen|2i_|2d_|2id_)/ b;/:/ b;/^(static|extern|enum|typedef) / b;s@^[a-z]@static &@'  out/argon2.c.new.1 > out/argon2.c.new.2
	rm -f out/argon2.c.new.1
	sed 's@malloc(@(void *) Tcl_AttemptAlloc(@g;s@free(@Tcl_Free((void *) @g;s@\.v\[@.a[@g;s@->v\[@->a[@g;s@->v)@->a)@g;s@->v,@->a,@g;s@\.v,@.a,@g' out/argon2.c.new.2 > out/argon2.c.new.1
	rm -f out/argon2.c.new.2
	mv out/argon2.c.new.1 out/argon2.c

out/argon2.h: src-patched/argon2.h src-patched/blamka-round-ref.h src-patched/core.h src-patched/encoding.h Makefile
	mkdir -p out
	cat src-patched/argon2.h > out/argon2.h.new.1
	echo '#ifdef ARGON2_INTERNAL_ONLY' >> out/argon2.h.new.1
	cat src-patched/blamka-round-ref.h src-patched/core.h src-patched/encoding.h >> out/argon2.h.new.1
	echo '#endif' >> out/argon2.h.new.1
	sed -r '/^extern int FLAG/ d;/#include "/ d;/( |\*)argon(2_ctx|2_verify|2_hash|2_type2|2_error_message|2_encodedlen|2i_|2d_|2id_)/ b;/:/ b;/^(static|extern|enum|typedef) / b;s@^[a-z]@static &@' out/argon2.h.new.1 > out/argon2.h.new.2
	rm -f out/argon2.h.new.1
	sed '/^typedef struct .* block;$$/ {i \'$$'\n''#ifndef TCL_NANO_AMALGAMATION'$$'\n''s@ v\[@ a[@;p;i \'$$'\n''#endif'$$'\n''d}' out/argon2.h.new.2 > out/argon2.h.new.1
	rm -f out/argon2.h.new.2
	mv out/argon2.h.new.1 out/argon2.h

install: out/argon2.c out/argon2.h
	mkdir -p '$(PREFIX)'
	cp out/argon2.c out/argon2.h '$(PREFIX)'

clean:
	rm -f out/argon2.c out/argon2.h
	rm -f out/argon2.c.new.1 out/argon2.c.new.2
	rm -f out/argon2.h.new.1 out/argon2.h.new.2
	rm -rf src-patched src-patched.new
	-rmdir out

distclean: clean

.PHONY: all install clean distclean

Modified build/argon2/monocypher-blake2b.h from [1b9e334905] to [2dddd538b2].

1
2
3
4
5
6

7


8

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25



26
27
28
29
30
31
32
#define crypto_hash(out, in, inlen) crypto_blake2b(out, in, inlen)
#define blake2b(out, outlen, in, inlen, key, keylen) 0, crypto_blake2b_general(out, outlen, key, keylen, in, inlen)
#define blake2b_state crypto_blake2b_ctx
#define blake2b_init(ctx, outlen) 0; crypto_blake2b_general_init(ctx, outlen, NULL, 0)
#define blake2b_update(ctx, in, inlen) 0; crypto_blake2b_update(ctx, in, inlen)
#define blake2b_final(ctx, out, ignore1) 0; crypto_blake2b_final(ctx, out)

#define BLAKE2_INLINE


#define BLAKE2B_OUTBYTES 64

#include <stdint.h>
#include <tcl.h>
#include "monocypher.h"
static BLAKE2_INLINE uint64_t rotr64(uint64_t x, uint64_t n) { return (x >> n) ^ (x << (64 - n)); }
static BLAKE2_INLINE void store32( void *dst, uint32_t w )
{
#if defined(NATIVE_LITTLE_ENDIAN)
  memcpy(dst, &w, sizeof w);
#else
  uint8_t *p = ( uint8_t * )dst;
  p[0] = (uint8_t)(w >>  0);
  p[1] = (uint8_t)(w >>  8);
  p[2] = (uint8_t)(w >> 16);
  p[3] = (uint8_t)(w >> 24);
#endif
}




static BLAKE2_INLINE void store64( void *dst, uint64_t w )
{
#if defined(NATIVE_LITTLE_ENDIAN)
  memcpy(dst, &w, sizeof w);
#else
  uint8_t *p = ( uint8_t * )dst;
  p[0] = (uint8_t)(w >>  0);






>
|
>
>
|
>



<













>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#define crypto_hash(out, in, inlen) crypto_blake2b(out, in, inlen)
#define blake2b(out, outlen, in, inlen, key, keylen) 0, crypto_blake2b_general(out, outlen, key, keylen, in, inlen)
#define blake2b_state crypto_blake2b_ctx
#define blake2b_init(ctx, outlen) 0; crypto_blake2b_general_init(ctx, outlen, NULL, 0)
#define blake2b_update(ctx, in, inlen) 0; crypto_blake2b_update(ctx, in, inlen)
#define blake2b_final(ctx, out, ignore1) 0; crypto_blake2b_final(ctx, out)
#ifndef BLAKE2_INLINE
#  define BLAKE2_INLINE
#endif
#ifndef BLAKE2B_OUTBYTES
#  define BLAKE2B_OUTBYTES 64
#endif
#include <stdint.h>
#include <tcl.h>
#include "monocypher.h"

static BLAKE2_INLINE void store32( void *dst, uint32_t w )
{
#if defined(NATIVE_LITTLE_ENDIAN)
  memcpy(dst, &w, sizeof w);
#else
  uint8_t *p = ( uint8_t * )dst;
  p[0] = (uint8_t)(w >>  0);
  p[1] = (uint8_t)(w >>  8);
  p[2] = (uint8_t)(w >> 16);
  p[3] = (uint8_t)(w >> 24);
#endif
}

#ifndef TCL_NANO_AMALGAMATION
static BLAKE2_INLINE uint64_t rotr64(uint64_t x, uint64_t n) { return (x >> n) ^ (x << (64 - n)); }

static BLAKE2_INLINE void store64( void *dst, uint64_t w )
{
#if defined(NATIVE_LITTLE_ENDIAN)
  memcpy(dst, &w, sizeof w);
#else
  uint8_t *p = ( uint8_t * )dst;
  p[0] = (uint8_t)(w >>  0);
54
55
56
57
58
59
60
61
         (( uint64_t )( p[3] ) << 24) |
         (( uint64_t )( p[4] ) << 32) |
         (( uint64_t )( p[5] ) << 40) |
         (( uint64_t )( p[6] ) << 48) |
         (( uint64_t )( p[7] ) << 56) ;
#endif
}








|
60
61
62
63
64
65
66
67
         (( uint64_t )( p[3] ) << 24) |
         (( uint64_t )( p[4] ) << 32) |
         (( uint64_t )( p[5] ) << 40) |
         (( uint64_t )( p[6] ) << 48) |
         (( uint64_t )( p[7] ) << 56) ;
#endif
}
#endif

Added build/argon2/patches/argon2-20181109-tclamalgamation.diff version [5316437e9c].



















































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
diff -uNr a/blake2b.c b/blake2b.c
--- a/blake2b.c	2019-01-11 10:45:44.194444669 -0600
+++ b/blake2b.c	2019-01-11 11:31:06.584395039 -0600
@@ -185,6 +185,7 @@
     v[14] = blake2b_IV[6] ^ S->f[0];
     v[15] = blake2b_IV[7] ^ S->f[1];
 
+#ifndef TCL_NANO_AMALGAMATION
 #define G(r, i, a, b, c, d)                                                    \
     do {                                                                       \
         a = a + b + m[blake2b_sigma[r][2 * i + 0]];                            \
@@ -196,6 +197,7 @@
         c = c + d;                                                             \
         b = rotr64(b ^ c, 63);                                                 \
     } while ((void)0, 0)
+#endif
 
 #define ROUND(r)                                                               \
     do {                                                                       \
diff -uNr a/blamka-round-ref.h b/blamka-round-ref.h
--- a/blamka-round-ref.h	2019-01-11 10:45:44.194444669 -0600
+++ b/blamka-round-ref.h	2019-01-11 11:31:15.166394883 -0600
@@ -22,6 +22,7 @@
 #include "blake2-impl.h"
 
 /* designed by the Lyra PHC team */
+#ifndef TCL_NANO_AMALGAMATION
 static BLAKE2_INLINE uint64_t fBlaMka(uint64_t x, uint64_t y) {
     const uint64_t m = UINT64_C(0xFFFFFFFF);
     const uint64_t xy = (x & m) * (y & m);
@@ -39,6 +40,7 @@
         c = fBlaMka(c, d);                                                     \
         b = rotr64(b ^ c, 63);                                                 \
     } while ((void)0, 0)
+#endif
 
 #define BLAKE2_ROUND_NOMSG(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11,   \
                            v12, v13, v14, v15)                                 \
diff -uNr a/core.c b/core.c
--- a/core.c	2019-01-11 10:45:44.194444669 -0600
+++ b/core.c	2019-01-11 11:31:06.586395039 -0600
@@ -56,6 +56,7 @@
 /***************Instance and Position constructors**********/
 void init_block_value(block *b, uint8_t in) { memset(b->v, in, sizeof(b->v)); }
 
+#ifndef TCL_NANO_AMALGAMATION
 void copy_block(block *dst, const block *src) {
     memcpy(dst->v, src->v, sizeof(uint64_t) * ARGON2_QWORDS_IN_BLOCK);
 }
@@ -80,6 +81,7 @@
         store64((uint8_t *)output + i * sizeof(src->v[i]), src->v[i]);
     }
 }
+#endif
 
 /***************Memory functions*****************/