diff --git a/makefile b/makefile index 4419e5c7..cb2d9c25 100644 --- a/makefile +++ b/makefile @@ -209,8 +209,8 @@ stage6: $(VOCSTATIC) -sP ulmCiphers.Mod $(VOCSTATIC) -sP ulmCipherOps.Mod $(VOCSTATIC) -sP ulmBlockCiphers.Mod - - + $(VOCSTATIC) -sP ulmAsymmetricCiphers.Mod + #pow32 libs $(VOCSTATIC) -sP powStrings.Mod diff --git a/makefile.gnuc.armv6j b/makefile.gnuc.armv6j index e355f134..1126d884 100644 --- a/makefile.gnuc.armv6j +++ b/makefile.gnuc.armv6j @@ -208,7 +208,7 @@ stage6: $(VOCSTATIC) -sP ulmCiphers.Mod $(VOCSTATIC) -sP ulmCipherOps.Mod $(VOCSTATIC) -sP ulmBlockCiphers.Mod - + $(VOCSTATIC) -sP ulmAsymmetricCiphers.Mod #pow32 libs $(VOCSTATIC) -sP powStrings.Mod diff --git a/makefile.gnuc.armv6j_hardfp b/makefile.gnuc.armv6j_hardfp index 50ea86c7..81c452a6 100644 --- a/makefile.gnuc.armv6j_hardfp +++ b/makefile.gnuc.armv6j_hardfp @@ -208,7 +208,7 @@ stage6: $(VOCSTATIC) -sP ulmCiphers.Mod $(VOCSTATIC) -sP ulmCipherOps.Mod $(VOCSTATIC) -sP ulmBlockCiphers.Mod - + $(VOCSTATIC) -sP ulmAsymmetricCiphers.Mod #pow32 libs $(VOCSTATIC) -sP powStrings.Mod diff --git a/makefile.gnuc.armv7a_hardfp b/makefile.gnuc.armv7a_hardfp index 2119f0f5..5ca4b414 100644 --- a/makefile.gnuc.armv7a_hardfp +++ b/makefile.gnuc.armv7a_hardfp @@ -208,7 +208,7 @@ stage6: $(VOCSTATIC) -sP ulmCiphers.Mod $(VOCSTATIC) -sP ulmCipherOps.Mod $(VOCSTATIC) -sP ulmBlockCiphers.Mod - + $(VOCSTATIC) -sP ulmAsymmetricCiphers.Mod #pow32 libs $(VOCSTATIC) -sP powStrings.Mod diff --git a/makefile.gnuc.powerpc b/makefile.gnuc.powerpc index d3f2e291..a35ddb72 100644 --- a/makefile.gnuc.powerpc +++ b/makefile.gnuc.powerpc @@ -208,7 +208,7 @@ stage6: $(VOCSTATIC) -sP ulmCiphers.Mod $(VOCSTATIC) -sP ulmCipherOps.Mod $(VOCSTATIC) -sP ulmBlockCiphers.Mod - + $(VOCSTATIC) -sP ulmAsymmetricCiphers.Mod #pow32 libs $(VOCSTATIC) -sP powStrings.Mod diff --git a/makefile.gnuc.x86 b/makefile.gnuc.x86 index 6a1c2d09..9930ce3c 100644 --- a/makefile.gnuc.x86 +++ b/makefile.gnuc.x86 @@ -208,7 +208,7 @@ stage6: $(VOCSTATIC) -sP ulmCiphers.Mod $(VOCSTATIC) -sP ulmCipherOps.Mod $(VOCSTATIC) -sP ulmBlockCiphers.Mod - + $(VOCSTATIC) -sP ulmAsymmetricCiphers.Mod #pow32 libs $(VOCSTATIC) -sP powStrings.Mod diff --git a/makefile.gnuc.x86_64 b/makefile.gnuc.x86_64 index d31fb091..df0ba347 100644 --- a/makefile.gnuc.x86_64 +++ b/makefile.gnuc.x86_64 @@ -208,7 +208,7 @@ stage6: $(VOCSTATIC) -sP ulmCiphers.Mod $(VOCSTATIC) -sP ulmCipherOps.Mod $(VOCSTATIC) -sP ulmBlockCiphers.Mod - + $(VOCSTATIC) -sP ulmAsymmetricCiphers.Mod #pow32 libs $(VOCSTATIC) -sP powStrings.Mod diff --git a/src/lib/ulm/ulmAsymmetricCiphers.Mod b/src/lib/ulm/ulmAsymmetricCiphers.Mod new file mode 100644 index 00000000..ba8dfdda --- /dev/null +++ b/src/lib/ulm/ulmAsymmetricCiphers.Mod @@ -0,0 +1,174 @@ +(* 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: AsymmetricC.om,v 1.1 1997/04/02 11:52:05 borchert Exp borchert $ + ---------------------------------------------------------------------------- + $Log: AsymmetricC.om,v $ + Revision 1.1 1997/04/02 11:52:05 borchert + Initial revision + + ---------------------------------------------------------------------------- +*) + +MODULE ulmAsymmetricCiphers; (* Michael Szczuka *) + + (* abstraction for the use of public key ciphers *) + + IMPORT BlockCiphers := ulmBlockCiphers, Ciphers := ulmCiphers, NetIO := ulmNetIO, PersistentObjects := ulmPersistentObjects, Services := ulmServices, Streams := ulmStreams; + + CONST + composed* = 0; isPrivateKey* = 1; + + TYPE + CapabilitySet* = SET; + + TYPE + Cipher* = POINTER TO CipherRec; + SplitProc* = PROCEDURE (VAR public: Cipher; key: Cipher); + RandomStreamProc* = PROCEDURE (s: Streams.Stream); + + Interface* = POINTER TO InterfaceRec; + InterfaceRec* = RECORD + (Ciphers.InterfaceRec) + (* public *) + compencrypt* : Ciphers.CryptProc; + split* : SplitProc; + randomStream* : RandomStreamProc; + END; + + CipherRec* = RECORD + (BlockCiphers.CipherRec) + (* private *) + cap : CapabilitySet; + asymIf : Interface; + END; + + VAR + asymmetricCipherType : Services.Type; + if : PersistentObjects.Interface; + + (* need to have this in case anyone wants to decrypt something with + a public cipher ... *) + PROCEDURE Identity(in: Streams.Stream; key: Ciphers.Cipher; + length: INTEGER; out: Streams.Stream) : BOOLEAN; + BEGIN + RETURN Streams.Copy(in, out, length); + END Identity; + + PROCEDURE Init* (key: Cipher; if: Interface; + cap: CapabilitySet; inLength, outLength: INTEGER); + BEGIN + IF if.decrypt = NIL THEN + (* decrypt is not defined, so we have only the public part of a cipher; + we can use the identity instead of a decrypting function + in this case + *) + if.decrypt := Identity; + END; + BlockCiphers.Init(key, if, inLength, outLength); + key.cap := cap; + key.asymIf := if; + IF (key.asymIf.compencrypt = NIL) OR ~(composed IN cap) THEN + (* so the cipher's composed function is not defined; therefor it must be + the identical function *) + key.asymIf.compencrypt := Identity; + END; + END Init; + + PROCEDURE Capabilities* (key: Cipher) : CapabilitySet; + BEGIN + RETURN key.cap; + END Capabilities; + + PROCEDURE IsPublicKey* (key: Cipher) : BOOLEAN; + BEGIN + RETURN ~(isPrivateKey IN key.cap); + END IsPublicKey; + + PROCEDURE Split* (VAR public: Cipher; key: Cipher); + BEGIN + IF IsPublicKey(key) THEN + (* trying to extract a public part from a key that already IS a public + cipher? well, if you really want to ... *) + public := key; + RETURN; + END; + key.asymIf.split(public, key); + (* define the extracted part as public *) + public.cap := public.cap - {isPrivateKey}; + END Split; + + (* encrypts a given stream msg with the composed map of the key *) + PROCEDURE ComposedEncrypt* (in: Streams.Stream; key: Cipher; + out: Streams.Stream) : BOOLEAN; + BEGIN + RETURN key.asymIf.compencrypt(in, key, -1, out); + END ComposedEncrypt; + + PROCEDURE ComposedEncryptPart* (in: Streams.Stream; key: Cipher; + length: INTEGER; + out: Streams.Stream) : BOOLEAN; + BEGIN + RETURN key.asymIf.compencrypt(in, key, length, out); + END ComposedEncryptPart; + + PROCEDURE ComposedEncryptBlock* (in: Streams.Stream; key: Cipher; + out: Streams.Stream) : BOOLEAN; + VAR + length : INTEGER; + BEGIN + length := BlockCiphers.GetInLength(key); + RETURN key.asymIf.compencrypt(in, key, length, out); + END ComposedEncryptBlock; + + PROCEDURE RandomStream*(s: Streams.Stream; key: Cipher); + BEGIN + key.asymIf.randomStream(s); + END RandomStream; + + PROCEDURE Create (VAR obj: PersistentObjects.Object); + VAR + cipher : Cipher; + BEGIN + NEW(cipher); + PersistentObjects.Init(cipher, asymmetricCipherType); + obj := cipher; + END Create; + + PROCEDURE Write (s: Streams.Stream; obj: PersistentObjects.Object) : BOOLEAN; + BEGIN + WITH obj:Cipher DO + RETURN NetIO.WriteSet(s, obj.cap); + END; + END Write; + + PROCEDURE Read (s: Streams.Stream; obj: PersistentObjects.Object) : BOOLEAN; + BEGIN + WITH obj:Cipher DO + RETURN NetIO.ReadSet(s, obj.cap); + END; + END Read; + +BEGIN + NEW(if); + if.create := Create; if.write := Write; if.read := Read; + if.createAndRead := NIL; + PersistentObjects.RegisterType(asymmetricCipherType, + "AsymmetricCiphers.Cipher", "BlockCiphers.Cipher", if); +END ulmAsymmetricCiphers. diff --git a/src/lib/ulm/ulmCiphers.Mod b/src/lib/ulm/ulmCiphers.Mod index aeb85438..bc881c83 100644 --- a/src/lib/ulm/ulmCiphers.Mod +++ b/src/lib/ulm/ulmCiphers.Mod @@ -44,7 +44,7 @@ TYPE InterfaceRec* = RECORD (Objects.ObjectRec) (* public *) - encrypt*, decrypt : CryptProc; + encrypt*, decrypt* : CryptProc; END; TYPE