Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Ask only once about the availability of an algorithm since it can be …

…costly to do so each time (e.g. if the instance are not reused)
  • Loading branch information...
commit ec5d81236f6809758ad6d99af40c69aae854421c 1 parent d96fbed
@spouliot spouliot authored
Showing with 15 additions and 7 deletions.
  1. +15 −7 class/Crimson.CryptoDev/Crimson.CryptoDev/Helper.cs
View
22 class/Crimson.CryptoDev/Crimson.CryptoDev/Helper.cs
@@ -25,6 +25,7 @@
//
using System;
+using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
@@ -106,11 +107,18 @@ static public bool IsAvailable (Cipher algo)
return true;
return Is (algo, KernelMode.Ocf);
}
+
+ static HashSet<long> availability = new HashSet<long> ();
static bool Is (Cipher algo, KernelMode mode)
{
- fixed (byte* k = &null_key[0])
- {
+ // asking the kernel for availability turns out to be very costly
+ long key = (((long) algo << 32) | (long) mode);
+ if (availability.Contains (key))
+ return true;
+
+ bool result = false;
+ fixed (byte* k = &null_key [0]) {
Session session = new Session ();
switch (algo) {
case Cipher.AES_CBC:
@@ -135,16 +143,16 @@ static bool Is (Cipher algo, KernelMode mode)
}
ulong ciocgsession = mode == KernelMode.CryptoDev ? CD_CIOCGSESSION : OCF_CIOCGSESSION;
- bool result;
if (IntPtr.Size == 4)
result = ioctl32 (fildes, (int) ciocgsession, ref session) == 0;
else
result = ioctl64 (fildes, ciocgsession, ref session) == 0;
-
- if (result)
- Mode = mode;
- return result;
}
+ if (result) {
+ Mode = mode;
+ availability.Add (key);
+ }
+ return result;
}
// values varies for cryptodev and OCF and for 32/64 bits
Please sign in to comment.
Something went wrong with that request. Please try again.