Skip to contentSkip to conversation

target-arm: add support for v8 SHA1 and SHA256 instructions

PATCH In review Ard Biesheuvel 3 participants 4 messages Mar 25, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target-arm: add support for v8 SHA1 and SHA256 instructions

This adds support for the SHA1 and SHA256 instructions that are available on some v8 implementations of Aarch32.

---
 target-arm/cpu.c           |   2 +
 target-arm/cpu.h           |   2 +
 target-arm/crypto_helper.c | 257 +++++++++++++++++++++++++++++++++++++++++++--
 target-arm/helper.h        |   9 ++
 target-arm/translate.c     |  81 ++++++++++++++
 5 files changed, 344 insertions(+), 7 deletions(-)
target-arm/cpu.c +2 -0
index c32d8c4855b4..58c4584ac3bc 100644
@@ -291,6 +291,8 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
         set_feature(env, ARM_FEATURE_ARM_DIV);
         set_feature(env, ARM_FEATURE_LPAE);
         set_feature(env, ARM_FEATURE_V8_AES);
+        set_feature(env, ARM_FEATURE_V8_SHA1);
+        set_feature(env, ARM_FEATURE_V8_SHA256);
     }
     if (arm_feature(env, ARM_FEATURE_V7)) {
         set_feature(env, ARM_FEATURE_VAPA);
target-arm/cpu.h +2 -0
index bf37cd60d0a2..f5039d8b0177 100644
@@ -630,6 +630,8 @@ enum arm_features {
     ARM_FEATURE_V8_AES, /* implements AES part of v8 Crypto Extensions */
     ARM_FEATURE_CBAR, /* has cp15 CBAR */
     ARM_FEATURE_CRC, /* ARMv8 CRC instructions */
+    ARM_FEATURE_V8_SHA1, /* implements SHA1 part of v8 Crypto Extensions */
+    ARM_FEATURE_V8_SHA256, /* implements SHA256 part of v8 Crypto Extensions */
 };
 
 static inline int arm_feature(CPUARMState *env, int feature)
target-arm/crypto_helper.c +250 -7

294 lines not on this page · raw message

target-arm/helper.h +9 -0
index 366c1b3ea59b..9024aef75157 100644
@@ -512,6 +512,15 @@ DEF_HELPER_3(neon_qzip32, void, env, i32, i32)
 DEF_HELPER_4(crypto_aese, void, env, i32, i32, i32)
 DEF_HELPER_4(crypto_aesmc, void, env, i32, i32, i32)
 
+DEF_HELPER_5(crypto_sha1_3reg, void, env, i32, i32, i32, i32)
+DEF_HELPER_3(crypto_sha1h, void, env, i32, i32)
+DEF_HELPER_3(crypto_sha1su1, void, env, i32, i32)
+
+DEF_HELPER_4(crypto_sha256h, void, env, i32, i32, i32)
+DEF_HELPER_4(crypto_sha256h2, void, env, i32, i32, i32)
+DEF_HELPER_3(crypto_sha256su0, void, env, i32, i32)
+DEF_HELPER_4(crypto_sha256su1, void, env, i32, i32, i32)
+
 DEF_HELPER_FLAGS_3(crc32, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32)
 DEF_HELPER_FLAGS_3(crc32c, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32)
 
target-arm/translate.c +81 -0

129 lines not on this page · raw message

Signature · 1 line
1.8.3.2
#1 lore raw

Am 25.03.2014 17:27, schrieb Ard Biesheuvel:

Quoted 30 lines

This adds support for the SHA1 and SHA256 instructions that are available on some v8 implementations of Aarch32.

---
 target-arm/cpu.c           |   2 +
 target-arm/cpu.h           |   2 +
 target-arm/crypto_helper.c | 257 +++++++++++++++++++++++++++++++++++++++++++--
 target-arm/helper.h        |   9 ++
 target-arm/translate.c     |  81 ++++++++++++++
 5 files changed, 344 insertions(+), 7 deletions(-)
target-arm/cpu.c +2 -0
index c32d8c4855b4..58c4584ac3bc 100644
@@ -291,6 +291,8 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
         set_feature(env, ARM_FEATURE_ARM_DIV);
         set_feature(env, ARM_FEATURE_LPAE);
         set_feature(env, ARM_FEATURE_V8_AES);
+        set_feature(env, ARM_FEATURE_V8_SHA1);
+        set_feature(env, ARM_FEATURE_V8_SHA256);
     }
     if (arm_feature(env, ARM_FEATURE_V7)) {
         set_feature(env, ARM_FEATURE_VAPA);
target-arm/cpu.h +0 -0
index bf37cd60d0a2..f5039d8b0177 100644

target-arm/cpu.h enum arm_features { · line 635

Quoted 6 lines
target-arm/cpu.h +2 -0
@@ -630,6 +630,8 @@ enum arm_features {
     ARM_FEATURE_V8_AES, /* implements AES part of v8 Crypto Extensions */
     ARM_FEATURE_CBAR, /* has cp15 CBAR */
     ARM_FEATURE_CRC, /* ARMv8 CRC instructions */
+    ARM_FEATURE_V8_SHA1, /* implements SHA1 part of v8 Crypto Extensions */
+    ARM_FEATURE_V8_SHA256, /* implements SHA256 part of v8 Crypto Extensions */
 };

Do these really need to be separate features? We only have 32 feature bits. Maybe even an ARM_FEATURE_CRYPTO for AES, SHA1, SHA256 would do?

Regards,
Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#2 lore raw
Quoted 11 lines · Andreas Färber

Am 25.03.2014 17:27, schrieb Ard Biesheuvel:

target-arm/cpu.h enum arm_features { · line 635

Quoted 7 lines
target-arm/cpu.h +2 -0
@@ -630,6 +630,8 @@ enum arm_features {
     ARM_FEATURE_V8_AES, /* implements AES part of v8 Crypto Extensions */
     ARM_FEATURE_CBAR, /* has cp15 CBAR */
     ARM_FEATURE_CRC, /* ARMv8 CRC instructions */
+    ARM_FEATURE_V8_SHA1, /* implements SHA1 part of v8 Crypto Extensions */
+    ARM_FEATURE_V8_SHA256, /* implements SHA256 part of v8 Crypto Extensions */
 };

Do these really need to be separate features? We only have 32 feature bits.

No, we have 64. We overflowed 32 bits a little while back :-)

Quoted 1 line

Maybe even an ARM_FEATURE_CRYPTO for AES, SHA1, SHA256 would do?

It's arguable. The ARM ARM defines the crypto extensions as a single extension with all these items in it, but the ID registers allow for more finely grained distinctions. I wouldn't obejct if we want to rename the V8_AES feature as V8_CRYPTO, or if
we just have a single V8_SHA bit, but I don't think it's critical either way.

thanks
-- PMM

#3 lore raw
Quoted 13 lines · Peter Maydell
Quoted 11 lines · Andreas Färber

Am 25.03.2014 17:27, schrieb Ard Biesheuvel:

target-arm/cpu.h enum arm_features { · line 635

Quoted 7 lines
target-arm/cpu.h +2 -0
@@ -630,6 +630,8 @@ enum arm_features {
     ARM_FEATURE_V8_AES, /* implements AES part of v8 Crypto Extensions */
     ARM_FEATURE_CBAR, /* has cp15 CBAR */
     ARM_FEATURE_CRC, /* ARMv8 CRC instructions */
+    ARM_FEATURE_V8_SHA1, /* implements SHA1 part of v8 Crypto Extensions */
+    ARM_FEATURE_V8_SHA256, /* implements SHA256 part of v8 Crypto Extensions */
 };

Do these really need to be separate features? We only have 32 feature bits.

Quoted 1 line

No, we have 64. We overflowed 32 bits a little while back :-)

Incidentally there's no limit at 64 either -- we can always define an arm_extended_feature() for feature bits 64 and up if we get that far.

-- PMM