Skip to content

Commit df912ed

Browse files
committed
Moves some of the tests to "cryptography_test".
1 parent aa878f5 commit df912ed

File tree

28 files changed

+1256
-1734
lines changed

28 files changed

+1256
-1734
lines changed

cryptography/lib/src/dart/blake2s.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,12 @@ class _Blake2sSink extends DartHashSink {
7575
late final Uint8List _bufferAsBytes = Uint8List.view(_buffer.buffer);
7676

7777
bool _isClosed = false;
78+
7879
_Blake2sSink() {
7980
checkSystemIsLittleEndian();
8081
_initializeH(_hash);
8182
}
83+
8284
@override
8385
bool get isClosed => _isClosed;
8486

cryptography/test/algorithms/aes_gcm_test.dart

Lines changed: 0 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import 'dart:typed_data';
16-
1715
import 'package:cryptography/cryptography.dart';
1816
import 'package:cryptography/dart.dart';
1917
import 'package:cryptography/src/_internal/hex.dart';
@@ -750,121 +748,4 @@ void _main() {
750748
});
751749
});
752750
});
753-
754-
Future<void> testRounds({
755-
required AesGcm algorithm,
756-
List<int> aad = const [],
757-
int rounds = 1000,
758-
required String expectedHex,
759-
}) async {
760-
var secretKeyBytes = hexToBytes(
761-
'02020202020202020202020202020202'
762-
'02020202020202020202020202020202',
763-
).sublist(0, algorithm.secretKeyLength);
764-
var nonce = hexToBytes(
765-
'03030303030303030303030303030303',
766-
);
767-
final hashAlgorithm = Sha256();
768-
769-
var data = List<int>.filled(rounds + 1000, 1);
770-
late Mac mac;
771-
for (var i = 0; i < rounds; i++) {
772-
// Encrypt
773-
final secretBox = await algorithm.encrypt(
774-
data,
775-
secretKey: SecretKey(secretKeyBytes),
776-
nonce: nonce,
777-
aad: aad,
778-
);
779-
expect(secretBox.nonce, nonce);
780-
mac = secretBox.mac;
781-
expect(mac.bytes, hasLength(16));
782-
783-
// Test that decryption works
784-
final decryptedSecretBox = await algorithm.decrypt(
785-
secretBox,
786-
secretKey: SecretKey(secretKeyBytes),
787-
aad: aad,
788-
);
789-
expect(decryptedSecretBox, data);
790-
791-
// Change data.
792-
// Put MAC somewhere in the data.
793-
data = Uint8List.fromList(secretBox.cipherText);
794-
data.setRange(100, 100 + 16, secretBox.mac.bytes);
795-
796-
// Change size for the next round
797-
data = data.sublist(1);
798-
799-
// Change secret key
800-
secretKeyBytes = (await hashAlgorithm.hash(data))
801-
.bytes
802-
.sublist(0, algorithm.secretKeyLength);
803-
804-
// Change nonce
805-
nonce = (await hashAlgorithm.hash(secretKeyBytes)).bytes.sublist(0, 12);
806-
}
807-
808-
expect(data, hasLength(1000));
809-
final hash = await hashAlgorithm.hash(data);
810-
expect(
811-
hexFromBytes(hash.bytes),
812-
expectedHex,
813-
);
814-
815-
// We don't need to test MAC because its part of the clearText at each round
816-
// after the first one.
817-
}
818-
819-
//
820-
// The following test vectors were calculated with Web Cryptography API.
821-
//
822-
823-
test('AesGcm.with128bits(): 1 000 cycles', () async {
824-
await testRounds(
825-
algorithm: AesGcm.with128bits(),
826-
expectedHex: ''
827-
'f3 52 fb 3f a0 3d 70 25 f3 0f 48 01 eb 3a d2 85\n'
828-
'89 53 06 4d 8c 53 25 38 96 ca 71 c2 90 f0 3b 06',
829-
);
830-
});
831-
832-
test('AesGcm.with128bits(): 1 000 cycles, AAD', () async {
833-
await testRounds(
834-
algorithm: AesGcm.with128bits(),
835-
aad: [1, 2, 3],
836-
expectedHex: ''
837-
'e5 a3 57 59 6c 11 c0 ab 18 e6 b3 f5 71 6a f9 46\n'
838-
'25 ce 95 7d eb 29 c4 bf 24 80 6d 33 e2 f5 1f 2b',
839-
);
840-
});
841-
842-
test('AesGcm.with192bits(): 1 000 cycles, AAD', () async {
843-
await testRounds(
844-
algorithm: AesGcm.with192bits(),
845-
aad: [1, 2, 3],
846-
expectedHex: ''
847-
'76 5d 6c 02 16 56 a0 ef 22 e1 97 5c 4b 81 fc 36\n'
848-
'2b 9c 5a da d9 2d 6c d5 c9 94 c7 a2 c8 73 e7 ab',
849-
);
850-
});
851-
852-
test('AesGcm.with256bits(): 1 000 cycles', () async {
853-
await testRounds(
854-
algorithm: AesGcm.with256bits(),
855-
expectedHex: ''
856-
'2e f9 45 f9 4b 94 43 d9 1a 43 3d c2 e4 40 c0 0f\n'
857-
'20 27 0d 93 3d 47 ae 44 41 29 6e 3c 32 27 97 ef',
858-
);
859-
});
860-
861-
test('AesGcm.with256bits(): 1 000 cycles, AAD', () async {
862-
await testRounds(
863-
algorithm: AesGcm.with256bits(),
864-
aad: [1, 2, 3],
865-
expectedHex: ''
866-
'52 dd c6 e5 07 65 f1 46 7e 1c 5a f5 9f cb 0c 69\n'
867-
'84 11 c1 52 83 08 b5 3b 19 28 d5 79 bd 2f aa c7',
868-
);
869-
});
870751
}

cryptography/test/algorithms/ecdh_test.dart

Lines changed: 0 additions & 201 deletions
This file was deleted.

cryptography/test/algorithms/ed25519_impl_test.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ import 'package:cryptography/src/dart/ed25519_impl.dart';
1616
import 'package:test/test.dart';
1717

1818
void main() {
19+
// ---------------------------------------------------------------------------
20+
//
21+
// IMPORTANT:
22+
//
23+
// We've migrated most of the tests to 'cryptography_test'.
24+
// This file is only for tests that are specific to the 'cryptography'
25+
// package.
26+
//
27+
// ---------------------------------------------------------------------------
1928
group('Register25519', () {
2029
final modulo = BigInt.two.pow(255) - BigInt.from(19);
2130

0 commit comments

Comments
 (0)