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