1*b0d17251Schristos#! /usr/bin/env perl 2*b0d17251Schristos# Copyright 2021 The OpenSSL Project Authors. All Rights Reserved. 3*b0d17251Schristos# 4*b0d17251Schristos# Licensed under the Apache License 2.0 (the "License"). You may not use 5*b0d17251Schristos# this file except in compliance with the License. You can obtain a copy 6*b0d17251Schristos# in the file LICENSE in the source distribution or at 7*b0d17251Schristos# https://www.openssl.org/source/license.html 8*b0d17251Schristos 9*b0d17251Schristosuse Getopt::Long; 10*b0d17251Schristos 11*b0d17251Schristosmy $activate = 1; 12*b0d17251Schristosmy $conditional_errors = 1; 13*b0d17251Schristosmy $security_checks = 1; 14*b0d17251Schristosmy $mac_key; 15*b0d17251Schristosmy $module_name; 16*b0d17251Schristosmy $section_name = "fips_sect"; 17*b0d17251Schristos 18*b0d17251SchristosGetOptions("key=s" => \$mac_key, 19*b0d17251Schristos "module=s" => \$module_name, 20*b0d17251Schristos "section_name=s" => \$section_name) 21*b0d17251Schristos or die "Error when getting command line arguments"; 22*b0d17251Schristos 23*b0d17251Schristosmy $mac_keylen = length($mac_key); 24*b0d17251Schristos 25*b0d17251Schristosuse Digest::SHA qw(hmac_sha256_hex); 26*b0d17251Schristosmy $module_size = [ stat($module_name) ]->[7]; 27*b0d17251Schristos 28*b0d17251Schristosopen my $fh, "<:raw", $module_name or die "Trying to open $module_name: $!"; 29*b0d17251Schristosread $fh, my $data, $module_size or die "Trying to read $module_name: $!"; 30*b0d17251Schristosclose $fh; 31*b0d17251Schristos 32*b0d17251Schristos# Calculate HMAC-SHA256 in hex, and split it into a list of two character 33*b0d17251Schristos# chunks, and join the chunks with colons. 34*b0d17251Schristosmy @module_mac 35*b0d17251Schristos = ( uc(hmac_sha256_hex($data, pack("H$mac_keylen", $mac_key))) =~ m/../g ); 36*b0d17251Schristosmy $module_mac = join(':', @module_mac); 37*b0d17251Schristos 38*b0d17251Schristosprint <<_____; 39*b0d17251Schristos[$section_name] 40*b0d17251Schristosactivate = $activate 41*b0d17251Schristosconditional-errors = $conditional_errors 42*b0d17251Schristossecurity-checks = $security_checks 43*b0d17251Schristosmodule-mac = $module_mac 44*b0d17251Schristos_____ 45