37532b3
diff -rupN --no-dereference openssl-3.0.9/include/crypto/aes_platform.h openssl-3.0.9-new/include/crypto/aes_platform.h
37532b3
--- openssl-3.0.9/include/crypto/aes_platform.h	2023-05-31 14:33:17.454112711 +0200
37532b3
+++ openssl-3.0.9-new/include/crypto/aes_platform.h	2023-05-31 14:33:19.301111904 +0200
37532b3
@@ -83,16 +83,8 @@ size_t ppc_aes_gcm_encrypt(const unsigne
37532b3
 size_t ppc_aes_gcm_decrypt(const unsigned char *in, unsigned char *out,
37532b3
                            size_t len, const void *key, unsigned char ivec[16],
37532b3
                            u64 *Xi);
37532b3
-size_t ppc_aes_gcm_encrypt_wrap(const unsigned char *in, unsigned char *out,
37532b3
-                                size_t len, const void *key,
37532b3
-                                unsigned char ivec[16], u64 *Xi);
37532b3
-size_t ppc_aes_gcm_decrypt_wrap(const unsigned char *in, unsigned char *out,
37532b3
-                                size_t len, const void *key,
37532b3
-                                unsigned char ivec[16], u64 *Xi);
37532b3
-#   define AES_gcm_encrypt ppc_aes_gcm_encrypt_wrap
37532b3
-#   define AES_gcm_decrypt ppc_aes_gcm_decrypt_wrap
37532b3
-#   define AES_GCM_ASM(gctx) ((gctx)->ctr==aes_p8_ctr32_encrypt_blocks && \
37532b3
-                              (gctx)->gcm.ghash==gcm_ghash_p8)
37532b3
+#   define AES_GCM_ASM_PPC(gctx) ((gctx)->ctr==aes_p8_ctr32_encrypt_blocks && \
37532b3
+                                 (gctx)->gcm.ghash==gcm_ghash_p8)
37532b3
 void gcm_ghash_p8(u64 Xi[2],const u128 Htable[16],const u8 *inp, size_t len);
37532b3
 #  endif /* PPC */
37532b3
 
37532b3
diff -rupN --no-dereference openssl-3.0.9/providers/implementations/ciphers/cipher_aes_gcm_hw_ppc.inc openssl-3.0.9-new/providers/implementations/ciphers/cipher_aes_gcm_hw_ppc.inc
37532b3
--- openssl-3.0.9/providers/implementations/ciphers/cipher_aes_gcm_hw_ppc.inc	2023-05-31 14:33:17.454112711 +0200
37532b3
+++ openssl-3.0.9-new/providers/implementations/ciphers/cipher_aes_gcm_hw_ppc.inc	2023-05-31 14:33:19.301111904 +0200
37532b3
@@ -23,12 +23,6 @@ static int aes_ppc_gcm_initkey(PROV_GCM_
37532b3
     return 1;
37532b3
 }
37532b3
 
37532b3
-
37532b3
-extern size_t ppc_aes_gcm_encrypt(const unsigned char *in, unsigned char *out, size_t len,
37532b3
-                                  const void *key, unsigned char ivec[16], u64 *Xi);
37532b3
-extern size_t ppc_aes_gcm_decrypt(const unsigned char *in, unsigned char *out, size_t len,
37532b3
-                                  const void *key, unsigned char ivec[16], u64 *Xi);
37532b3
-
37532b3
 static inline u32 UTO32(unsigned char *buf)
37532b3
 {
37532b3
     return ((u32) buf[0] << 24) | ((u32) buf[1] << 16) | ((u32) buf[2] << 8) | ((u32) buf[3]);
37532b3
@@ -47,7 +41,7 @@ static inline u32 add32TOU(unsigned char
37532b3
     return r;
37532b3
 }
37532b3
 
37532b3
-static size_t aes_p10_gcm_crypt(const unsigned char *in, unsigned char *out, size_t len,
37532b3
+static size_t ppc_aes_gcm_crypt(const unsigned char *in, unsigned char *out, size_t len,
37532b3
                                 const void *key, unsigned char ivec[16], u64 *Xi, int encrypt)
37532b3
 {
37532b3
     int s = 0;
37532b3
@@ -90,24 +84,66 @@ static size_t aes_p10_gcm_crypt(const un
37532b3
     return ndone;
37532b3
 }
37532b3
 
37532b3
-size_t ppc_aes_gcm_encrypt_wrap(const unsigned char *in, unsigned char *out, size_t len,
37532b3
-                                const void *key, unsigned char ivec[16], u64 *Xi)
37532b3
-{
37532b3
-    return aes_p10_gcm_crypt(in, out, len, key, ivec, Xi, 1);
37532b3
-}
37532b3
-
37532b3
-size_t ppc_aes_gcm_decrypt_wrap(const unsigned char *in, unsigned char *out, size_t len,
37532b3
-                                const void *key, unsigned char ivec[16], u64 *Xi)
37532b3
+static int ppc_aes_gcm_cipher_update(PROV_GCM_CTX *ctx, const unsigned char *in,
37532b3
+                                     size_t len, unsigned char *out)
37532b3
 {
37532b3
-    return aes_p10_gcm_crypt(in, out, len, key, ivec, Xi, 0);
37532b3
+    if (ctx->enc) {
37532b3
+        if (ctx->ctr != NULL) {
37532b3
+            size_t bulk = 0;
37532b3
+
37532b3
+            if (len >= AES_GCM_ENC_BYTES && AES_GCM_ASM_PPC(ctx)) {
37532b3
+                size_t res = (16 - ctx->gcm.mres) % 16;
37532b3
+
37532b3
+                if (CRYPTO_gcm128_encrypt(&ctx->gcm, in, out, res))
37532b3
+                    return 0;
37532b3
+
37532b3
+                bulk = ppc_aes_gcm_crypt(in + res, out + res, len - res,
37532b3
+                                         ctx->gcm.key,
37532b3
+                                         ctx->gcm.Yi.c, ctx->gcm.Xi.u, 1);
37532b3
+
37532b3
+                ctx->gcm.len.u[1] += bulk;
37532b3
+                bulk += res;
37532b3
+            }
37532b3
+            if (CRYPTO_gcm128_encrypt_ctr32(&ctx->gcm, in + bulk, out + bulk,
37532b3
+                                            len - bulk, ctx->ctr))
37532b3
+                return 0;
37532b3
+        } else {
37532b3
+            if (CRYPTO_gcm128_encrypt(&ctx->gcm, in, out, len))
37532b3
+                return 0;
37532b3
+        }
37532b3
+    } else {
37532b3
+        if (ctx->ctr != NULL) {
37532b3
+            size_t bulk = 0;
37532b3
+
37532b3
+            if (len >= AES_GCM_DEC_BYTES && AES_GCM_ASM_PPC(ctx)) {
37532b3
+                size_t res = (16 - ctx->gcm.mres) % 16;
37532b3
+
37532b3
+                if (CRYPTO_gcm128_decrypt(&ctx->gcm, in, out, res))
37532b3
+                    return -1;
37532b3
+
37532b3
+                bulk = ppc_aes_gcm_crypt(in + res, out + res, len - res,
37532b3
+                                         ctx->gcm.key,
37532b3
+                                         ctx->gcm.Yi.c, ctx->gcm.Xi.u, 0);
37532b3
+
37532b3
+                ctx->gcm.len.u[1] += bulk;
37532b3
+                bulk += res;
37532b3
+            }
37532b3
+            if (CRYPTO_gcm128_decrypt_ctr32(&ctx->gcm, in + bulk, out + bulk,
37532b3
+                                            len - bulk, ctx->ctr))
37532b3
+                return 0;
37532b3
+        } else {
37532b3
+            if (CRYPTO_gcm128_decrypt(&ctx->gcm, in, out, len))
37532b3
+                return 0;
37532b3
+        }
37532b3
+    }
37532b3
+    return 1;
37532b3
 }
37532b3
 
37532b3
-
37532b3
 static const PROV_GCM_HW aes_ppc_gcm = {
37532b3
     aes_ppc_gcm_initkey,
37532b3
     ossl_gcm_setiv,
37532b3
     ossl_gcm_aad_update,
37532b3
-    generic_aes_gcm_cipher_update,
37532b3
+    ppc_aes_gcm_cipher_update,
37532b3
     ossl_gcm_cipher_final,
37532b3
     ossl_gcm_one_shot
37532b3
 };