Skip to content

Commit

Permalink
alg/sha256.c: use _arm
Browse files Browse the repository at this point in the history
  • Loading branch information
gperciva committed Feb 20, 2021
1 parent 4b9a5e6 commit 3050bca
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion libcperciva/alg/sha256.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "cpusupport.h"
#include "insecure_memzero.h"
#include "sha256_arm.h"
#include "sha256_shani.h"
#include "sha256_sse2.h"
#include "sysendian.h"
Expand All @@ -12,13 +13,15 @@
#include "sha256.h"

#if defined(CPUSUPPORT_X86_SHANI) && defined(CPUSUPPORT_X86_SSSE3) || \
defined(CPUSUPPORT_X86_SSE2)
defined(CPUSUPPORT_X86_SSE2) || \
defined(CPUSUPPORT_ARM_SHA256)
#define HWACCEL

enum {
HW_UNSET,
HW_X86_SHANI,
HW_X86_SSE2,
HW_ARM_SHA256,
HW_SOFTWARE
};
#endif
Expand Down Expand Up @@ -186,6 +189,21 @@ usehw(void)
" self-test");
}
}
#endif
#if defined(CPUSUPPORT_ARM_SHA256)
/* If the CPU claims to be able to do it... */
if (cpusupport_arm_sha256()) {
/* ... test if it works... */
if (hwtest(initial_state, block, W, S,
SHA256_Transform_arm)) {
warn0("Disabling ARM-SHA256 due to failed"
" self-test");
} else
hwgood = HW_ARM_SHA256;

/* ... and bail whether or not we can use it. */
goto done;
}
#endif
}

Expand Down Expand Up @@ -245,6 +263,11 @@ SHA256_Transform(uint32_t state[static restrict 8],
case HW_X86_SSE2:
SHA256_Transform_sse2(state, block, W, S);
return;
#endif
#if defined(CPUSUPPORT_ARM_SHA256)
case HW_ARM_SHA256:
SHA256_Transform_arm(state, block, W, S);
return;
#endif
case HW_SOFTWARE:
break;
Expand Down

0 comments on commit 3050bca

Please sign in to comment.