You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dateKeys-dart/test/authorkey_vm_test.dart

50 lines
1.4 KiB

Stage 7b: the author keys and Ed25519 signing ed25519_sign.dart signs as crypto_sign of TweetNaCl in its JavaScript port, with the SHA-512 of package:crypto: the field of curve25519.dart, whose arithmetic is private there, copied with the product as a loop, and modL over 64 limbs of 8 bits in a Float64List, with floor divisions in place of the shifts of TweetNaCl, exact on the VM and on the web. The secret scalar and the nonce never meet a BigInt or a branch; neither platform promises constant time, and the values are wiped as a best effort. authorkey.dart ports package authorkey of datekeys-go: AuthorKey with generate, fromSeed, publicKey, sign, clear and secret, and a toString that hides it; authorPublicString, parseAuthorPublic and parseAuthorSecret, also on the bytes of a Go string; marshalAuthorKey; encryptAuthorKey, scrypt with logN 16 through ScryptRecipient and ageEncrypt of stage 6a; and readAuthorKey, through the age reader with a maximum work factor of 16, whose lines are those of bufio.Scanner and strings.TrimSpace. Every error has the text of Go, with the sets of go_unicode.dart for the case of a string and the spaces of a line. A cleared key refuses every use, where Go would give the values of a key of zeros. tool/authorkey_go_vectors.go writes test/vectors/authorkey.json: the signatures of crypto/ed25519 over lines of sign.input (RFC 8032 tests 1, 2, 3 and 1024), TEST SHA(abc), seeded seeds and messages up to 1 MiB and other public keys; the scalars of math/big; and Generate, Encrypt, ParsePublic, ParseSecret and Read of authorkey with each text, while crypto/rand reads the keystream of SeededRandomSource. Dart writes the same bytes and gives the same texts in every case; authorkey.g.dart, a part of it, runs also in Node.js. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 day ago
// The author keys against the whole of test/vectors/authorkey.json, on the
// VM: the signatures and the rune cases that authorkey.g.dart leaves out,
// among them the messages of 64 KiB and 1 MiB; and authorkey.g.dart
// checked against the file, of which it is a part.
@TestOn('vm')
library;
import 'dart:convert';
import 'dart:io';
import 'package:test/test.dart';
import 'authorkey_support.dart';
import 'vectors/authorkey.g.dart';
void main() {
final file = jsonDecode(
File('test/vectors/authorkey.json').readAsStringSync(),
) as Json;
final part = jsonDecode(authorKeyJson) as Json;
test('authorkey.g.dart is a part of authorkey.json', () {
for (final k in file.keys) {
if (k == 'sign' || k == 'runes') continue;
expect(part[k], file[k], reason: k);
}
expect(part.keys.toSet(), file.keys.toSet());
expect(part['sign'], [
for (final c in listOf(file['sign']))
if (c['node'] == true) c,
]);
final runes = file['runes']! as Json;
final some = part['runes']! as Json;
expect(some['public'], runes['public']);
expect(some['secret'], runes['secret']);
final all = {for (final c in runes['cases']! as List) jsonEncode(c)};
final cases = some['cases']! as List;
expect(cases, isNotEmpty);
for (final c in cases) {
expect(all, contains(jsonEncode(c)));
}
});
signTests([
for (final c in listOf(file['sign']))
if (c['node'] != true) c,
]);
runeTests(file);
}

Powered by TurnKey Linux.