-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsg_setup_test.dart
55 lines (41 loc) · 1.61 KB
/
msg_setup_test.dart
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
import 'dart:convert';
import 'dart:math';
import 'dart:typed_data';
import 'package:dilithium_crypto/dilithium_crypto.dart';
import 'package:test/test.dart';
void main() {
late DilithiumKeyPair keyPair;
setUpAll(() {
final random = Random.secure();
final seed = Uint8List.fromList(
List<int>.generate(Dilithium.SEEDBYTES, (_) => random.nextInt(256)));
keyPair = Dilithium.generateKeyPair(DilithiumParameterSpec.LEVEL3, seed);
});
group('encode message as Uint8List', () {
test('string msg', () {
String stringMsg = 'Hello World!';
Uint8List byteMsg = utf8.encode(stringMsg);
final signature = Dilithium.sign(keyPair.privateKey, byteMsg);
final isValid = Dilithium.verify(keyPair.publicKey, signature, byteMsg);
expect(isValid, isTrue);
});
test('int msg', () {
ByteData byteData = ByteData(8); // 8 bytes for int (int64)
int intMsg = 1234567890;
byteData.setInt64(0, intMsg);
Uint8List byteMsg = byteData.buffer.asUint8List();
final signature = Dilithium.sign(keyPair.privateKey, byteMsg);
final isValid = Dilithium.verify(keyPair.publicKey, signature, byteMsg);
expect(isValid, isTrue);
});
test('double msg', () {
ByteData byteData = ByteData(8); // 8 bytes for double
double doubleMsg = 3.141592653589793;
byteData.setFloat64(0, doubleMsg);
Uint8List byteMsg = byteData.buffer.asUint8List();
final signature = Dilithium.sign(keyPair.privateKey, byteMsg);
final isValid = Dilithium.verify(keyPair.publicKey, signature, byteMsg);
expect(isValid, isTrue);
});
});
}