poly1305_ppc.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright 2009-2021 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include <openssl/opensslconf.h>
  10. #include <openssl/types.h>
  11. #include "crypto/poly1305.h"
  12. #include "crypto/ppc_arch.h"
  13. void poly1305_init_int(void *ctx, const unsigned char key[16]);
  14. void poly1305_blocks(void *ctx, const unsigned char *inp, size_t len,
  15. unsigned int padbit);
  16. void poly1305_emit(void *ctx, unsigned char mac[16],
  17. const unsigned int nonce[4]);
  18. void poly1305_init_fpu(void *ctx, const unsigned char key[16]);
  19. void poly1305_blocks_fpu(void *ctx, const unsigned char *inp, size_t len,
  20. unsigned int padbit);
  21. void poly1305_emit_fpu(void *ctx, unsigned char mac[16],
  22. const unsigned int nonce[4]);
  23. void poly1305_init_vsx(void *ctx, const unsigned char key[16]);
  24. void poly1305_blocks_vsx(void *ctx, const unsigned char *inp, size_t len,
  25. unsigned int padbit);
  26. void poly1305_emit_vsx(void *ctx, unsigned char mac[16],
  27. const unsigned int nonce[4]);
  28. int poly1305_init(void *ctx, const unsigned char key[16], void *func[2]);
  29. int poly1305_init(void *ctx, const unsigned char key[16], void *func[2])
  30. {
  31. if (OPENSSL_ppccap_P & PPC_CRYPTO207) {
  32. poly1305_init_int(ctx, key);
  33. func[0] = (void*)(uintptr_t)poly1305_blocks_vsx;
  34. func[1] = (void*)(uintptr_t)poly1305_emit;
  35. } else if (sizeof(size_t) == 4 && (OPENSSL_ppccap_P & PPC_FPU)) {
  36. poly1305_init_fpu(ctx, key);
  37. func[0] = (void*)(uintptr_t)poly1305_blocks_fpu;
  38. func[1] = (void*)(uintptr_t)poly1305_emit_fpu;
  39. } else {
  40. poly1305_init_int(ctx, key);
  41. func[0] = (void*)(uintptr_t)poly1305_blocks;
  42. func[1] = (void*)(uintptr_t)poly1305_emit;
  43. }
  44. return 1;
  45. }