From 2e05d3b3397bd48e4dcdf2d74ddc20e5736144b3 Mon Sep 17 00:00:00 2001 From: Norayr Chilingarian Date: Wed, 22 Jan 2014 00:20:04 +0400 Subject: [PATCH] ported ulmBlockCiphers.Mod --- makefile | 1 + makefile.gnuc.armv6j | 1 + makefile.gnuc.armv6j_hardfp | 1 + makefile.gnuc.armv7a_hardfp | 1 + makefile.gnuc.powerpc | 1 + makefile.gnuc.x86 | 1 + makefile.gnuc.x86_64 | 1 + src/lib/ulm/ulmBlockCiphers.Mod | 123 ++++++++++++++++++++++++++++++++ 8 files changed, 130 insertions(+) create mode 100644 src/lib/ulm/ulmBlockCiphers.Mod diff --git a/makefile b/makefile index 33b1d61c..4419e5c7 100644 --- a/makefile +++ b/makefile @@ -208,6 +208,7 @@ stage6: $(VOCSTATIC) -sP ulmSysStat.Mod $(VOCSTATIC) -sP ulmCiphers.Mod $(VOCSTATIC) -sP ulmCipherOps.Mod + $(VOCSTATIC) -sP ulmBlockCiphers.Mod #pow32 libs diff --git a/makefile.gnuc.armv6j b/makefile.gnuc.armv6j index 5d25fbbb..e355f134 100644 --- a/makefile.gnuc.armv6j +++ b/makefile.gnuc.armv6j @@ -207,6 +207,7 @@ stage6: $(VOCSTATIC) -sP ulmSysStat.Mod $(VOCSTATIC) -sP ulmCiphers.Mod $(VOCSTATIC) -sP ulmCipherOps.Mod + $(VOCSTATIC) -sP ulmBlockCiphers.Mod #pow32 libs diff --git a/makefile.gnuc.armv6j_hardfp b/makefile.gnuc.armv6j_hardfp index 682dcf5b..50ea86c7 100644 --- a/makefile.gnuc.armv6j_hardfp +++ b/makefile.gnuc.armv6j_hardfp @@ -207,6 +207,7 @@ stage6: $(VOCSTATIC) -sP ulmSysStat.Mod $(VOCSTATIC) -sP ulmCiphers.Mod $(VOCSTATIC) -sP ulmCipherOps.Mod + $(VOCSTATIC) -sP ulmBlockCiphers.Mod #pow32 libs diff --git a/makefile.gnuc.armv7a_hardfp b/makefile.gnuc.armv7a_hardfp index d95f3474..2119f0f5 100644 --- a/makefile.gnuc.armv7a_hardfp +++ b/makefile.gnuc.armv7a_hardfp @@ -207,6 +207,7 @@ stage6: $(VOCSTATIC) -sP ulmSysStat.Mod $(VOCSTATIC) -sP ulmCiphers.Mod $(VOCSTATIC) -sP ulmCipherOps.Mod + $(VOCSTATIC) -sP ulmBlockCiphers.Mod #pow32 libs diff --git a/makefile.gnuc.powerpc b/makefile.gnuc.powerpc index d0a03fd4..d3f2e291 100644 --- a/makefile.gnuc.powerpc +++ b/makefile.gnuc.powerpc @@ -207,6 +207,7 @@ stage6: $(VOCSTATIC) -sP ulmSysStat.Mod $(VOCSTATIC) -sP ulmCiphers.Mod $(VOCSTATIC) -sP ulmCipherOps.Mod + $(VOCSTATIC) -sP ulmBlockCiphers.Mod #pow32 libs diff --git a/makefile.gnuc.x86 b/makefile.gnuc.x86 index 963479e9..6a1c2d09 100644 --- a/makefile.gnuc.x86 +++ b/makefile.gnuc.x86 @@ -207,6 +207,7 @@ stage6: $(VOCSTATIC) -sP ulmSysStat.Mod $(VOCSTATIC) -sP ulmCiphers.Mod $(VOCSTATIC) -sP ulmCipherOps.Mod + $(VOCSTATIC) -sP ulmBlockCiphers.Mod #pow32 libs diff --git a/makefile.gnuc.x86_64 b/makefile.gnuc.x86_64 index 8c36d47c..d31fb091 100644 --- a/makefile.gnuc.x86_64 +++ b/makefile.gnuc.x86_64 @@ -207,6 +207,7 @@ stage6: $(VOCSTATIC) -sP ulmSysStat.Mod $(VOCSTATIC) -sP ulmCiphers.Mod $(VOCSTATIC) -sP ulmCipherOps.Mod + $(VOCSTATIC) -sP ulmBlockCiphers.Mod #pow32 libs diff --git a/src/lib/ulm/ulmBlockCiphers.Mod b/src/lib/ulm/ulmBlockCiphers.Mod new file mode 100644 index 00000000..41e3355c --- /dev/null +++ b/src/lib/ulm/ulmBlockCiphers.Mod @@ -0,0 +1,123 @@ +(* Ulm's Oberon Library + Copyright (C) 1989-1997 by University of Ulm, SAI, D-89069 Ulm, Germany + ---------------------------------------------------------------------------- + Ulm's Oberon Library is free software; you can redistribute it + and/or modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either version + 2 of the License, or (at your option) any later version. + + Ulm's Oberon Library is distributed in the hope that it will be + useful, but WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + ---------------------------------------------------------------------------- + E-mail contact: oberon@mathematik.uni-ulm.de + ---------------------------------------------------------------------------- + $Id: BlockCipher.om,v 1.1 1997/04/02 11:52:59 borchert Exp borchert $ + ---------------------------------------------------------------------------- + $Log: BlockCipher.om,v $ + Revision 1.1 1997/04/02 11:52:59 borchert + Initial revision + + ---------------------------------------------------------------------------- +*) + +MODULE ulmBlockCiphers; (* Michael Szczuka *) + + (* abstraction for the use of block ciphers *) + + IMPORT Ciphers := ulmCiphers, NetIO := ulmNetIO, PersistentObjects := ulmPersistentObjects, Services := ulmServices, Streams := ulmStreams; + + TYPE + Cipher* = POINTER TO CipherRec; + + CipherRec* = RECORD + (Ciphers.CipherRec) + (* private *) + inLength: INTEGER; + outLength: INTEGER; + END; + + VAR + blockCipherType : Services.Type; + if : PersistentObjects.Interface; + + PROCEDURE Init* (key: Cipher; if: Ciphers.Interface; + inLength, outLength: INTEGER); + (* init a block cipher with its special interface *) + BEGIN + Ciphers.Init(key, if); + ASSERT(inLength > 0); + ASSERT(outLength > 0); + key.inLength := inLength; + key.outLength := outLength; + END Init; + + PROCEDURE GetInLength* (key: Cipher) : INTEGER; + (* returns the input block length of a block cipher *) + BEGIN + RETURN key.inLength; + END GetInLength; + + PROCEDURE GetOutLength* (key: Cipher) : INTEGER; + (* returns the output block length of a block cipher *) + BEGIN + RETURN key.outLength; + END GetOutLength; + + PROCEDURE EncryptBlock* (in: Streams.Stream; key: Cipher; + out: Streams.Stream) : BOOLEAN; + VAR + length : INTEGER; + BEGIN + length := GetInLength(key); + RETURN Ciphers.EncryptPart(in, key, length, out); + END EncryptBlock; + + PROCEDURE DecryptBlock* (in: Streams.Stream; key: Cipher; + out: Streams.Stream) : BOOLEAN; + VAR + length : INTEGER; + BEGIN + length := GetOutLength(key); + RETURN Ciphers.DecryptPart(in, key, length, out); + END DecryptBlock; + + PROCEDURE Create(VAR obj: PersistentObjects.Object); + VAR + key : Cipher; + BEGIN + NEW(key); + PersistentObjects.Init(key, blockCipherType); + obj := key; + END Create; + + PROCEDURE Write(s: Streams.Stream; obj: PersistentObjects.Object) : BOOLEAN; + BEGIN + WITH obj:Cipher DO + RETURN NetIO.WriteInteger(s, obj.inLength) & + NetIO.WriteInteger(s, obj.outLength); + END; + END Write; + + PROCEDURE Read(s: Streams.Stream; obj: PersistentObjects.Object) : BOOLEAN; + BEGIN + WITH obj:Cipher DO + RETURN NetIO.ReadInteger(s, obj.inLength) & + NetIO.ReadInteger(s, obj.outLength); + END; + END Read; + +BEGIN + NEW(if); + if.create := Create; + if.write := Write; + if.read := Read; + if.createAndRead := NIL; + PersistentObjects.RegisterType(blockCipherType, "BlockCiphers.Cipher", + "Ciphers.Cipher", if); +END ulmBlockCiphers.