Skip to content

Commit

Permalink
Use FIPS compliant SHA1 (#944)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbevain authored May 21, 2024
1 parent fec4ee9 commit dff01d9
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Mono.Security.Cryptography/CryptoService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace Mono.Cecil {

static class CryptoService {

static SHA1 CreateSHA1 () => new SHA1CryptoServiceProvider ();

public static byte [] GetPublicKey (WriterParameters parameters)
{
using (var rsa = parameters.CreateRSA ()) {
Expand Down Expand Up @@ -93,7 +95,7 @@ static byte [] HashStream (Stream stream, ImageWriter writer, out int strong_nam
+ (strong_name_directory.VirtualAddress - text.VirtualAddress));
var strong_name_length = (int) strong_name_directory.Size;

var sha1 = new SHA1Managed ();
var sha1 = CreateSHA1 ();
var buffer = new byte [buffer_size];
using (var crypto_stream = new CryptoStream (Stream.Null, sha1, CryptoStreamMode.Write)) {
stream.Seek (0, SeekOrigin.Begin);
Expand Down Expand Up @@ -131,7 +133,7 @@ public static byte [] ComputeHash (Stream stream)
{
const int buffer_size = 8192;

var sha1 = new SHA1Managed ();
var sha1 = CreateSHA1 ();
var buffer = new byte [buffer_size];

using (var crypto_stream = new CryptoStream (Stream.Null, sha1, CryptoStreamMode.Write))
Expand All @@ -142,7 +144,7 @@ public static byte [] ComputeHash (Stream stream)

public static byte [] ComputeHash (params ByteBuffer [] buffers)
{
var sha1 = new SHA1Managed ();
var sha1 = CreateSHA1 ();

using (var crypto_stream = new CryptoStream (Stream.Null, sha1, CryptoStreamMode.Write)) {
for (int i = 0; i < buffers.Length; i++) {
Expand Down

0 comments on commit dff01d9

Please sign in to comment.