commit 149d87f0474cfb1ae1f5540962effcdc8ac0fcb6
parent 3e6cf95033fca07d02f9b8ecc199eb5f96c477b7
Author: erai <erai@omiltem.net>
Date: Fri, 11 Oct 2024 11:26:12 -0400
63 bit numbers
Diffstat:
M | as.c | | | 8 | ++++---- |
M | cc0.c | | | 28 | ++++++++++++++++++---------- |
M | ed25519.c | | | 96 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
M | kernel.c | | | 16 | ++++++++-------- |
M | lib.c | | | 26 | +++++++++++++++++++------- |
M | poly1305.c | | | 8 | ++++---- |
M | sha256.c | | | 144 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
M | sha512.c | | | 176 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
8 files changed, 261 insertions(+), 241 deletions(-)
diff --git a/as.c b/as.c
@@ -588,7 +588,7 @@ emit_kstart(c: *assembler) {
// Enable paging
as_modrr(c, OP_RDCRR, R_CR0, R_RAX);
- as_modri(c, OP_ORI, R_RAX, (-0x8000 << 16) | (0x0001));
+ as_modri(c, OP_ORI, R_RAX, (-0x80000000) | 0x0001);
as_modrr(c, OP_WRCRR, R_CR0, R_RAX);
// flags
@@ -606,7 +606,7 @@ emit_kstart(c: *assembler) {
as_jmp(c, OP_CALL, do_ret);
// Reload the gdt in the top half
- as_modri(c, OP_ORI, R_RBP, (-0x8000 << 16));
+ as_modri(c, OP_ORI, R_RBP, -0x80000000);
as_modri(c, OP_MOVI, R_RAX, 23);
as_modrm(c, OP_STORE, R_RAX, R_RBP, 0, 0, 0);
as_modrm(c, OP_LEA, R_RAX, R_RBP, 0, 0, 8);
@@ -623,7 +623,7 @@ emit_kstart(c: *assembler) {
as_modrr(c, OP_MOVE, R_RSP, R_RSP);
// Reload stack in the top half
- as_modri(c, OP_ORI, R_RSP, (-0x8000 << 16));
+ as_modri(c, OP_ORI, R_RSP, -0x80000000);
// Kill the lower mapping
as_modri(c, OP_MOVI, R_RAX, 0);
@@ -649,7 +649,7 @@ emit_kstart(c: *assembler) {
// ret to top half
fixup_label(c, do_ret);
as_opr(c, OP_POPR, R_RAX);
- as_modri(c, OP_ORI, R_RAX, (-0x8000 << 16));
+ as_modri(c, OP_ORI, R_RAX, -0x80000000);
as_opr(c, OP_PUSHR, R_RAX);
as_op(c, OP_RET);
diff --git a/cc0.c b/cc0.c
@@ -2699,13 +2699,17 @@ unsigned long( my_dec2int)(unsigned char* my_s,unsigned long my_len,unsigned lon
(*(my_ok))=(0UL);
return 0UL;
}
+ if ((unsigned long)(((long)(my_x))>((long)(461168601842738790UL)))) {
+ (*(my_ok))=(0UL);
+ return 0UL;
+ }
(my_x)=((unsigned long)(((long)(my_x))*((long)(10UL))));
- (my_x)=((unsigned long)(((unsigned long)(my_x))+((unsigned long)(my_d))));
- (my_i)=((unsigned long)(((unsigned long)(my_i))+((unsigned long)(1UL))));
- if ((unsigned long)(((long)(my_x))>((long)(2147483647UL)))) {
+ if ((unsigned long)(((long)(my_x))>((long)((unsigned long)(((unsigned long)((unsigned long)(((unsigned long)((unsigned long)(((unsigned long)(1UL))<<((unsigned long)(63UL)))))-((unsigned long)(1UL)))))-((unsigned long)(my_d))))))) {
(*(my_ok))=(0UL);
return 0UL;
}
+ (my_x)=((unsigned long)(((unsigned long)(my_x))+((unsigned long)(my_d))));
+ (my_i)=((unsigned long)(((unsigned long)(my_i))+((unsigned long)(1UL))));
}
(*(my_ok))=(1UL);
return my_x;
@@ -3642,7 +3646,7 @@ void( my_emit_kstart)(struct my_assembler* my_c){
(my_as_modri)((my_c),(my_OP_ORI),(my_R_RAX),(256UL));
(my_as_op)((my_c),(my_OP_WRMSR));
(my_as_modrr)((my_c),(my_OP_RDCRR),(my_R_CR0),(my_R_RAX));
- (my_as_modri)((my_c),(my_OP_ORI),(my_R_RAX),((unsigned long)(((unsigned long)((unsigned long)(((unsigned long)((unsigned long)(-(unsigned long)(32768UL))))<<((unsigned long)(16UL)))))|((unsigned long)(1UL)))));
+ (my_as_modri)((my_c),(my_OP_ORI),(my_R_RAX),((unsigned long)(((unsigned long)((unsigned long)(-(unsigned long)(2147483648UL))))|((unsigned long)(1UL)))));
(my_as_modrr)((my_c),(my_OP_WRCRR),(my_R_CR0),(my_R_RAX));
(my_as_modri)((my_c),(my_OP_MOVI),(my_R_RAX),(0UL));
(my_as_opr)((my_c),(my_OP_PUSHR),(my_R_RAX));
@@ -3651,7 +3655,7 @@ void( my_emit_kstart)(struct my_assembler* my_c){
(my_as_jmp)((my_c),(my_OP_CALL),(my_do_iret));
((my_c)->my_bits32)=(0UL);
(my_as_jmp)((my_c),(my_OP_CALL),(my_do_ret));
- (my_as_modri)((my_c),(my_OP_ORI),(my_R_RBP),((unsigned long)(((unsigned long)((unsigned long)(-(unsigned long)(32768UL))))<<((unsigned long)(16UL)))));
+ (my_as_modri)((my_c),(my_OP_ORI),(my_R_RBP),((unsigned long)(-(unsigned long)(2147483648UL))));
(my_as_modri)((my_c),(my_OP_MOVI),(my_R_RAX),(23UL));
(my_as_modrm)((my_c),(my_OP_STORE),(my_R_RAX),(my_R_RBP),(0UL),(0UL),(0UL));
(my_as_modrm)((my_c),(my_OP_LEA),(my_R_RAX),(my_R_RBP),(0UL),(0UL),(8UL));
@@ -3664,7 +3668,7 @@ void( my_emit_kstart)(struct my_assembler* my_c){
(my_as_modrr)((my_c),(my_OP_WRSR),(my_R_GS),(my_R_RAX));
(my_as_modrr)((my_c),(my_OP_WRSR),(my_R_SS),(my_R_RAX));
(my_as_modrr)((my_c),(my_OP_MOVE),(my_R_RSP),(my_R_RSP));
- (my_as_modri)((my_c),(my_OP_ORI),(my_R_RSP),((unsigned long)(((unsigned long)((unsigned long)(-(unsigned long)(32768UL))))<<((unsigned long)(16UL)))));
+ (my_as_modri)((my_c),(my_OP_ORI),(my_R_RSP),((unsigned long)(-(unsigned long)(2147483648UL))));
(my_as_modri)((my_c),(my_OP_MOVI),(my_R_RAX),(0UL));
(my_as_modrm)((my_c),(my_OP_LEA),(my_R_RDI),(my_R_RBP),(0UL),(0UL),(64UL));
(my_as_modrm)((my_c),(my_OP_STORE),(my_R_RAX),(my_R_RDI),(0UL),(0UL),(4096UL));
@@ -3680,7 +3684,7 @@ void( my_emit_kstart)(struct my_assembler* my_c){
(my_as_op)((my_c),(my_OP_IRET));
(my_fixup_label)((my_c),(my_do_ret));
(my_as_opr)((my_c),(my_OP_POPR),(my_R_RAX));
- (my_as_modri)((my_c),(my_OP_ORI),(my_R_RAX),((unsigned long)(((unsigned long)((unsigned long)(-(unsigned long)(32768UL))))<<((unsigned long)(16UL)))));
+ (my_as_modri)((my_c),(my_OP_ORI),(my_R_RAX),((unsigned long)(-(unsigned long)(2147483648UL))));
(my_as_opr)((my_c),(my_OP_PUSHR),(my_R_RAX));
(my_as_op)((my_c),(my_OP_RET));
(my_fixup_label)((my_c),(my_done));
@@ -4540,13 +4544,17 @@ unsigned long( my_hex2int)(unsigned char* my_s,unsigned long my_len,unsigned lon
(*(my_ok))=(0UL);
return 0UL;
}
+ if ((unsigned long)(((long)(my_x))>((long)((unsigned long)(((unsigned long)((unsigned long)(((unsigned long)(1UL))<<((unsigned long)(59UL)))))-((unsigned long)(1UL))))))) {
+ (*(my_ok))=(0UL);
+ return 0UL;
+ }
(my_x)=((unsigned long)(((long)(my_x))*((long)(16UL))));
- (my_x)=((unsigned long)(((unsigned long)(my_x))+((unsigned long)(my_d))));
- (my_i)=((unsigned long)(((unsigned long)(my_i))+((unsigned long)(1UL))));
- if ((unsigned long)(((long)(my_x))>((long)(2147483647UL)))) {
+ if ((unsigned long)(((long)(my_x))>((long)((unsigned long)(((unsigned long)((unsigned long)(((unsigned long)((unsigned long)(((unsigned long)(1UL))<<((unsigned long)(63UL)))))-((unsigned long)(1UL)))))-((unsigned long)(my_d))))))) {
(*(my_ok))=(0UL);
return 0UL;
}
+ (my_x)=((unsigned long)(((unsigned long)(my_x))+((unsigned long)(my_d))));
+ (my_i)=((unsigned long)(((unsigned long)(my_i))+((unsigned long)(1UL))));
}
(*(my_ok))=(1UL);
return my_x;
diff --git a/ed25519.c b/ed25519.c
@@ -315,14 +315,14 @@ ed25519_one(r: *int) {
}
ed25519_d(d: *int) {
- d[7] = (0x5203 << 16) | 0x6cee;
- d[6] = (0x2b6f << 16) | 0xfe73;
- d[5] = (0x8cc7 << 16) | 0x4079;
- d[4] = (0x7779 << 16) | 0xe898;
- d[3] = (0x0070 << 16) | 0x0a4d;
- d[2] = (0x4141 << 16) | 0xd8ab;
- d[1] = (0x75eb << 16) | 0x4dca;
- d[0] = (0x1359 << 16) | 0x78a3;
+ d[7] = 0x52036cee;
+ d[6] = 0x2b6ffe73;
+ d[5] = 0x8cc74079;
+ d[4] = 0x7779e898;
+ d[3] = 0x00700a4d;
+ d[2] = 0x4141d8ab;
+ d[1] = 0x75eb4dca;
+ d[0] = 0x135978a3;
}
ed25519_a(a: *int) {
@@ -447,34 +447,34 @@ ed25519_pk(r: *int, a: *int, k: *int) {
}
ed25519_base(p: *int) {
- p[7] = (0x2169 << 16) | 0x36d3;
- p[6] = (0xcd6e << 16) | 0x53fe;
- p[5] = (0xc0a4 << 16) | 0xe231;
- p[4] = (0xfdd6 << 16) | 0xdc5c;
- p[3] = (0x692c << 16) | 0xc760;
- p[2] = (0x9525 << 16) | 0xa7b2;
- p[1] = (0xc956 << 16) | 0x2d60;
- p[0] = (0x8f25 << 16) | 0xd51a;
- p[15] = (0x6666 << 16) | 0x6666;
- p[14] = (0x6666 << 16) | 0x6666;
- p[13] = (0x6666 << 16) | 0x6666;
- p[12] = (0x6666 << 16) | 0x6666;
- p[11] = (0x6666 << 16) | 0x6666;
- p[10] = (0x6666 << 16) | 0x6666;
- p[9] = (0x6666 << 16) | 0x6666;
- p[8] = (0x6666 << 16) | 0x6658;
+ p[7] = 0x216936d3;
+ p[6] = 0xcd6e53fe;
+ p[5] = 0xc0a4e231;
+ p[4] = 0xfdd6dc5c;
+ p[3] = 0x692cc760;
+ p[2] = 0x9525a7b2;
+ p[1] = 0xc9562d60;
+ p[0] = 0x8f25d51a;
+ p[15] = 0x66666666;
+ p[14] = 0x66666666;
+ p[13] = 0x66666666;
+ p[12] = 0x66666666;
+ p[11] = 0x66666666;
+ p[10] = 0x66666666;
+ p[9] = 0x66666666;
+ p[8] = 0x66666658;
}
// 2**((p-1)//4)
ed25519_sqrtz(z: *int) {
- z[7] = (0x2b83 << 16) | 0x2480;
- z[6] = (0x4fc1 << 16) | 0xdf0b;
- z[5] = (0x2b4d << 16) | 0x0099;
- z[4] = (0x3dfb << 16) | 0xd7a7;
- z[3] = (0x2f43 << 16) | 0x1806;
- z[2] = (0xad2f << 16) | 0xe478;
- z[1] = (0xc4ee << 16) | 0x1b27;
- z[0] = (0x4a0e << 16) | 0xa0b0;
+ z[7] = 0x2b832480;
+ z[6] = 0x4fc1df0b;
+ z[5] = 0x2b4d0099;
+ z[4] = 0x3dfbd7a7;
+ z[3] = 0x2f431806;
+ z[2] = 0xad2fe478;
+ z[1] = 0xc4ee1b27;
+ z[0] = 0x4a0ea0b0;
}
// sqrt(x) = x**((p+3)/8) * [1 or 2**((p-1)/4)]
@@ -717,14 +717,14 @@ ed25519_sign(sig: *byte, b: *byte, msg: *byte, len: int) {
}
ed25519_l(l: *int) {
- l[7] = (0x1000 << 16) | 0x0000;
- l[6] = (0x0000 << 16) | 0x0000;
- l[5] = (0x0000 << 16) | 0x0000;
- l[4] = (0x0000 << 16) | 0x0000;
- l[3] = (0x14de << 16) | 0xf9de;
- l[2] = (0xa2f7 << 16) | 0x9cd6;
- l[1] = (0x5812 << 16) | 0x631a;
- l[0] = (0x5cf5 << 16) | 0xd3ed;
+ l[7] = 0x10000000;
+ l[6] = 0x00000000;
+ l[5] = 0x00000000;
+ l[4] = 0x00000000;
+ l[3] = 0x14def9de;
+ l[2] = 0xa2f79cd6;
+ l[1] = 0x5812631a;
+ l[0] = 0x5cf5d3ed;
}
ed25519_mod1(m: *int, l: *int, q: int) {
@@ -1019,14 +1019,14 @@ ed25519_verify(sig: *byte, pub: *byte, msg: *byte, len: int): int {
}
ed25519_bi(d: *int) {
- d[7] = (0x0f26 << 16) | 0xedf4;
- d[6] = (0x60a0 << 16) | 0x06bb;
- d[5] = (0xd27b << 16) | 0x08dc;
- d[4] = (0x03fc << 16) | 0x4f7e;
- d[3] = (0xc5a1 << 16) | 0xd3d1;
- d[2] = (0x4b7d << 16) | 0x1a82;
- d[1] = (0xcc6e << 16) | 0x04aa;
- d[0] = (0xff45 << 16) | 0x7e06;
+ d[7] = 0x0f26edf4;
+ d[6] = 0x60a006bb;
+ d[5] = 0xd27b08dc;
+ d[4] = 0x03fc4f7e;
+ d[3] = 0xc5a1d3d1;
+ d[2] = 0x4b7d1a82;
+ d[1] = 0xcc6e04aa;
+ d[0] = 0xff457e06;
}
// u = (1 + y) / (1 - y)
diff --git a/kernel.c b/kernel.c
@@ -305,7 +305,7 @@ bytesum(a: *byte, n: int): byte {
ptov(p: int): *byte {
if p < (1 << 30) {
- return (p + (-0x8000 << 16)): *byte;
+ return (p - 0x80000000): *byte;
} else {
return (p + (-1 << 47)): *byte;
}
@@ -4834,7 +4834,7 @@ _kstart(mb: int) {
global.ip_gw = (192 << 24) + (168 << 16) + (1 << 8) + 1;
global.ip_mask = 20;
global.curtask = &task;
- wrmsr((0xc000 << 16) + 0x0101, global.ptr:int);
+ wrmsr(0xc0000101, global.ptr:int);
global.mmio = -(1 << 31);
@@ -4851,7 +4851,7 @@ _kstart(mb: int) {
global.kpt = rdcr3();
mbinfo = ptov(mb);
- mmap = ptov(_r32(&mbinfo[48])): *int;
+ mmap = ptov(_r32(&mbinfo[48]) + 4): *int;
mmap_len = _r32(&mbinfo[44]);
mmap_count = mmap_len / 24;
@@ -4936,19 +4936,19 @@ _kstart(mb: int) {
// Load gdt idt tss and segments
lgdt(gdt, gdt_size);
lseg(8, 16);
- wrmsr((0xc000 << 16) + 0x0101, global.ptr:int);
+ wrmsr(0xc0000101, global.ptr:int);
lldt(0);
ltr(7 * 8);
lidt(idt, idt_size);
// STAR
- wrmsr((0xc000 << 16) + 0x0081, ((24 + 3) << 48) | (8 << 32));
+ wrmsr(0xc0000081, ((24 + 3) << 48) | (8 << 32));
// LSTAR
- wrmsr((0xc000 << 16) + 0x0082, (_ssr0): int);
+ wrmsr(0xc0000082, (_ssr0): int);
// FMASK
- wrmsr((0xc000 << 16) + 0x0084, -1);
+ wrmsr(0xc0000084, -1);
// EFER
- wrmsr((0xc000 << 16) + 0x0080, rdmsr((0xc000 << 16) + 0x0080) | 1);
+ wrmsr(0xc0000080, rdmsr(0xc0000080) | 1);
// interrupt stack
brk = (brk + 4095) & -4096;
diff --git a/lib.c b/lib.c
@@ -504,14 +504,21 @@ hex2int(s: *byte, len: int, ok: *int): int {
return 0;
}
+ if x > (1 << 59) - 1 {
+ *ok = 0;
+ return 0;
+ }
+
x = x * 16;
- x = x + d;
- i = i + 1;
- if x > 0x7fffffff {
+ if x > ((1 << 63) - 1) - d {
*ok = 0;
return 0;
}
+
+ x = x + d;
+
+ i = i + 1;
}
*ok = 1;
@@ -541,15 +548,20 @@ dec2int(s: *byte, len: int, ok: *int): int {
return 0;
}
- x = x * 10;
+ if x > 461168601842738790 {
+ *ok = 0;
+ return 0;
+ }
- x = x + d;
- i = i + 1;
+ x = x * 10;
- if x > 0x7fffffff {
+ if x > ((1 << 63) - 1) - d {
*ok = 0;
return 0;
}
+
+ x = x + d;
+ i = i + 1;
}
*ok = 1;
diff --git a/poly1305.c b/poly1305.c
@@ -147,10 +147,10 @@ poly1305_mul(a: *int, r: *int) {
poly1305_truncate(dest: *int, key: *byte) {
poly1305_load(dest, key, 4);
- dest[0] = dest[0] & ((0x0fff << 16) | 0xffff);
- dest[1] = dest[1] & ((0x0fff << 16) | 0xfffc);
- dest[2] = dest[2] & ((0x0fff << 16) | 0xfffc);
- dest[3] = dest[3] & ((0x0fff << 16) | 0xfffc);
+ dest[0] = dest[0] & 0x0fffffff;
+ dest[1] = dest[1] & 0x0ffffffc;
+ dest[2] = dest[2] & 0x0ffffffc;
+ dest[3] = dest[3] & 0x0ffffffc;
dest[4] = 0;
}
diff --git a/sha256.c b/sha256.c
@@ -41,14 +41,14 @@ struct _sha256_digest {
}
sha256_init(r: *sha256_ctx) {
- r.a = (0x6a09 << 16) | 0xe667;
- r.b = (0xbb67 << 16) | 0xae85;
- r.c = (0x3c6e << 16) | 0xf372;
- r.d = (0xa54f << 16) | 0xf53a;
- r.e = (0x510e << 16) | 0x527f;
- r.f = (0x9b05 << 16) | 0x688c;
- r.g = (0x1f83 << 16) | 0xd9ab;
- r.h = (0x5be0 << 16) | 0xcd19;
+ r.a = 0x6a09e667;
+ r.b = 0xbb67ae85;
+ r.c = 0x3c6ef372;
+ r.d = 0xa54ff53a;
+ r.e = 0x510e527f;
+ r.f = 0x9b05688c;
+ r.g = 0x1f83d9ab;
+ r.h = 0x5be0cd19;
r.len = 0;
}
@@ -183,70 +183,70 @@ sha256_rounds(ctx: *sha256_ctx, block: *byte) {
| (block[62]:int << 8)
| block[63]:int;
- sha256_round(&r, w, (0x428a << 16) | 0x2f98);
- sha256_round(&r, w, (0x7137 << 16) | 0x4491);
- sha256_round(&r, w, (0xb5c0 << 16) | 0xfbcf);
- sha256_round(&r, w, (0xe9b5 << 16) | 0xdba5);
- sha256_round(&r, w, (0x3956 << 16) | 0xc25b);
- sha256_round(&r, w, (0x59f1 << 16) | 0x11f1);
- sha256_round(&r, w, (0x923f << 16) | 0x82a4);
- sha256_round(&r, w, (0xab1c << 16) | 0x5ed5);
- sha256_round(&r, w, (0xd807 << 16) | 0xaa98);
- sha256_round(&r, w, (0x1283 << 16) | 0x5b01);
- sha256_round(&r, w, (0x2431 << 16) | 0x85be);
- sha256_round(&r, w, (0x550c << 16) | 0x7dc3);
- sha256_round(&r, w, (0x72be << 16) | 0x5d74);
- sha256_round(&r, w, (0x80de << 16) | 0xb1fe);
- sha256_round(&r, w, (0x9bdc << 16) | 0x06a7);
- sha256_round(&r, w, (0xc19b << 16) | 0xf174);
- sha256_round(&r, w, (0xe49b << 16) | 0x69c1);
- sha256_round(&r, w, (0xefbe << 16) | 0x4786);
- sha256_round(&r, w, (0x0fc1 << 16) | 0x9dc6);
- sha256_round(&r, w, (0x240c << 16) | 0xa1cc);
- sha256_round(&r, w, (0x2de9 << 16) | 0x2c6f);
- sha256_round(&r, w, (0x4a74 << 16) | 0x84aa);
- sha256_round(&r, w, (0x5cb0 << 16) | 0xa9dc);
- sha256_round(&r, w, (0x76f9 << 16) | 0x88da);
- sha256_round(&r, w, (0x983e << 16) | 0x5152);
- sha256_round(&r, w, (0xa831 << 16) | 0xc66d);
- sha256_round(&r, w, (0xb003 << 16) | 0x27c8);
- sha256_round(&r, w, (0xbf59 << 16) | 0x7fc7);
- sha256_round(&r, w, (0xc6e0 << 16) | 0x0bf3);
- sha256_round(&r, w, (0xd5a7 << 16) | 0x9147);
- sha256_round(&r, w, (0x06ca << 16) | 0x6351);
- sha256_round(&r, w, (0x1429 << 16) | 0x2967);
- sha256_round(&r, w, (0x27b7 << 16) | 0x0a85);
- sha256_round(&r, w, (0x2e1b << 16) | 0x2138);
- sha256_round(&r, w, (0x4d2c << 16) | 0x6dfc);
- sha256_round(&r, w, (0x5338 << 16) | 0x0d13);
- sha256_round(&r, w, (0x650a << 16) | 0x7354);
- sha256_round(&r, w, (0x766a << 16) | 0x0abb);
- sha256_round(&r, w, (0x81c2 << 16) | 0xc92e);
- sha256_round(&r, w, (0x9272 << 16) | 0x2c85);
- sha256_round(&r, w, (0xa2bf << 16) | 0xe8a1);
- sha256_round(&r, w, (0xa81a << 16) | 0x664b);
- sha256_round(&r, w, (0xc24b << 16) | 0x8b70);
- sha256_round(&r, w, (0xc76c << 16) | 0x51a3);
- sha256_round(&r, w, (0xd192 << 16) | 0xe819);
- sha256_round(&r, w, (0xd699 << 16) | 0x0624);
- sha256_round(&r, w, (0xf40e << 16) | 0x3585);
- sha256_round(&r, w, (0x106a << 16) | 0xa070);
- sha256_round(&r, w, (0x19a4 << 16) | 0xc116);
- sha256_round(&r, w, (0x1e37 << 16) | 0x6c08);
- sha256_round(&r, w, (0x2748 << 16) | 0x774c);
- sha256_round(&r, w, (0x34b0 << 16) | 0xbcb5);
- sha256_round(&r, w, (0x391c << 16) | 0x0cb3);
- sha256_round(&r, w, (0x4ed8 << 16) | 0xaa4a);
- sha256_round(&r, w, (0x5b9c << 16) | 0xca4f);
- sha256_round(&r, w, (0x682e << 16) | 0x6ff3);
- sha256_round(&r, w, (0x748f << 16) | 0x82ee);
- sha256_round(&r, w, (0x78a5 << 16) | 0x636f);
- sha256_round(&r, w, (0x84c8 << 16) | 0x7814);
- sha256_round(&r, w, (0x8cc7 << 16) | 0x0208);
- sha256_round(&r, w, (0x90be << 16) | 0xfffa);
- sha256_round(&r, w, (0xa450 << 16) | 0x6ceb);
- sha256_round(&r, w, (0xbef9 << 16) | 0xa3f7);
- sha256_round(&r, w, (0xc671 << 16) | 0x78f2);
+ sha256_round(&r, w, 0x428a2f98);
+ sha256_round(&r, w, 0x71374491);
+ sha256_round(&r, w, 0xb5c0fbcf);
+ sha256_round(&r, w, 0xe9b5dba5);
+ sha256_round(&r, w, 0x3956c25b);
+ sha256_round(&r, w, 0x59f111f1);
+ sha256_round(&r, w, 0x923f82a4);
+ sha256_round(&r, w, 0xab1c5ed5);
+ sha256_round(&r, w, 0xd807aa98);
+ sha256_round(&r, w, 0x12835b01);
+ sha256_round(&r, w, 0x243185be);
+ sha256_round(&r, w, 0x550c7dc3);
+ sha256_round(&r, w, 0x72be5d74);
+ sha256_round(&r, w, 0x80deb1fe);
+ sha256_round(&r, w, 0x9bdc06a7);
+ sha256_round(&r, w, 0xc19bf174);
+ sha256_round(&r, w, 0xe49b69c1);
+ sha256_round(&r, w, 0xefbe4786);
+ sha256_round(&r, w, 0x0fc19dc6);
+ sha256_round(&r, w, 0x240ca1cc);
+ sha256_round(&r, w, 0x2de92c6f);
+ sha256_round(&r, w, 0x4a7484aa);
+ sha256_round(&r, w, 0x5cb0a9dc);
+ sha256_round(&r, w, 0x76f988da);
+ sha256_round(&r, w, 0x983e5152);
+ sha256_round(&r, w, 0xa831c66d);
+ sha256_round(&r, w, 0xb00327c8);
+ sha256_round(&r, w, 0xbf597fc7);
+ sha256_round(&r, w, 0xc6e00bf3);
+ sha256_round(&r, w, 0xd5a79147);
+ sha256_round(&r, w, 0x06ca6351);
+ sha256_round(&r, w, 0x14292967);
+ sha256_round(&r, w, 0x27b70a85);
+ sha256_round(&r, w, 0x2e1b2138);
+ sha256_round(&r, w, 0x4d2c6dfc);
+ sha256_round(&r, w, 0x53380d13);
+ sha256_round(&r, w, 0x650a7354);
+ sha256_round(&r, w, 0x766a0abb);
+ sha256_round(&r, w, 0x81c2c92e);
+ sha256_round(&r, w, 0x92722c85);
+ sha256_round(&r, w, 0xa2bfe8a1);
+ sha256_round(&r, w, 0xa81a664b);
+ sha256_round(&r, w, 0xc24b8b70);
+ sha256_round(&r, w, 0xc76c51a3);
+ sha256_round(&r, w, 0xd192e819);
+ sha256_round(&r, w, 0xd6990624);
+ sha256_round(&r, w, 0xf40e3585);
+ sha256_round(&r, w, 0x106aa070);
+ sha256_round(&r, w, 0x19a4c116);
+ sha256_round(&r, w, 0x1e376c08);
+ sha256_round(&r, w, 0x2748774c);
+ sha256_round(&r, w, 0x34b0bcb5);
+ sha256_round(&r, w, 0x391c0cb3);
+ sha256_round(&r, w, 0x4ed8aa4a);
+ sha256_round(&r, w, 0x5b9cca4f);
+ sha256_round(&r, w, 0x682e6ff3);
+ sha256_round(&r, w, 0x748f82ee);
+ sha256_round(&r, w, 0x78a5636f);
+ sha256_round(&r, w, 0x84c87814);
+ sha256_round(&r, w, 0x8cc70208);
+ sha256_round(&r, w, 0x90befffa);
+ sha256_round(&r, w, 0xa4506ceb);
+ sha256_round(&r, w, 0xbef9a3f7);
+ sha256_round(&r, w, 0xc67178f2);
ctx.a = (ctx.a + r.a) & (-1 >> 32);
ctx.b = (ctx.b + r.b) & (-1 >> 32);
diff --git a/sha512.c b/sha512.c
@@ -37,14 +37,14 @@ struct _sha512_digest {
}
sha512_init(ctx: *sha512_ctx) {
- ctx.a = (0x6a09 << 48) | (0xe667 << 32) | (0xf3bc << 16) | 0xc908;
- ctx.b = (0xbb67 << 48) | (0xae85 << 32) | (0x84ca << 16) | 0xa73b;
- ctx.c = (0x3c6e << 48) | (0xf372 << 32) | (0xfe94 << 16) | 0xf82b;
- ctx.d = (0xa54f << 48) | (0xf53a << 32) | (0x5f1d << 16) | 0x36f1;
- ctx.e = (0x510e << 48) | (0x527f << 32) | (0xade6 << 16) | 0x82d1;
- ctx.f = (0x9b05 << 48) | (0x688c << 32) | (0x2b3e << 16) | 0x6c1f;
- ctx.g = (0x1f83 << 48) | (0xd9ab << 32) | (0xfb41 << 16) | 0xbd6b;
- ctx.h = (0x5be0 << 48) | (0xcd19 << 32) | (0x137e << 16) | 0x2179;
+ ctx.a = (0x6a09e667 << 32) | 0xf3bcc908;
+ ctx.b = (0xbb67ae85 << 32) | 0x84caa73b;
+ ctx.c = (0x3c6ef372 << 32) | 0xfe94f82b;
+ ctx.d = (0xa54ff53a << 32) | 0x5f1d36f1;
+ ctx.e = (0x510e527f << 32) | 0xade682d1;
+ ctx.f = (0x9b05688c << 32) | 0x2b3e6c1f;
+ ctx.g = (0x1f83d9ab << 32) | 0xfb41bd6b;
+ ctx.h = (0x5be0cd19 << 32) | 0x137e2179;
ctx.len = 0;
}
@@ -131,86 +131,86 @@ sha512_rounds(ctx: *sha512_ctx, block: *byte) {
i = i + 1;
}
- sha512_round(&r, w, (0x428a << 48) | (0x2f98 << 32) | (0xd728 << 16) | 0xae22);
- sha512_round(&r, w, (0x7137 << 48) | (0x4491 << 32) | (0x23ef << 16) | 0x65cd);
- sha512_round(&r, w, (0xb5c0 << 48) | (0xfbcf << 32) | (0xec4d << 16) | 0x3b2f);
- sha512_round(&r, w, (0xe9b5 << 48) | (0xdba5 << 32) | (0x8189 << 16) | 0xdbbc);
- sha512_round(&r, w, (0x3956 << 48) | (0xc25b << 32) | (0xf348 << 16) | 0xb538);
- sha512_round(&r, w, (0x59f1 << 48) | (0x11f1 << 32) | (0xb605 << 16) | 0xd019);
- sha512_round(&r, w, (0x923f << 48) | (0x82a4 << 32) | (0xaf19 << 16) | 0x4f9b);
- sha512_round(&r, w, (0xab1c << 48) | (0x5ed5 << 32) | (0xda6d << 16) | 0x8118);
- sha512_round(&r, w, (0xd807 << 48) | (0xaa98 << 32) | (0xa303 << 16) | 0x0242);
- sha512_round(&r, w, (0x1283 << 48) | (0x5b01 << 32) | (0x4570 << 16) | 0x6fbe);
- sha512_round(&r, w, (0x2431 << 48) | (0x85be << 32) | (0x4ee4 << 16) | 0xb28c);
- sha512_round(&r, w, (0x550c << 48) | (0x7dc3 << 32) | (0xd5ff << 16) | 0xb4e2);
- sha512_round(&r, w, (0x72be << 48) | (0x5d74 << 32) | (0xf27b << 16) | 0x896f);
- sha512_round(&r, w, (0x80de << 48) | (0xb1fe << 32) | (0x3b16 << 16) | 0x96b1);
- sha512_round(&r, w, (0x9bdc << 48) | (0x06a7 << 32) | (0x25c7 << 16) | 0x1235);
- sha512_round(&r, w, (0xc19b << 48) | (0xf174 << 32) | (0xcf69 << 16) | 0x2694);
- sha512_round(&r, w, (0xe49b << 48) | (0x69c1 << 32) | (0x9ef1 << 16) | 0x4ad2);
- sha512_round(&r, w, (0xefbe << 48) | (0x4786 << 32) | (0x384f << 16) | 0x25e3);
- sha512_round(&r, w, (0x0fc1 << 48) | (0x9dc6 << 32) | (0x8b8c << 16) | 0xd5b5);
- sha512_round(&r, w, (0x240c << 48) | (0xa1cc << 32) | (0x77ac << 16) | 0x9c65);
- sha512_round(&r, w, (0x2de9 << 48) | (0x2c6f << 32) | (0x592b << 16) | 0x0275);
- sha512_round(&r, w, (0x4a74 << 48) | (0x84aa << 32) | (0x6ea6 << 16) | 0xe483);
- sha512_round(&r, w, (0x5cb0 << 48) | (0xa9dc << 32) | (0xbd41 << 16) | 0xfbd4);
- sha512_round(&r, w, (0x76f9 << 48) | (0x88da << 32) | (0x8311 << 16) | 0x53b5);
- sha512_round(&r, w, (0x983e << 48) | (0x5152 << 32) | (0xee66 << 16) | 0xdfab);
- sha512_round(&r, w, (0xa831 << 48) | (0xc66d << 32) | (0x2db4 << 16) | 0x3210);
- sha512_round(&r, w, (0xb003 << 48) | (0x27c8 << 32) | (0x98fb << 16) | 0x213f);
- sha512_round(&r, w, (0xbf59 << 48) | (0x7fc7 << 32) | (0xbeef << 16) | 0x0ee4);
- sha512_round(&r, w, (0xc6e0 << 48) | (0x0bf3 << 32) | (0x3da8 << 16) | 0x8fc2);
- sha512_round(&r, w, (0xd5a7 << 48) | (0x9147 << 32) | (0x930a << 16) | 0xa725);
- sha512_round(&r, w, (0x06ca << 48) | (0x6351 << 32) | (0xe003 << 16) | 0x826f);
- sha512_round(&r, w, (0x1429 << 48) | (0x2967 << 32) | (0x0a0e << 16) | 0x6e70);
- sha512_round(&r, w, (0x27b7 << 48) | (0x0a85 << 32) | (0x46d2 << 16) | 0x2ffc);
- sha512_round(&r, w, (0x2e1b << 48) | (0x2138 << 32) | (0x5c26 << 16) | 0xc926);
- sha512_round(&r, w, (0x4d2c << 48) | (0x6dfc << 32) | (0x5ac4 << 16) | 0x2aed);
- sha512_round(&r, w, (0x5338 << 48) | (0x0d13 << 32) | (0x9d95 << 16) | 0xb3df);
- sha512_round(&r, w, (0x650a << 48) | (0x7354 << 32) | (0x8baf << 16) | 0x63de);
- sha512_round(&r, w, (0x766a << 48) | (0x0abb << 32) | (0x3c77 << 16) | 0xb2a8);
- sha512_round(&r, w, (0x81c2 << 48) | (0xc92e << 32) | (0x47ed << 16) | 0xaee6);
- sha512_round(&r, w, (0x9272 << 48) | (0x2c85 << 32) | (0x1482 << 16) | 0x353b);
- sha512_round(&r, w, (0xa2bf << 48) | (0xe8a1 << 32) | (0x4cf1 << 16) | 0x0364);
- sha512_round(&r, w, (0xa81a << 48) | (0x664b << 32) | (0xbc42 << 16) | 0x3001);
- sha512_round(&r, w, (0xc24b << 48) | (0x8b70 << 32) | (0xd0f8 << 16) | 0x9791);
- sha512_round(&r, w, (0xc76c << 48) | (0x51a3 << 32) | (0x0654 << 16) | 0xbe30);
- sha512_round(&r, w, (0xd192 << 48) | (0xe819 << 32) | (0xd6ef << 16) | 0x5218);
- sha512_round(&r, w, (0xd699 << 48) | (0x0624 << 32) | (0x5565 << 16) | 0xa910);
- sha512_round(&r, w, (0xf40e << 48) | (0x3585 << 32) | (0x5771 << 16) | 0x202a);
- sha512_round(&r, w, (0x106a << 48) | (0xa070 << 32) | (0x32bb << 16) | 0xd1b8);
- sha512_round(&r, w, (0x19a4 << 48) | (0xc116 << 32) | (0xb8d2 << 16) | 0xd0c8);
- sha512_round(&r, w, (0x1e37 << 48) | (0x6c08 << 32) | (0x5141 << 16) | 0xab53);
- sha512_round(&r, w, (0x2748 << 48) | (0x774c << 32) | (0xdf8e << 16) | 0xeb99);
- sha512_round(&r, w, (0x34b0 << 48) | (0xbcb5 << 32) | (0xe19b << 16) | 0x48a8);
- sha512_round(&r, w, (0x391c << 48) | (0x0cb3 << 32) | (0xc5c9 << 16) | 0x5a63);
- sha512_round(&r, w, (0x4ed8 << 48) | (0xaa4a << 32) | (0xe341 << 16) | 0x8acb);
- sha512_round(&r, w, (0x5b9c << 48) | (0xca4f << 32) | (0x7763 << 16) | 0xe373);
- sha512_round(&r, w, (0x682e << 48) | (0x6ff3 << 32) | (0xd6b2 << 16) | 0xb8a3);
- sha512_round(&r, w, (0x748f << 48) | (0x82ee << 32) | (0x5def << 16) | 0xb2fc);
- sha512_round(&r, w, (0x78a5 << 48) | (0x636f << 32) | (0x4317 << 16) | 0x2f60);
- sha512_round(&r, w, (0x84c8 << 48) | (0x7814 << 32) | (0xa1f0 << 16) | 0xab72);
- sha512_round(&r, w, (0x8cc7 << 48) | (0x0208 << 32) | (0x1a64 << 16) | 0x39ec);
- sha512_round(&r, w, (0x90be << 48) | (0xfffa << 32) | (0x2363 << 16) | 0x1e28);
- sha512_round(&r, w, (0xa450 << 48) | (0x6ceb << 32) | (0xde82 << 16) | 0xbde9);
- sha512_round(&r, w, (0xbef9 << 48) | (0xa3f7 << 32) | (0xb2c6 << 16) | 0x7915);
- sha512_round(&r, w, (0xc671 << 48) | (0x78f2 << 32) | (0xe372 << 16) | 0x532b);
- sha512_round(&r, w, (0xca27 << 48) | (0x3ece << 32) | (0xea26 << 16) | 0x619c);
- sha512_round(&r, w, (0xd186 << 48) | (0xb8c7 << 32) | (0x21c0 << 16) | 0xc207);
- sha512_round(&r, w, (0xeada << 48) | (0x7dd6 << 32) | (0xcde0 << 16) | 0xeb1e);
- sha512_round(&r, w, (0xf57d << 48) | (0x4f7f << 32) | (0xee6e << 16) | 0xd178);
- sha512_round(&r, w, (0x06f0 << 48) | (0x67aa << 32) | (0x7217 << 16) | 0x6fba);
- sha512_round(&r, w, (0x0a63 << 48) | (0x7dc5 << 32) | (0xa2c8 << 16) | 0x98a6);
- sha512_round(&r, w, (0x113f << 48) | (0x9804 << 32) | (0xbef9 << 16) | 0x0dae);
- sha512_round(&r, w, (0x1b71 << 48) | (0x0b35 << 32) | (0x131c << 16) | 0x471b);
- sha512_round(&r, w, (0x28db << 48) | (0x77f5 << 32) | (0x2304 << 16) | 0x7d84);
- sha512_round(&r, w, (0x32ca << 48) | (0xab7b << 32) | (0x40c7 << 16) | 0x2493);
- sha512_round(&r, w, (0x3c9e << 48) | (0xbe0a << 32) | (0x15c9 << 16) | 0xbebc);
- sha512_round(&r, w, (0x431d << 48) | (0x67c4 << 32) | (0x9c10 << 16) | 0x0d4c);
- sha512_round(&r, w, (0x4cc5 << 48) | (0xd4be << 32) | (0xcb3e << 16) | 0x42b6);
- sha512_round(&r, w, (0x597f << 48) | (0x299c << 32) | (0xfc65 << 16) | 0x7e2a);
- sha512_round(&r, w, (0x5fcb << 48) | (0x6fab << 32) | (0x3ad6 << 16) | 0xfaec);
- sha512_round(&r, w, (0x6c44 << 48) | (0x198c << 32) | (0x4a47 << 16) | 0x5817);
+ sha512_round(&r, w, (0x428a2f98 << 32) | 0xd728ae22);
+ sha512_round(&r, w, (0x71374491 << 32) | 0x23ef65cd);
+ sha512_round(&r, w, (0xb5c0fbcf << 32) | 0xec4d3b2f);
+ sha512_round(&r, w, (0xe9b5dba5 << 32) | 0x8189dbbc);
+ sha512_round(&r, w, (0x3956c25b << 32) | 0xf348b538);
+ sha512_round(&r, w, (0x59f111f1 << 32) | 0xb605d019);
+ sha512_round(&r, w, (0x923f82a4 << 32) | 0xaf194f9b);
+ sha512_round(&r, w, (0xab1c5ed5 << 32) | 0xda6d8118);
+ sha512_round(&r, w, (0xd807aa98 << 32) | 0xa3030242);
+ sha512_round(&r, w, (0x12835b01 << 32) | 0x45706fbe);
+ sha512_round(&r, w, (0x243185be << 32) | 0x4ee4b28c);
+ sha512_round(&r, w, (0x550c7dc3 << 32) | 0xd5ffb4e2);
+ sha512_round(&r, w, (0x72be5d74 << 32) | 0xf27b896f);
+ sha512_round(&r, w, (0x80deb1fe << 32) | 0x3b1696b1);
+ sha512_round(&r, w, (0x9bdc06a7 << 32) | 0x25c71235);
+ sha512_round(&r, w, (0xc19bf174 << 32) | 0xcf692694);
+ sha512_round(&r, w, (0xe49b69c1 << 32) | 0x9ef14ad2);
+ sha512_round(&r, w, (0xefbe4786 << 32) | 0x384f25e3);
+ sha512_round(&r, w, (0x0fc19dc6 << 32) | 0x8b8cd5b5);
+ sha512_round(&r, w, (0x240ca1cc << 32) | 0x77ac9c65);
+ sha512_round(&r, w, (0x2de92c6f << 32) | 0x592b0275);
+ sha512_round(&r, w, (0x4a7484aa << 32) | 0x6ea6e483);
+ sha512_round(&r, w, (0x5cb0a9dc << 32) | 0xbd41fbd4);
+ sha512_round(&r, w, (0x76f988da << 32) | 0x831153b5);
+ sha512_round(&r, w, (0x983e5152 << 32) | 0xee66dfab);
+ sha512_round(&r, w, (0xa831c66d << 32) | 0x2db43210);
+ sha512_round(&r, w, (0xb00327c8 << 32) | 0x98fb213f);
+ sha512_round(&r, w, (0xbf597fc7 << 32) | 0xbeef0ee4);
+ sha512_round(&r, w, (0xc6e00bf3 << 32) | 0x3da88fc2);
+ sha512_round(&r, w, (0xd5a79147 << 32) | 0x930aa725);
+ sha512_round(&r, w, (0x06ca6351 << 32) | 0xe003826f);
+ sha512_round(&r, w, (0x14292967 << 32) | 0x0a0e6e70);
+ sha512_round(&r, w, (0x27b70a85 << 32) | 0x46d22ffc);
+ sha512_round(&r, w, (0x2e1b2138 << 32) | 0x5c26c926);
+ sha512_round(&r, w, (0x4d2c6dfc << 32) | 0x5ac42aed);
+ sha512_round(&r, w, (0x53380d13 << 32) | 0x9d95b3df);
+ sha512_round(&r, w, (0x650a7354 << 32) | 0x8baf63de);
+ sha512_round(&r, w, (0x766a0abb << 32) | 0x3c77b2a8);
+ sha512_round(&r, w, (0x81c2c92e << 32) | 0x47edaee6);
+ sha512_round(&r, w, (0x92722c85 << 32) | 0x1482353b);
+ sha512_round(&r, w, (0xa2bfe8a1 << 32) | 0x4cf10364);
+ sha512_round(&r, w, (0xa81a664b << 32) | 0xbc423001);
+ sha512_round(&r, w, (0xc24b8b70 << 32) | 0xd0f89791);
+ sha512_round(&r, w, (0xc76c51a3 << 32) | 0x0654be30);
+ sha512_round(&r, w, (0xd192e819 << 32) | 0xd6ef5218);
+ sha512_round(&r, w, (0xd6990624 << 32) | 0x5565a910);
+ sha512_round(&r, w, (0xf40e3585 << 32) | 0x5771202a);
+ sha512_round(&r, w, (0x106aa070 << 32) | 0x32bbd1b8);
+ sha512_round(&r, w, (0x19a4c116 << 32) | 0xb8d2d0c8);
+ sha512_round(&r, w, (0x1e376c08 << 32) | 0x5141ab53);
+ sha512_round(&r, w, (0x2748774c << 32) | 0xdf8eeb99);
+ sha512_round(&r, w, (0x34b0bcb5 << 32) | 0xe19b48a8);
+ sha512_round(&r, w, (0x391c0cb3 << 32) | 0xc5c95a63);
+ sha512_round(&r, w, (0x4ed8aa4a << 32) | 0xe3418acb);
+ sha512_round(&r, w, (0x5b9cca4f << 32) | 0x7763e373);
+ sha512_round(&r, w, (0x682e6ff3 << 32) | 0xd6b2b8a3);
+ sha512_round(&r, w, (0x748f82ee << 32) | 0x5defb2fc);
+ sha512_round(&r, w, (0x78a5636f << 32) | 0x43172f60);
+ sha512_round(&r, w, (0x84c87814 << 32) | 0xa1f0ab72);
+ sha512_round(&r, w, (0x8cc70208 << 32) | 0x1a6439ec);
+ sha512_round(&r, w, (0x90befffa << 32) | 0x23631e28);
+ sha512_round(&r, w, (0xa4506ceb << 32) | 0xde82bde9);
+ sha512_round(&r, w, (0xbef9a3f7 << 32) | 0xb2c67915);
+ sha512_round(&r, w, (0xc67178f2 << 32) | 0xe372532b);
+ sha512_round(&r, w, (0xca273ece << 32) | 0xea26619c);
+ sha512_round(&r, w, (0xd186b8c7 << 32) | 0x21c0c207);
+ sha512_round(&r, w, (0xeada7dd6 << 32) | 0xcde0eb1e);
+ sha512_round(&r, w, (0xf57d4f7f << 32) | 0xee6ed178);
+ sha512_round(&r, w, (0x06f067aa << 32) | 0x72176fba);
+ sha512_round(&r, w, (0x0a637dc5 << 32) | 0xa2c898a6);
+ sha512_round(&r, w, (0x113f9804 << 32) | 0xbef90dae);
+ sha512_round(&r, w, (0x1b710b35 << 32) | 0x131c471b);
+ sha512_round(&r, w, (0x28db77f5 << 32) | 0x23047d84);
+ sha512_round(&r, w, (0x32caab7b << 32) | 0x40c72493);
+ sha512_round(&r, w, (0x3c9ebe0a << 32) | 0x15c9bebc);
+ sha512_round(&r, w, (0x431d67c4 << 32) | 0x9c100d4c);
+ sha512_round(&r, w, (0x4cc5d4be << 32) | 0xcb3e42b6);
+ sha512_round(&r, w, (0x597f299c << 32) | 0xfc657e2a);
+ sha512_round(&r, w, (0x5fcb6fab << 32) | 0x3ad6faec);
+ sha512_round(&r, w, (0x6c44198c << 32) | 0x4a475817);
ctx.a = ctx.a + r.a;
ctx.b = ctx.b + r.b;