VirtualBox

source: vbox/trunk/src/libs/openssl-3.0.3/test/recipes/91-test_pkey_check.t@ 95792

Last change on this file since 95792 was 94320, checked in by vboxsync, 3 years ago

libs/openssl-3.0.1: Export to OSE and fix copyright headers in Makefiles, bugref:10128

File size: 1.6 KB
Line 
1#! /usr/bin/env perl
2# Copyright 2017-2021 The OpenSSL Project Authors. All Rights Reserved.
3#
4# Licensed under the Apache License 2.0 (the "License"). You may not use
5# this file except in compliance with the License. You can obtain a copy
6# in the file LICENSE in the source distribution or at
7# https://www.openssl.org/source/license.html
8
9
10use strict;
11use warnings;
12
13use File::Spec;
14use OpenSSL::Test qw/:DEFAULT data_file/;
15use OpenSSL::Test::Utils;
16
17sub check_key {
18 my $f = shift;
19
20 return run(app(['openssl', 'pkey', '-check', '-text',
21 '-in', $f]));
22}
23
24sub check_key_notok {
25 my $f = shift;
26 my $str = "$f should fail validation";
27
28 $f = data_file($f);
29
30 if ( -s $f ) {
31 ok(!check_key($f), $str);
32 } else {
33 fail("Missing file $f");
34 }
35}
36
37setup("test_pkey_check");
38
39my @tests = ();
40
41push(@tests, (
42 # For EC keys the range for the secret scalar `k` is `1 <= k <= n-1`
43 "ec_p256_bad_0.pem", # `k` set to `n` (equivalent to `0 mod n`, invalid)
44 "ec_p256_bad_1.pem", # `k` set to `n+1` (equivalent to `1 mod n`, invalid)
45 )) unless disabled("ec");
46
47push(@tests, (
48 # For SM2 keys the range for the secret scalar `k` is `1 <= k < n-1`
49 "sm2_bad_neg1.pem", # `k` set to `n-1` (invalid, because SM2 range)
50 "sm2_bad_0.pem", # `k` set to `n` (equivalent to `0 mod n`, invalid)
51 "sm2_bad_1.pem", # `k` set to `n+1` (equivalent to `1 mod n`, invalid)
52 )) unless disabled("sm2");
53
54plan skip_all => "No tests within the current enabled feature set"
55 unless @tests;
56
57plan tests => scalar(@tests);
58
59foreach my $t (@tests) {
60 check_key_notok($t);
61}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette