From cffd0299fe9ecfbffd78a503b2e89b0a4cda16e3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20Grubbstr=C3=B6m=20=28Grubba=29?=
 <grubba@grubba.org>
Date: Wed, 13 Nov 1996 16:26:51 +0100
Subject: [PATCH] Decryption is now done in the reverse order of encryption.

Rev: src/modules/_Crypto/pipe.c:1.2
---
 src/modules/_Crypto/pipe.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/modules/_Crypto/pipe.c b/src/modules/_Crypto/pipe.c
index 870dd9df6d..33c5fef1c3 100644
--- a/src/modules/_Crypto/pipe.c
+++ b/src/modules/_Crypto/pipe.c
@@ -1,5 +1,5 @@
 /*
- * $Id: pipe.c,v 1.1 1996/11/11 19:24:04 grubba Exp $
+ * $Id: pipe.c,v 1.2 1996/11/13 15:26:51 grubba Exp $
  *
  * PIPE crypto module for Pike.
  *
@@ -185,6 +185,7 @@ static void f_set_encrypt_key(INT32 args)
   if (args != PIKE_PIPE->num_objs) {
     error("Wrong number of arguments to pipe->set_encrypt_key()\n");
   }
+  PIKE_PIPE->mode = 0;
   for (i=-args; i; i++) {
     int n_args;
 
@@ -211,6 +212,7 @@ static void f_set_decrypt_key(INT32 args)
   if (args != PIKE_PIPE->num_objs) {
     error("Wrong number of arguments to pipe->set_decrypt_key()\n");
   }
+  PIKE_PIPE->mode = 1;
   for (i=-args; i; i++) {
     int n_args;
 
@@ -243,8 +245,15 @@ static void f_crypt_block(INT32 args)
   if (sp[-1].u.string->len % PIKE_PIPE->block_size) {
     error("Bad length of argument 1 to pipe->crypt_block()\n");
   }
-  for (i=0; i<PIKE_PIPE->num_objs; i++) {
-    safe_apply(PIKE_PIPE->objects[i], "crypt_block", 1);
+  if (PIKE_PIPE->mode) {
+    /* Decryption -- Reverse the order */
+    for (i=PIKE_PIPE->num_objs; i--;) {
+      safe_apply(PIKE_PIPE->objects[i], "crypt_block", 1);
+    }
+  } else {
+    for (i=0; i<PIKE_PIPE->num_objs; i++) {
+      safe_apply(PIKE_PIPE->objects[i], "crypt_block", 1);
+    }
   }
 }
 
-- 
GitLab