Update code to v1.0.14 (10)

This commit is contained in:
Caten
2024-02-29 19:35:00 +08:00
parent c2ee3b694c
commit a956d26f6d
3188 changed files with 2317293 additions and 146 deletions

View File

@@ -0,0 +1,52 @@
#!/bin/bash
function usage(){
cat << _EOT_
Usage :
$0 [-g] [-]
Description:
Generate 2048 bit Rsa key pair and Display modulus and public exponent
Options:
-g generate rsa key pair, default on
-s only show modulus and public exponent
_EOT_
exit 1
}
FLAG_G="on"
FLAG_S="off"
while getopts gsh OPT
do
case $OPT in
g)
FLAG_G="on"
;;
s)
FLAG_S="on"
FLAG_G="off"
;;
h)
usage
;;
\?)
usage
;;
esac
done
if [ $FLAG_G = "on" ]; then
# generate 2048bit Rsa private key
openssl genrsa 2048 2> /dev/null > private-key.pem
# expose public key
openssl rsa -in private-key.pem -pubout -out public-key.pem 2> /dev/null
fi
if [ $FLAG_S = "on" ]; then
# display modulus and exponent
openssl rsa -modulus < private-key.pem 2>/dev/null | grep Modulus=
openssl rsa -text < private-key.pem 2> /dev/null | grep publicExponent
fi

View File

@@ -0,0 +1,89 @@
#!/usr/bin/perl
# genhexbuf.pl
# Copyright (C) 2020 wolfSSL Inc.
#
use strict;
use warnings;
# ---- SCRIPT SETTINGS -------------------------------------------------------
# output C header file to write cert/key buffers to
my $outputFile = "certs_sig_data.h";
# rsa keys and certs to be converted
my @fileList = (
# please add your der file and name of the data for C language
# der file name name of the data
#[ "./yourder.der", "your_der_name_in_C" ],
[ "./ca-cert.der", "ca_cert_der" ],
[ "./ca-cert.der.sign", "ca_cert_der_sign" ],
);
# ----------------------------------------------------------------------------
my $num = @fileList;
# open our output file, "+>" creates and/or truncates
open OUT_FILE, "+>", $outputFile or die $!;
print OUT_FILE "/* certs_sig_data.h */\n\n";
print OUT_FILE "#ifndef WOLFSSL_CERTS_SIG_DATA_H\n";
print OUT_FILE "#define WOLFSSL_CERTS_SIG_DATA_H\n\n";
# convert and print 1024-bit cert/keys
for (my $i = 0; $i < $num; $i++) {
my $fname = $fileList[$i][0];
my $sname = $fileList[$i][1];
print OUT_FILE "/* $fname, */\n";
print OUT_FILE "static const unsigned char $sname\[] =\n";
print OUT_FILE "{\n";
file_to_hex($fname);
print OUT_FILE "};\n";
print OUT_FILE "static const int sizeof_$sname = sizeof($sname);\n\n";
}
print OUT_FILE "#endif /* WOLFSSL_CERTS_SIG_DATA_H */\n\n";
# print file as hex, comma-separated, as needed by C buffer
sub file_to_hex {
my $fileName = $_[0];
open my $fp, "<", $fileName or die $!;
binmode($fp);
my $fileLen = -s $fileName;
my $byte;
for (my $i = 0, my $j = 1; $i < $fileLen; $i++, $j++)
{
if ($j == 1) {
print OUT_FILE " ";
}
if ($j != 1) {
print OUT_FILE " ";
}
read($fp, $byte, 1) or die "Error reading $fileName";
my $output = sprintf("0x%02X", ord($byte));
print OUT_FILE $output;
if ($i != ($fileLen - 1)) {
print OUT_FILE ",";
}
if ($j == 10) {
$j = 0;
print OUT_FILE "\n";
}
}
print OUT_FILE "\n";
close($fp);
}

View File

@@ -0,0 +1,34 @@
#!/bin/bash
SIGOPT=rsa_padding_mode:pss
SIGOPT2=rsa_pss_saltlen:-1
function usage() {
cat <<_EOT_
Usage:
$0 <pri key> <pub key> <file name>
pri key : private key for sign/verify
pub key : public key for sign/verify
file name : file name to be signed
_EOT_
exit 1
}
if [ $# -ne 3 ]; then
usage
fi
# $1 private key for sign/verify
# $2 public key for verify
# $3 file for sign/verify
openssl dgst -sha256 -sign $1 -sigopt $SIGOPT -sigopt $SIGOPT2 -out $3.sign $3
echo verify by private key
openssl dgst -sha256 -prverify $1 -sigopt $SIGOPT -sigopt $SIGOPT2 -signature $3.sign $3
echo verifiy by public key
openssl dgst -sha256 -verify $2 -sigopt $SIGOPT -sigopt $SIGOPT2 -signature $3.sign $3