Helmut Schellong <
r...@schellong.biz> wrote:
> On 04/11/2022 19:12, Enrik Berkhan wrote:
>> Bisher gar nicht, oder kommen inzwischen die korrekten Werte heraus?
>
> Darum geht es aber gar nicht bei dieser Konzeptfrage!
> Es geht hier um die Quellcode-Formulierung, nicht um Runtime-Resultate.
Hier sind die Fixes für Deine Quellcode-Formulierung. Bei ist der Test
damit - zumindest auf den ersten Blick - erfolgreich durchgelaufen:
commit 290bd21f98badbe535652fa27c7fcd7a7f49fe0c (HEAD -> main)
Author: Enrik Berkhan <
Enrik....@inka.de>
Date: Mon Apr 11 22:23:34 2022 +0200
Fix key output byte order
diff --git a/dragon.c b/dragon.c
index 23be0d4..41a6673 100644
--- a/dragon.c
+++ b/dragon.c
@@ -123,7 +123,7 @@ static int dragon(int C, char *A[])
k= (uint64_t)a<<32 | e;
if (DRAGON_TEST>0) {
if (wr-->0) {
- for (i=0; i<8; ++i) printf("%02hhX", (byte)(k>>8*i));
+ for (i=0; i<8; ++i) printf("%02hhX", (byte)(k>>8*(7-i)));
printf(wr%4==0?"\n":" "); continue;
}
else return 0;
commit e06e44dd7535e5952d7eec6fba1e68a13b99f23d
Author: Enrik Berkhan <
Enrik....@inka.de>
Date: Mon Apr 11 22:22:02 2022 +0200
Fix shifting during key stream generation
diff --git a/dragon.c b/dragon.c
index ba9b613..23be0d4 100644
--- a/dragon.c
+++ b/dragon.c
@@ -117,8 +117,8 @@ static int dragon(int C, char *A[])
while (1) { uint64_t k, buf[2*1024];
a= B[0]; b= B[9]; c= B[16]; d= B[19]; e= B[30]^M>>32; f= B[31]^M;
UPDATE_F();
- B[0]= b; B[1]= c;
for (i=31; i>1; --i) B[i]= B[i-2];
+ B[0]= b; B[1]= c;
M+= 1;
k= (uint64_t)a<<32 | e;
if (DRAGON_TEST>0) {
commit 0366613a12f590699d2686dcf4f5dfae33f4577f
Author: Enrik Berkhan <
Enrik....@inka.de>
Date: Mon Apr 11 22:13:38 2022 +0200
Fix W -> B copy
diff --git a/dragon.c b/dragon.c
index e1b1ecd..ba9b613 100644
--- a/dragon.c
+++ b/dragon.c
@@ -112,7 +112,7 @@ static int dragon(int C, char *A[])
W[0][1]= ((uint64_t)c<<32|d) ^ W[5][1];
M= (uint64_t)e<<32 | f;
}
- for (i=0; i<32; i+=2) q= ((uint64_t*)W)[i/2], B[i]= q, B[i+1]= q>>32;
+ for (i=0; i<8; i+=1) B[4*i]= W[i][0]>>32, B[4*i+1]= W[i][0], B[4*i+2] = W[i][1]>>32, B[4*i+3] = W[i][1];
int nb=0, nk=0, wr=16;
while (1) { uint64_t k, buf[2*1024];
a= B[0]; b= B[9]; c= B[16]; d= B[19]; e= B[30]^M>>32; f= B[31]^M;
commit 5e4bb1243f29183ca8d8f3aaf3d3e626c0204d73
Author: Enrik Berkhan <
Enrik....@inka.de>
Date: Mon Apr 11 22:12:17 2022 +0200
Fix shifting during initialization
diff --git a/dragon.c b/dragon.c
index c2df8b3..e1b1ecd 100644
--- a/dragon.c
+++ b/dragon.c
@@ -107,9 +107,9 @@ static int dragon(int C, char *A[])
q= W[0][1]^W[6][1]^W[7][1]; c= q>>32, d= q;
e= M>>32, f= M;
UPDATE_F();
- W[0][0]= ((uint64_t)c<<32|d) ^ W[4][0];
- W[0][1]= ((uint64_t)a<<32|b) ^ W[4][1];
for (q=7; q>0; --q) W[q][0]= W[q-1][0], W[q][1]= W[q-1][1];
+ W[0][0]= ((uint64_t)a<<32|b) ^ W[5][0];
+ W[0][1]= ((uint64_t)c<<32|d) ^ W[5][1];
M= (uint64_t)e<<32 | f;
}
for (i=0; i<32; i+=2) q= ((uint64_t*)W)[i/2], B[i]= q, B[i+1]= q>>32;
commit f3cf6ee3801b58c5f2858637b50065d760d206cd
Author: Enrik Berkhan <
Enrik....@inka.de>
Date: Mon Apr 11 22:11:15 2022 +0200
Fix W -> a,b,c,d mapping
diff --git a/dragon.c b/dragon.c
index 6d1be57..c2df8b3 100644
--- a/dragon.c
+++ b/dragon.c
@@ -103,8 +103,8 @@ static int dragon(int C, char *A[])
W[7][0]= I[2], W[7][1]= I[3];
M= 0x447261676F6Eull;
for (i=0; i<16; ++i) {
- q= W[0][0]^W[6][0]^W[7][0]; c= q>>32, d= q;
- q= W[0][1]^W[6][1]^W[7][1]; a= q>>32, b= q;
+ q= W[0][0]^W[6][0]^W[7][0]; a= q>>32, b= q;
+ q= W[0][1]^W[6][1]^W[7][1]; c= q>>32, d= q;
e= M>>32, f= M;
UPDATE_F();
W[0][0]= ((uint64_t)c<<32|d) ^ W[4][0];
commit 83ae91be87e0e860afa638f5ba8bb39e5e5551c7
Author: Enrik Berkhan <
Enrik....@inka.de>
Date: Mon Apr 11 22:09:39 2022 +0200
Fix UPDATE()
diff --git a/dragon.c b/dragon.c
index f4f3492..6d1be57 100644
--- a/dragon.c
+++ b/dragon.c
@@ -40,9 +40,7 @@ static void noret dragE(const char *es, int e)
a^= S2[b>>24&255] ^ S2[b>>16&255] ^ S2[b>>8&255] ^ S1[b&255]; \
c^= S2[d>>24&255] ^ S2[d>>16&255] ^ S1[d>>8&255] ^ S2[d&255]; \
e^= S2[f>>24&255] ^ S1[f>>16&255] ^ S2[f>>8&255] ^ S2[f&255]; \
- d+=a, f+=c, b+=e; c^=b, e^=d, a^=f; \
- d= d<<16|d>>16, f= f<<16|f>>16, b= b<<16|b>>16; \
- c= c<<16|c>>16, e= e<<16|e>>16, a= a<<16|a>>16;
+ d+=a, f+=c, b+=e; c^=b, e^=d, a^=f;
static uint32_t const S1[], S2[];
commit 0c209f698f2ef9168e15798711aa2d1df555b4b7
Author: Enrik Berkhan <
Enrik....@inka.de>
Date: Mon Apr 11 21:35:38 2022 +0200
Fix key/iv byte order
diff --git a/dragon.c b/dragon.c
index 3763279..f4f3492 100644
--- a/dragon.c
+++ b/dragon.c
@@ -82,7 +82,7 @@ static int dragon(int C, char *A[])
for (nb=i=0; i<64; nb+=i&1,++i) {
h= Chex[ap[i]]-1;
if (!(i&1)) m =h, m<<=4;
- else m|=h, P[nb/8]|= (uint64_t)m<<8*(nb%8);
+ else m|=h, P[nb/8]|= (uint64_t)m<<8*((31-nb)%8);
}
break;
case 32: for (i=0; i<32; ++i) P[i/8]|= ap[i]<<8*(i%8);
commit 177b795c005c1b7d5bfabedcd80fe07e5684dc20
Author: Enrik Berkhan <
Enrik....@inka.de>
Date: Mon Apr 11 20:55:17 2022 +0200
Fix key/iv initialization from hex string.
diff --git a/dragon.c b/dragon.c
index 4ed7133..3763279 100644
--- a/dragon.c
+++ b/dragon.c
@@ -71,7 +71,7 @@ static int dragon(int C, char *A[])
if (!pass&&DRAGON_TEST==0) return 0;
if (C!=5) dragE(args, 1);
for (i=0; i<4; ++i) K[i]=I[i]= 0;
- for (p=1; p<3; ++p) { char *ap, h, m; uint64_t *P; unsigned nb;
+ for (p=1; p<3; ++p) { char *ap, h; unsigned m; uint64_t *P; unsigned nb;
ap= A[p]; P= p==1 ? K : I;
for (h=1,i=0; i<256+1&&ap[i]; ++i) if (!Chex[ap[i]]) h=0;
switch (i) {
@@ -82,7 +82,7 @@ static int dragon(int C, char *A[])
for (nb=i=0; i<64; nb+=i&1,++i) {
h= Chex[ap[i]]-1;
if (!(i&1)) m =h, m<<=4;
- else m|=h, P[nb/8]|= m<<8*(nb%8);
+ else m|=h, P[nb/8]|= (uint64_t)m<<8*(nb%8);
}
break;
case 32: for (i=0; i<32; ++i) P[i/8]|= ap[i]<<8*(i%8);