Skip to content

Commit

Permalink
Comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
wasabii committed Jan 17, 2025
1 parent 9591d71 commit e04d0fb
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
21 changes: 20 additions & 1 deletion src/IKVM.Runtime/Util/Com/Sun/Crypto/Provider/AESCrypt_x86.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,26 @@ namespace IKVM.Runtime.Util.Com.Sun.Crypto.Provider
{

/// <summary>
/// X86 implementation of the AES functions.
/// X86 implementation of the AES intrinsic functions.
/// </summary>
static class AESCrypt_x86
{

/// <summary>
/// Returns <c>true</c> if the current platform is supported by this implementation.
/// </summary>
public static bool IsSupported => Aes.IsSupported && Ssse3.IsSupported;

public static ReadOnlySpan<int> KeyShuffleMask => [0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f];

/// <summary>
/// Implementation of com.sun.crypto.provider.AESCrypt.decryptBlock for the x86 platform.
/// Derived from the OpenJDK C code 'stubGenerator_x86_32.cpp:generate_aescrypt_decryptBlock'.
/// Keep the structure of the body of this method as close to the orignal C code as possible to facilitate porting changes.
/// </summary>
/// <param name="from"></param>
/// <param name="to"></param>
/// <param name="key"></param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void DecryptBlock(ReadOnlySpan<byte> from, Span<byte> to, ReadOnlySpan<int> key)
{
Expand Down Expand Up @@ -80,6 +91,14 @@ public static void DecryptBlock(ReadOnlySpan<byte> from, Span<byte> to, ReadOnly
xmm_result.CopyTo(to);
}

/// <summary>
/// Implementation of com.sun.crypto.provider.AESCrypt.encryptBlock for the x86 platform.
/// Derived from the OpenJDK C code 'stubGenerator_x86_32.cpp:generate_aescrypt_encryptBlock'.
/// Keep the structure of the body of this method as close to the orignal C code as possible to facilitate porting changes.
/// </summary>
/// <param name="from"></param>
/// <param name="to"></param>
/// <param name="key"></param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void EncryptBlock(ReadOnlySpan<byte> from, Span<byte> to, ReadOnlySpan<int> key)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static bool DecryptAESCrypt(object self, byte[] cipher, int cipherOffset,

var k = AESCryptAccessor.K(aes);

if (AESCrypt_x86.IsSupported)
if (CipherBlockChaining_x86.IsSupported)
{
CipherBlockChaining_x86.DecryptAESCrypt(cipher.AsSpan(cipherOffset), plain.AsSpan(plainOffset), k, r, cipherLen);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,22 @@ namespace IKVM.Runtime.Util.Com.Sun.Crypto.Provider
{

/// <summary>
/// X86 implementations of the CipherBlockChaining functions.
/// X86 implementations of the CipherBlockChaining intrinsic functions.
/// </summary>
static class CipherBlockChaining_x86
{

const int AESBlockSize = 16;

/// <summary>
/// Returns <c>true</c> if the current platform is supported by this implementation.
/// </summary>
public static bool IsSupported => AESCrypt_x86.IsSupported;

/// <summary>
/// Implementation of com.sun.crypto.provider.CipherBlockChaining.implDecrypt for the x86 platform.
/// Derived from the OpenJDK C code 'stubGenerator_x86_32.cpp:generate_cipherBlockChaining_decryptAESCrypt'.
/// Keep the structure of the body of this method as close to the orignal C code as possible to facilitate porting changes.
/// </summary>
/// <param name="from"></param>
/// <param name="to"></param>
Expand Down Expand Up @@ -147,6 +154,16 @@ public static void DecryptAESCrypt(ReadOnlySpan<byte> from, Span<byte> to, ReadO
goto exit;
}

/// <summary>
/// Implementation of com.sun.crypto.provider.CipherBlockChaining.implEncrypt for the x86 platform.
/// Derived from the OpenJDK C code 'stubGenerator_x86_32.cpp:generate_cipherBlockChaining_encryptAESCrypt'.
/// Keep the structure of the body of this method as close to the orignal C code as possible to facilitate porting changes.
/// </summary>
/// <param name="from"></param>
/// <param name="to"></param>
/// <param name="key"></param>
/// <param name="rvec"></param>
/// <param name="length"></param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void EncryptAESCrypt(ReadOnlySpan<byte> from, Span<byte> to, ReadOnlySpan<int> key, Span<byte> rvec, int length)
{
Expand Down
14 changes: 13 additions & 1 deletion src/IKVM.Runtime/Util/Com/Sun/Crypto/Provider/GHASH_x86.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,29 @@ namespace IKVM.Runtime.Util.Com.Sun.Crypto.Provider
{

/// <summary>
/// X86 implementation of the GHASH functions.
/// X86 implementation of the GHASH intrinsic functions.
/// </summary>
static class GHASH_x86
{

/// <summary>
/// Returns <c>true</c> if the current platform is supported by this implementation.
/// </summary>
public static bool IsSupported => Pclmulqdq.IsSupported && Ssse3.IsSupported;

static ReadOnlySpan<int> ByteSwapMask => [0x0c0d0e0f, 0x08090a0b, 0x04050607, 0x00010203];

static ReadOnlySpan<int> LongSwapMask => [0x0b0a0908, 0x0f0e0d0c, 0x03020100, 0x07060504];

/// <summary>
/// Implementation of com.sun.crypto.provider.GHASH.processBlocks for the x86 platform.
/// Derived from the OpenJDK C code 'stubGenerator_x86_32.cpp:generate_ghash_processBlocks'.
/// Keep the structure of the body of this method as close to the orignal C code as possible to facilitate porting changes.
/// </summary>
/// <param name="data"></param>
/// <param name="blocks"></param>
/// <param name="state"></param>
/// <param name="subH"></param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ProcessBlocks(ReadOnlySpan<byte> data, int blocks, Span<long> state, ReadOnlySpan<long> subH)
{
Expand Down

0 comments on commit e04d0fb

Please sign in to comment.