[Webfunds-commits] java/webfunds/token/algorithm AbstractTokenInterface.java AbstractTokenUtil.java AbstractBlindedToken.java AbstractPrivateTokenParameters.java AbstractProtoToken.java AbstractPublicTokenParameters.java AbstractToken.java ChaumBlindedToken.java ChaumConstants.java ChaumProtoToken.java ChaumToken.java RandomBlindedToken.java RandomProtoToken.java RandomToken.java

Edwin Woudt edwin@cypherpunks.ai
Tue, 2 Jan 2001 22:19:21 -0400 (AST)


edwin       01/01/02 22:19:21

  Modified:    webfunds/token/algorithm AbstractBlindedToken.java
                        AbstractPrivateTokenParameters.java
                        AbstractProtoToken.java
                        AbstractPublicTokenParameters.java
                        AbstractToken.java ChaumBlindedToken.java
                        ChaumConstants.java ChaumProtoToken.java
                        ChaumToken.java RandomBlindedToken.java
                        RandomProtoToken.java RandomToken.java
  Added:       webfunds/token/algorithm AbstractTokenInterface.java
                        AbstractTokenUtil.java
  Log:
  Basically complete implementation of the general abstract token classes.
  Parameter classes still need some work.

Revision  Changes    Path
1.3       +92 -12    java/webfunds/token/algorithm/AbstractBlindedToken.java

Index: AbstractBlindedToken.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/token/algorithm/AbstractBlindedToken.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AbstractBlindedToken.java	2000/12/31 03:54:19	1.2
+++ AbstractBlindedToken.java	2001/01/03 02:19:19	1.3
@@ -1,4 +1,4 @@
-/* $Id: AbstractBlindedToken.java,v 1.2 2000/12/31 03:54:19 edwin Exp $
+/* $Id: AbstractBlindedToken.java,v 1.3 2001/01/03 02:19:19 edwin Exp $
  *
  * Copyright (c) Systemics Ltd 2000 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -13,26 +13,27 @@
 /**
  * Class description
  *
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
  * @author Edwin Woudt <edwin@webfunds.org>
  */
-public abstract class AbstractBlindedToken {
+public abstract class AbstractBlindedToken implements AbstractTokenInterface {
 
 
 // Init methods
 //.............................................................................
 
-    public abstract void decode(byte[] data, int start, int len)
+    protected abstract void decodeImpl(byte[] data, int start, int len)
     throws DataFormatException, UnsupportedVersionException;
 
+    public final void decode(byte[] data, int start, int len)
+    throws DataFormatException, UnsupportedVersionException
+    {
+        int delta = AbstractTokenUtil.decodeUtil(data, start, len, 
+                        AbstractTokenUtil.PKT_BLINDEDPROTO, this);
+        start += delta; len -= delta;
+        decodeImpl(data, start, len);
+    }
 
-// Information retrieval methods
-//.............................................................................
-
-    public abstract long getSeries();
-    
-    public abstract long getValue(AbstractPrivateTokenParameters privparams);
-    
 
 // Processing methods
 //.............................................................................
@@ -44,9 +45,16 @@
 // Output methods
 //.............................................................................
 
-    public abstract byte[] encode();
+    protected abstract byte[] encodeImpl();
     
+    public final byte[] encode() {
 
+        byte[] data = encodeImpl();
+        return AbstractTokenUtil.encodeUtil(data, 
+                   AbstractTokenUtil.PKT_SIGNEDBLINDED, this);
+    }
+        
+
 // Challenge/response methods
 //.............................................................................
     
@@ -74,4 +82,76 @@
     }
 
 
+// Intance variables
+//.............................................................................
+
+    private byte[] currencyID;
+    private byte[] series;
+    private long   value;
+    
+    private byte   abstractMajorVersion;
+    private byte   abstractMinorVersion;
+    private byte   implementationMajorVersion;
+    private byte   implementationMinorVersion;
+
+
+// Getters/Setters
+//.............................................................................
+
+    public final byte getAbstractMajorVersion() { 
+        return abstractMajorVersion; 
+    }
+    
+    public final byte getAbstractMinorVersion() { 
+        return abstractMajorVersion; 
+    }
+    
+    public final byte getImplementationMajorVersion() { 
+        return abstractMajorVersion; 
+    }
+    
+    public final byte getImplementationMinorVersion() { 
+        return abstractMajorVersion; 
+    }
+    
+    public final byte[] getCurrencyID() {
+        return currencyID;
+    }
+    
+    public final byte[] getSeries() {
+        return series;
+    }
+    
+    public final long getValue() {
+        return value;
+    }
+    
+    public final void setAbstractMajorVersion(byte x) {
+        this.abstractMajorVersion = x;
+    }
+    
+    public final void setAbstractMinorVersion(byte x) {
+        this.abstractMajorVersion = x;
+    }
+    
+    public final void setImplementationMajorVersion(byte x) {
+        this.abstractMajorVersion = x;
+    }
+    
+    public final void setImplementationMinorVersion(byte x) {
+        this.abstractMajorVersion = x;
+    }
+    
+    public final void setCurrencyID(byte[] x) {
+        this.currencyID = x;
+    }
+    
+    public final void setSeries(byte[] x) {
+        this.series = x;
+    }
+    
+    public final void setValue(long x) {
+        this.value = x;
+    }
+    
 }



1.2       +2 -2      java/webfunds/token/algorithm/AbstractPrivateTokenParameters.java

Index: AbstractPrivateTokenParameters.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/token/algorithm/AbstractPrivateTokenParameters.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractPrivateTokenParameters.java	2000/12/31 03:54:19	1.1
+++ AbstractPrivateTokenParameters.java	2001/01/03 02:19:19	1.2
@@ -1,4 +1,4 @@
-/* $Id: AbstractPrivateTokenParameters.java,v 1.1 2000/12/31 03:54:19 edwin Exp $
+/* $Id: AbstractPrivateTokenParameters.java,v 1.2 2001/01/03 02:19:19 edwin Exp $
  *
  * Copyright (c) Systemics Ltd 2000 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -84,7 +84,7 @@
  *      specific data. <br>
  * </p>
  *
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
  * @author Edwin Woudt <edwin@webfunds.org>
  */
 public abstract class AbstractPrivateTokenParameters {
@@ -204,7 +204,7 @@
         throw new RuntimeException("NYI");
     }
 
-    public final long getSeries() {
+    public final byte[] getSeries() {
         throw new RuntimeException("NYI");
     }
 



1.3       +93 -7     java/webfunds/token/algorithm/AbstractProtoToken.java

Index: AbstractProtoToken.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/token/algorithm/AbstractProtoToken.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AbstractProtoToken.java	2000/12/31 03:54:19	1.2
+++ AbstractProtoToken.java	2001/01/03 02:19:19	1.3
@@ -1,4 +1,4 @@
-/* $Id: AbstractProtoToken.java,v 1.2 2000/12/31 03:54:19 edwin Exp $
+/* $Id: AbstractProtoToken.java,v 1.3 2001/01/03 02:19:19 edwin Exp $
  *
  * Copyright (c) Systemics Ltd 2000 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -10,25 +10,56 @@
 /**
  * Class description
  *
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
  * @author Edwin Woudt <edwin@webfunds.org>
  */
-public abstract class AbstractProtoToken {
+public abstract class AbstractProtoToken implements AbstractTokenInterface {
 
 
+// Instance variables
+//.............................................................................
+
+    private byte[] currencyID;
+    private byte[] series;
+    private long   value;
+
+
 // Init methods
 //.............................................................................
+
+    protected abstract void generateImpl(SecureRandom sr, long value, 
+                                       AbstractPublicTokenParameters pubparams);
 
-    public abstract void generate(SecureRandom sr, long value, 
-                                  AbstractPublicTokenParameters pubparams);
+    public final void generate(SecureRandom sr, long value, 
+                               AbstractPublicTokenParameters pubparams)
+    {
+        this.currencyID = pubparams.getCurrencyID();
+        this.series     = pubparams.getSeries();
+        this.value      = value;
+        generateImpl(sr, value, pubparams);
+    }
 
 
 // Output methods
 //.............................................................................
 
-    public abstract byte[] encodeBlindedProtoToken();
+    protected abstract byte[] encodeBlindedProtoTokenImpl();
+    
+    public final byte[] encodeBlindedProtoToken() {
+        
+        byte[] temp = encodeBlindedProtoTokenImpl();
+        return AbstractTokenUtil.encodeUtil(temp, 
+                   AbstractTokenUtil.PKT_BLINDEDPROTO, this);
+    }
     
-    public abstract byte[] encodeLocallySavedData();
+    protected abstract byte[] encodeLocallySavedDataImpl();
+    
+    public final byte[] encodeLocallySavedData() {
+
+        byte[] temp = encodeLocallySavedDataImpl();
+        return AbstractTokenUtil.encodeUtil(temp, 
+                   AbstractTokenUtil.PKT_LOCALSAVED, this);
+    }
 
 
 // Challenge/response methods
@@ -42,4 +73,59 @@
     }
 
 
+// Getters/Setters
+//.............................................................................
+
+    public final byte getAbstractMajorVersion() { 
+        return AbstractTokenUtil.ABSTRACT_TOKEN_MAJOR_VERSION; 
+    }
+    
+    public final byte getAbstractMinorVersion() { 
+        return AbstractTokenUtil.ABSTRACT_TOKEN_MINOR_VERSION; 
+    }
+    
+    public abstract byte getImplementationMajorVersion();
+    
+    public abstract byte getImplementationMinorVersion();
+    
+    public final byte[] getCurrencyID() {
+        return currencyID;
+    }
+    
+    public final byte[] getSeries() {
+        return series;
+    }
+    
+    public final long getValue() {
+        return value;
+    }
+    
+    public final void setAbstractMajorVersion(byte x) {
+        throw new RuntimeException("Do not call me");
+    }
+    
+    public final void setAbstractMinorVersion(byte x) {
+        throw new RuntimeException("Do not call me");
+    }
+    
+    public final void setImplementationMajorVersion(byte x) {
+        throw new RuntimeException("Do not call me");
+    }
+    
+    public final void setImplementationMinorVersion(byte x) {
+        throw new RuntimeException("Do not call me");
+    }
+    
+    public final void setCurrencyID(byte[] x) {
+        throw new RuntimeException("Do not call me");
+    }
+    
+    public final void setSeries(byte[] x) {
+        throw new RuntimeException("Do not call me");
+    }
+    
+    public final void setValue(long x) {
+        throw new RuntimeException("Do not call me");
+    }
+    
 }



1.2       +2 -2      java/webfunds/token/algorithm/AbstractPublicTokenParameters.java

Index: AbstractPublicTokenParameters.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/token/algorithm/AbstractPublicTokenParameters.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractPublicTokenParameters.java	2000/12/31 03:54:20	1.1
+++ AbstractPublicTokenParameters.java	2001/01/03 02:19:19	1.2
@@ -1,4 +1,4 @@
-/* $Id: AbstractPublicTokenParameters.java,v 1.1 2000/12/31 03:54:20 edwin Exp $
+/* $Id: AbstractPublicTokenParameters.java,v 1.2 2001/01/03 02:19:19 edwin Exp $
  *
  * Copyright (c) Systemics Ltd 2000 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -21,7 +21,7 @@
 /**
  * Class description
  *
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
  * @author Edwin Woudt <edwin@webfunds.org>
  */
 public abstract class AbstractPublicTokenParameters {
@@ -49,7 +49,7 @@
         throw new RuntimeException("NYI");
     }
 
-    public final long getSeries() {
+    public final byte[] getSeries() {
         throw new RuntimeException("NYI");
     }
 



1.3       +120 -17   java/webfunds/token/algorithm/AbstractToken.java

Index: AbstractToken.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/token/algorithm/AbstractToken.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AbstractToken.java	2000/12/31 03:54:20	1.2
+++ AbstractToken.java	2001/01/03 02:19:19	1.3
@@ -1,4 +1,4 @@
-/* $Id: AbstractToken.java,v 1.2 2000/12/31 03:54:20 edwin Exp $
+/* $Id: AbstractToken.java,v 1.3 2001/01/03 02:19:19 edwin Exp $
  *
  * Copyright (c) Systemics Ltd 2000 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -13,33 +13,57 @@
 /**
  * Class description
  *
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
  * @author Edwin Woudt <edwin@webfunds.org>
  */
-public abstract class AbstractToken {
+public abstract class AbstractToken implements AbstractTokenInterface {
 
 
 // Init methods
 //.............................................................................
 
-    public abstract void unblind(byte[] blindedcoin, int start, int len,
-                                 byte[] locallysaveddata, SecureRandom sr, 
-                                 AbstractPublicTokenParameters pubparams) 
-    throws DataFormatException;
-
-                                 
-    public abstract void decode(byte[] data, int start, int len)
+    protected abstract void unblindImpl(byte[] blindedcoin, int startb, 
+        int lenb, byte[] locallysaveddata, int startl, int lenl, 
+        SecureRandom sr, AbstractPublicTokenParameters pubparams)
     throws DataFormatException, UnsupportedVersionException;
-    
-    
-// Information retrieval methods
-//.............................................................................
 
-    public abstract long getSeries();
 
-    public abstract long getValue();
+    public final void unblind(byte[] blindedcoin, int startb, int lenb,
+        byte[] locallysaveddata, int startl, int lenl, SecureRandom sr, 
+        AbstractPublicTokenParameters pubparams) 
+    throws DataFormatException, UnsupportedVersionException
+    {
+        int delta = AbstractTokenUtil.decodeUtil(blindedcoin, startb, lenb,
+            AbstractTokenUtil.PKT_SIGNEDBLINDED, this);
+
+        startb += delta; lenb -= delta;
+        
+        delta = AbstractTokenUtil.decodeUtil(locallysaveddata, startl, lenl,
+            AbstractTokenUtil.PKT_LOCALSAVED, this);
+
+        startl += delta; lenl -= delta;
+        
+        unblindImpl(blindedcoin, startb, lenb, locallysaveddata, startl, lenl,
+                    sr, pubparams);
+    }
 
 
+    protected abstract void decodeImpl(byte[] data, int start, int len)
+    throws DataFormatException, UnsupportedVersionException;
+    
+
+    public final void decode(byte[] data, int start, int len)
+    throws DataFormatException, UnsupportedVersionException
+    {
+        int delta = AbstractTokenUtil.decodeUtil(data, start, len,
+            AbstractTokenUtil.PKT_TOKEN, this);
+
+        start += delta; len -= delta;
+        
+        decodeImpl(data, start, len);
+    }
+    
+    
 // Processing methods
 //.............................................................................
 
@@ -53,9 +77,16 @@
 // Output methods
 //.............................................................................
 
-    public abstract byte[] encode();
+    protected abstract byte[] encodeImpl();
+    
+    public final byte[] encode() {
 
+        byte[] temp = encodeImpl();
+        return AbstractTokenUtil.encodeUtil(temp, AbstractTokenUtil.PKT_TOKEN, 
+                                            this);
+    }
 
+
 // Challenge/response methods
 //.............................................................................
     
@@ -76,4 +107,76 @@
     }
     
 
+// Intance variables
+//.............................................................................
+
+    private byte[] currencyID;
+    private byte[] series;
+    private long   value;
+
+    private byte   abstractMajorVersion;
+    private byte   abstractMinorVersion;
+    private byte   implementationMajorVersion;
+    private byte   implementationMinorVersion;
+
+
+// Getters/Setters
+//.............................................................................
+
+    public final byte getAbstractMajorVersion() { 
+        return abstractMajorVersion; 
+    }
+    
+    public final byte getAbstractMinorVersion() { 
+        return abstractMajorVersion; 
+    }
+    
+    public final byte getImplementationMajorVersion() { 
+        return abstractMajorVersion; 
+    }
+    
+    public final byte getImplementationMinorVersion() { 
+        return abstractMajorVersion; 
+    }
+    
+    public final byte[] getCurrencyID() {
+        return currencyID;
+    }
+    
+    public final byte[] getSeries() {
+        return series;
+    }
+    
+    public final long getValue() {
+        return value;
+    }
+    
+    public final void setAbstractMajorVersion(byte x) {
+        this.abstractMajorVersion = x;
+    }
+    
+    public final void setAbstractMinorVersion(byte x) {
+        this.abstractMajorVersion = x;
+    }
+    
+    public final void setImplementationMajorVersion(byte x) {
+        this.abstractMajorVersion = x;
+    }
+    
+    public final void setImplementationMinorVersion(byte x) {
+        this.abstractMajorVersion = x;
+    }
+    
+    public final void setCurrencyID(byte[] x) {
+        this.currencyID = x;
+    }
+    
+    public final void setSeries(byte[] x) {
+        this.series = x;
+    }
+    
+    public final void setValue(long x) {
+        this.value = x;
+    }
+    
 }



1.3       +6 -19     java/webfunds/token/algorithm/ChaumBlindedToken.java

Index: ChaumBlindedToken.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/token/algorithm/ChaumBlindedToken.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ChaumBlindedToken.java	2000/12/31 03:54:20	1.2
+++ ChaumBlindedToken.java	2001/01/03 02:19:19	1.3
@@ -1,4 +1,4 @@
-/* $Id: ChaumBlindedToken.java,v 1.2 2000/12/31 03:54:20 edwin Exp $
+/* $Id: ChaumBlindedToken.java,v 1.3 2001/01/03 02:19:19 edwin Exp $
  *
  * Copyright (c) Systemics Ltd 2000 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -9,12 +9,11 @@
 import java.security.SecureRandom;
 
 import webfunds.token.DataFormatException;
-import webfunds.token.UnsupportedVersionException;
 
 /**
  * Class description
  *
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
  * @author Edwin Woudt <edwin@webfunds.org>
  */
 public final class ChaumBlindedToken extends AbstractBlindedToken {
@@ -30,25 +29,13 @@
 // Init methods
 //.............................................................................
 
-    public void decode(byte[] data, int start, int len)
-    throws DataFormatException, UnsupportedVersionException
+    protected void decodeImpl(byte[] data, int start, int len)
+    throws DataFormatException
     {
         blindedProtoToken = EncodeDecodeUtil.decodeMPI(data, start, len);
     }
 
 
-// Information retrieval methods
-//.............................................................................
-
-    public long getSeries() {
-        throw new RuntimeException("NYI");
-    }
-    
-    public long getValue(AbstractPrivateTokenParameters privparams) {
-        throw new RuntimeException("NYI");
-    }
-    
-
 // Processing methods
 //.............................................................................
 
@@ -58,7 +45,7 @@
 
         BigInteger n = ((ChaumPrivateTokenParameters)privparams).getN();
         BigInteger d = ((ChaumPrivateTokenParameters)privparams).getD(
-                                                  getValue(privparams));
+                                                                    getValue());
 
         blindedSignedToken = blindedProtoToken.modPow(d, n);
 
@@ -68,7 +55,7 @@
 // Output methods
 //.............................................................................
 
-    public byte[] encode() {
+    protected byte[] encodeImpl() {
 
         byte[] bb = new byte[EncodeDecodeUtil.getMPILength(blindedSignedToken)];
 



1.2       +6 -1      java/webfunds/token/algorithm/ChaumConstants.java

Index: ChaumConstants.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/token/algorithm/ChaumConstants.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ChaumConstants.java	2000/12/31 03:54:20	1.1
+++ ChaumConstants.java	2001/01/03 02:19:19	1.2
@@ -1,4 +1,4 @@
-/* $Id: ChaumConstants.java,v 1.1 2000/12/31 03:54:20 edwin Exp $
+/* $Id: ChaumConstants.java,v 1.2 2001/01/03 02:19:19 edwin Exp $
  *
  * Copyright (c) Systemics Ltd 2000 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -8,7 +8,7 @@
 /**
  * Constants for the Chaum blinding algorithm
  *
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
  * @author Edwin Woudt <edwin@webfunds.org>
  */
 public final class ChaumConstants {
@@ -19,5 +19,10 @@
     public static final int    RANDOM_SIZE =  160/8;
     public static final int    HASH_SIZE   =  160/8;
     public static final String HASH_ALG    = "SHA-1";
+    
+    public static final byte   MAJOR_TOKEN_VERSION = 1;
+    public static final byte   MINOR_TOKEN_VERSION = 0;
+    public static final byte   MAJOR_PARAMS_VERSION = 1;
+    public static final byte   MINOR_PARAMS_VERSION = 0;
 
 }



1.3       +18 -6     java/webfunds/token/algorithm/ChaumProtoToken.java

Index: ChaumProtoToken.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/token/algorithm/ChaumProtoToken.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ChaumProtoToken.java	2000/12/31 03:54:20	1.2
+++ ChaumProtoToken.java	2001/01/03 02:19:19	1.3
@@ -1,4 +1,4 @@
-/* $Id: ChaumProtoToken.java,v 1.2 2000/12/31 03:54:20 edwin Exp $
+/* $Id: ChaumProtoToken.java,v 1.3 2001/01/03 02:19:19 edwin Exp $
  *
  * Copyright (c) Systemics Ltd 2000 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -14,7 +14,7 @@
 /**
  * Class description
  *
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
  * @author Edwin Woudt <edwin@webfunds.org>
  */
 public final class ChaumProtoToken extends AbstractProtoToken {
@@ -27,10 +27,22 @@
 private BigInteger blindedProtoToken;
 
 
+// Getters
+//.............................................................................
+
+    public byte getImplementationMajorVersion() { 
+        return ChaumConstants.MAJOR_TOKEN_VERSION; 
+    }
+    
+    public byte getImplementationMinorVersion() { 
+        return ChaumConstants.MINOR_TOKEN_VERSION; 
+    }
+    
+
 // Init methods
 //.............................................................................
 
-    public byte[] hashAndExtend(byte[] id) {
+    /* package */ static byte[] hashAndExtend(byte[] id) {
         
         byte[] proto = new byte[ChaumConstants.KEY_SIZE];
         proto[0] = 0; // first byte always zero to avoid overflow errors
@@ -61,7 +73,7 @@
 
     }
 
-    public void generate(SecureRandom sr, long value, 
+    protected void generateImpl(SecureRandom sr, long value, 
                          AbstractPublicTokenParameters pubparams) {
         
         byte[] id = new byte[ChaumConstants.RANDOM_SIZE];
@@ -85,7 +97,7 @@
 // Output methods
 //.............................................................................
 
-    public byte[] encodeBlindedProtoToken() {
+    protected byte[] encodeBlindedProtoTokenImpl() {
         
         byte[] bpt = new byte[EncodeDecodeUtil.getMPILength(blindedProtoToken)];
 
@@ -96,7 +108,7 @@
         
     }
     
-    public byte[] encodeLocallySavedData() {
+    protected byte[] encodeLocallySavedDataImpl() {
 
         byte[] lsd = new byte[EncodeDecodeUtil.getMPILength(protoToken) +
                               EncodeDecodeUtil.getMPILength(blindingFactor)];



1.3       +55 -33    java/webfunds/token/algorithm/ChaumToken.java

Index: ChaumToken.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/token/algorithm/ChaumToken.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ChaumToken.java	2000/12/31 03:54:21	1.2
+++ ChaumToken.java	2001/01/03 02:19:19	1.3
@@ -1,4 +1,4 @@
-/* $Id: ChaumToken.java,v 1.2 2000/12/31 03:54:21 edwin Exp $
+/* $Id: ChaumToken.java,v 1.3 2001/01/03 02:19:19 edwin Exp $
  *
  * Copyright (c) Systemics Ltd 2000 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -9,12 +9,11 @@
 import java.security.SecureRandom;
 
 import webfunds.token.DataFormatException;
-import webfunds.token.UnsupportedVersionException;
 
 /**
  * Class description
  *
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
  * @author Edwin Woudt <edwin@webfunds.org>
  */
 public final class ChaumToken extends AbstractToken {
@@ -24,44 +23,62 @@
 
 private BigInteger token;
 private BigInteger sig;
+private byte[] tokenbytes;
+private byte[] tokenid;
 
 
 // Init methods
 //.............................................................................
 
-    public void unblind(byte[] blindedcoin, int start, int len,
-                        byte[] locallysaveddata, SecureRandom sr, 
-                        AbstractPublicTokenParameters pubparams)
+    private void decodeToken() throws DataFormatException {
+        
+        byte[] temp = token.toByteArray();
+        if (temp.length >= ChaumConstants.KEY_SIZE) {
+            throw new DataFormatException("Token too large");
+        }
+        tokenbytes = new byte[ChaumConstants.KEY_SIZE];
+        System.arraycopy(temp, 0, tokenbytes, tokenbytes.length-temp.length, 
+                         temp.length);
+        tokenid = new byte[ChaumConstants.RANDOM_SIZE];
+        System.arraycopy(temp, 1, tokenid, 0, tokenid.length);
+        
+    }
+
+    
+    protected void unblindImpl(byte[] blindedcoin, int startb, int lenb,
+        byte[] locallysaveddata, int startl, int lenl, SecureRandom sr, 
+        AbstractPublicTokenParameters pubparams)
     throws DataFormatException
     {
         int delta;
         BigInteger blindedSignedCoin, blindingFactor;
         
-        blindedSignedCoin = EncodeDecodeUtil.decodeMPI(blindedcoin, start, len);
-        delta = EncodeDecodeUtil.getMPILength(blindedcoin, start, len);
-        start += delta; len -= delta;
+        blindedSignedCoin = EncodeDecodeUtil.decodeMPI(blindedcoin, startb, lenb);
+        delta = EncodeDecodeUtil.getMPILength(blindedcoin, startb, lenb);
+        startb += delta; lenb -= delta;
 
 
-        start = 0; len = locallysaveddata.length;
+        blindingFactor = EncodeDecodeUtil.decodeMPI(locallysaveddata, startl, lenl);
+        delta = EncodeDecodeUtil.getMPILength(locallysaveddata, startl, lenl);
+        startl += delta; lenl -= delta;
+
+        token = EncodeDecodeUtil.decodeMPI(locallysaveddata, startl, lenl);
+        delta = EncodeDecodeUtil.getMPILength(locallysaveddata, startl, lenl);
+        startl += delta; lenl -= delta;
         
-        blindingFactor = EncodeDecodeUtil.decodeMPI(locallysaveddata, start, len);
-        delta = EncodeDecodeUtil.getMPILength(locallysaveddata, start, len);
-        start += delta; len -= delta;
-
-        token = EncodeDecodeUtil.decodeMPI(locallysaveddata, start, len);
-        delta = EncodeDecodeUtil.getMPILength(locallysaveddata, start, len);
-        start += delta; len -= delta;
-        
         
         BigInteger n = ((ChaumPublicTokenParameters)pubparams).getN();
 
         sig = blindedSignedCoin.multiply(blindingFactor.modInverse(n)).mod(n);
         
+        
+        decodeToken();
+        
     }
                         
                                  
-    public void decode(byte[] data, int start, int len)
-    throws DataFormatException, UnsupportedVersionException
+    protected void decodeImpl(byte[] data, int start, int len)
+    throws DataFormatException
     {
 
         int delta;
@@ -73,26 +90,27 @@
         sig = EncodeDecodeUtil.decodeMPI(data, start, len);
         delta = EncodeDecodeUtil.getMPILength(data, start, len);
         start += delta; len -= delta;
+        
+        decodeToken();
 
     }
     
     
-// Information retrieval methods
+// Processing methods
 //.............................................................................
-
-    public long getSeries() {
-        throw new RuntimeException("NYI");
-    }
 
-    public long getValue() {
-        throw new RuntimeException("NYI");
+    private boolean correctTokenFormat() {
+    
+        byte[] temp = ChaumProtoToken.hashAndExtend(tokenid);
+        for (int i=0; i<temp.length; i++) {
+            if (temp[i] != tokenbytes[i]) return false;
+        }
+        // no differences found
+        return true;
+    
     }
 
-
-// Processing methods
-//.............................................................................
-
-    public boolean verify(BigInteger e, BigInteger n) {
+    private boolean verify(BigInteger e, BigInteger n) {
         
         return token.equals(sig.modPow(e,n));
         
@@ -100,6 +118,8 @@
 
     public boolean verifyPublic(AbstractPublicTokenParameters pubparams) {
 
+        if (! correctTokenFormat()) return false;
+
         BigInteger n = ((ChaumPublicTokenParameters)pubparams).getN();
         BigInteger e = ((ChaumPublicTokenParameters)pubparams).getE(getValue());
 
@@ -109,6 +129,8 @@
     
     public boolean verifyPrivate(AbstractPrivateTokenParameters privparams) {
 
+        if (! correctTokenFormat()) return false;
+
         BigInteger n = ((ChaumPrivateTokenParameters)privparams).getN();
         BigInteger e = ((ChaumPrivateTokenParameters)privparams).getE(getValue());
 
@@ -120,7 +142,7 @@
 // Output methods
 //.............................................................................
 
-    public byte[] encode() {
+    protected byte[] encodeImpl() {
 
         byte[] bb = new byte[EncodeDecodeUtil.getMPILength(token) +
                              EncodeDecodeUtil.getMPILength(sig)];



1.3       +5 -18     java/webfunds/token/algorithm/RandomBlindedToken.java

Index: RandomBlindedToken.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/token/algorithm/RandomBlindedToken.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- RandomBlindedToken.java	2000/12/31 03:54:21	1.2
+++ RandomBlindedToken.java	2001/01/03 02:19:19	1.3
@@ -1,4 +1,4 @@
-/* $Id: RandomBlindedToken.java,v 1.2 2000/12/31 03:54:21 edwin Exp $
+/* $Id: RandomBlindedToken.java,v 1.3 2001/01/03 02:19:19 edwin Exp $
  *
  * Copyright (c) Systemics Ltd 2000 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -8,12 +8,11 @@
 import java.security.SecureRandom;
 
 import webfunds.token.DataFormatException;
-import webfunds.token.UnsupportedVersionException;
 
 /**
  * Class description
  *
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
  * @author Edwin Woudt <edwin@webfunds.org>
  */
 public final class RandomBlindedToken extends AbstractBlindedToken {
@@ -22,25 +21,13 @@
 // Init methods
 //.............................................................................
 
-    public void decode(byte[] data, int start, int len)
-    throws DataFormatException, UnsupportedVersionException
+    protected void decodeImpl(byte[] data, int start, int len)
+    throws DataFormatException
     {
         throw new RuntimeException("NYI");
     }
 
 
-// Information retrieval methods
-//.............................................................................
-
-    public long getSeries() {
-        throw new RuntimeException("NYI");
-    }
-    
-    public long getValue(AbstractPrivateTokenParameters privparams) {
-        throw new RuntimeException("NYI");
-    }
-    
-
 // Processing methods
 //.............................................................................
 
@@ -54,7 +41,7 @@
 // Output methods
 //.............................................................................
 
-    public byte[] encode() {
+    protected byte[] encodeImpl() {
         throw new RuntimeException("NYI");
     }
     



1.3       +17 -5     java/webfunds/token/algorithm/RandomProtoToken.java

Index: RandomProtoToken.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/token/algorithm/RandomProtoToken.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- RandomProtoToken.java	2000/12/31 03:54:21	1.2
+++ RandomProtoToken.java	2001/01/03 02:19:20	1.3
@@ -1,4 +1,4 @@
-/* $Id: RandomProtoToken.java,v 1.2 2000/12/31 03:54:21 edwin Exp $
+/* $Id: RandomProtoToken.java,v 1.3 2001/01/03 02:19:20 edwin Exp $
  *
  * Copyright (c) Systemics Ltd 2000 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -10,16 +10,28 @@
 /**
  * Class description
  *
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
  * @author Edwin Woudt <edwin@webfunds.org>
  */
 public final class RandomProtoToken extends AbstractProtoToken {
 
 
+// Getters
+//.............................................................................
+
+    public byte getImplementationMajorVersion() { 
+        throw new RuntimeException("NYI");
+    }
+    
+    public byte getImplementationMinorVersion() { 
+        throw new RuntimeException("NYI");
+    }
+    
+
 // Init methods
 //.............................................................................
 
-    public void generate(SecureRandom sr, long value, 
+    protected void generateImpl(SecureRandom sr, long value, 
                          AbstractPublicTokenParameters pubparams) {
         throw new RuntimeException("NYI");
     }
@@ -28,11 +40,11 @@
 // Output methods
 //.............................................................................
 
-    public byte[] encodeBlindedProtoToken() {
+    protected byte[] encodeBlindedProtoTokenImpl() {
         throw new RuntimeException("NYI");
     }
     
-    public byte[] encodeLocallySavedData() {
+    protected byte[] encodeLocallySavedDataImpl() {
         throw new RuntimeException("NYI");
     }
 



1.3       +8 -21     java/webfunds/token/algorithm/RandomToken.java

Index: RandomToken.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/token/algorithm/RandomToken.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- RandomToken.java	2000/12/31 03:54:22	1.2
+++ RandomToken.java	2001/01/03 02:19:20	1.3
@@ -1,4 +1,4 @@
-/* $Id: RandomToken.java,v 1.2 2000/12/31 03:54:22 edwin Exp $
+/* $Id: RandomToken.java,v 1.3 2001/01/03 02:19:20 edwin Exp $
  *
  * Copyright (c) Systemics Ltd 2000 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -8,12 +8,11 @@
 import java.security.SecureRandom;
 
 import webfunds.token.DataFormatException;
-import webfunds.token.UnsupportedVersionException;
 
 /**
  * Class description
  *
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
  * @author Edwin Woudt <edwin@webfunds.org>
  */
 public final class RandomToken extends AbstractToken {
@@ -22,34 +21,22 @@
 // Init methods
 //.............................................................................
 
-    public void unblind(byte[] blindedcoin, int start, int len,
-                        byte[] locallysaveddata, SecureRandom sr, 
-                        AbstractPublicTokenParameters pubparams) 
+    protected void unblindImpl(byte[] blindedcoin, int startb, int lenb,
+        byte[] locallysaveddata, int startl, int lenl, SecureRandom sr, 
+        AbstractPublicTokenParameters pubparams) 
     throws DataFormatException
     {
         throw new RuntimeException("NYI");
     }
                         
                                  
-    public void decode(byte[] data, int start, int len)
-    throws DataFormatException, UnsupportedVersionException
+    protected void decodeImpl(byte[] data, int start, int len)
+    throws DataFormatException
     {
         throw new RuntimeException("NYI");
     }
     
     
-// Information retrieval methods
-//.............................................................................
-
-    public long getSeries() {
-        throw new RuntimeException("NYI");
-    }
-
-    public long getValue() {
-        throw new RuntimeException("NYI");
-    }
-
-
 // Processing methods
 //.............................................................................
 
@@ -65,7 +52,7 @@
 // Output methods
 //.............................................................................
 
-    public byte[] encode() {
+    protected byte[] encodeImpl() {
         throw new RuntimeException("NYI");
     }
 



1.1                  java/webfunds/token/algorithm/AbstractTokenInterface.java

Index: AbstractTokenInterface.java
===================================================================
/* $Id: AbstractTokenInterface.java,v 1.1 2001/01/03 02:19:19 edwin Exp $
 *
 * Copyright (c) Systemics Ltd 2000 on behalf of
 * the WebFunds Development Team.  All Rights Reserved.
 */
package webfunds.token.algorithm;

/**
 * Description
 *
 * @version $Revision: 1.1 $
 * @author Edwin Woudt <edwin@webfunds.org>
 */
interface AbstractTokenInterface {

    byte getAbstractMajorVersion();
    void setAbstractMajorVersion(byte x);
    
    byte getAbstractMinorVersion();
    void setAbstractMinorVersion(byte x);
    
    byte getImplementationMajorVersion();
    void setImplementationMajorVersion(byte x);
    
    byte getImplementationMinorVersion();
    void setImplementationMinorVersion(byte x);
    
    byte[] getCurrencyID();
    void setCurrencyID(byte[] x);
    
    byte[] getSeries();
    void setSeries(byte[] x);
    
    long getValue();
    void setValue(long x);

}



1.1                  java/webfunds/token/algorithm/AbstractTokenUtil.java

Index: AbstractTokenUtil.java
===================================================================
/* $Id: AbstractTokenUtil.java,v 1.1 2001/01/03 02:19:19 edwin Exp $
 *
 * Copyright (c) Systemics Ltd 2000 on behalf of
 * the WebFunds Development Team.  All Rights Reserved.
 */
package webfunds.token.algorithm;

import webfunds.token.DataFormatException;
import webfunds.token.UnsupportedVersionException;

/**
 * Constants for the token library
 *
 * @version $Revision: 1.1 $
 * @author Edwin Woudt <edwin@webfunds.org>
 */
public final class AbstractTokenUtil {

    private AbstractTokenUtil() {} // static constants only
    
    public static final byte PKT_BLINDEDPROTO  = 0x10;
    public static final byte PKT_LOCALSAVED    = 0x11;
    public static final byte PKT_SIGNEDBLINDED = 0x12;
    public static final byte PKT_TOKEN         = 0x20;
    public static final byte PKT_PUBLICPARAMS  = 0x30;
    public static final byte PKT_PRIVATEPARAMS = 0x31;
    
    public static final byte ABSTRACT_TOKEN_MAJOR_VERSION  = 1;
    public static final byte ABSTRACT_TOKEN_MINOR_VERSION  = 0;
    public static final byte ABSTRACT_PARAMS_MAJOR_VERSION = 1;
    public static final byte ABSTRACT_PARAMS_MINOR_VERSION = 0;

    public static final byte[] encodeUtil(byte[] data, byte identifier, 
                                          AbstractTokenInterface tok) 
    {
        int len = data.length;
        len += 1; // identifier
        len += 4; // version info
        len += EncodeDecodeUtil.getByteArrayLength(tok.getCurrencyID());
        len += EncodeDecodeUtil.getByteArrayLength(tok.getSeries());
        len += 8; // value
        
        byte[] output = new byte[len];
        int start=0;

        output[start++] = identifier;
        len -= 1;
        
        output[start++] = tok.getAbstractMajorVersion();
        output[start++] = tok.getAbstractMinorVersion();
        output[start++] = tok.getImplementationMajorVersion();
        output[start++] = tok.getImplementationMinorVersion();
        len -= 4;
        
        int delta;
        
        EncodeDecodeUtil.encodeByteArray(tok.getCurrencyID(), output, start);
        delta = EncodeDecodeUtil.getByteArrayLength(tok.getCurrencyID());
        start += delta; len -= delta;
        
        EncodeDecodeUtil.encodeByteArray(tok.getSeries(), output, start);
        delta = EncodeDecodeUtil.getByteArrayLength(tok.getSeries());
        start += delta; len -= delta;
        
        EncodeDecodeUtil.encodeLong(tok.getValue(), output, start);
        start += 8; len -= 8;
        
        System.arraycopy(data, 0, output, start, len);

        return output;
    }


    public static final int decodeUtil(byte[] data, int start, int len,
                                   byte identifier, AbstractTokenInterface tok)
    throws DataFormatException, UnsupportedVersionException
    {
        int initlen = len;
        
        if (EncodeDecodeUtil.decodeByte(data, start++, len--) != identifier) {
            throw new DataFormatException("Invalid identifier");
        }
        
        tok.setAbstractMajorVersion( 
            EncodeDecodeUtil.decodeByte(data, start++, len--));
        tok.setAbstractMinorVersion( 
            EncodeDecodeUtil.decodeByte(data, start++, len--));
        tok.setImplementationMajorVersion( 
            EncodeDecodeUtil.decodeByte(data, start++, len--));
        tok.setImplementationMinorVersion(
            EncodeDecodeUtil.decodeByte(data, start++, len--));
        
        if (tok.getAbstractMajorVersion() > ABSTRACT_TOKEN_MAJOR_VERSION) 
        {
            throw new UnsupportedVersionException("Decoded version " +
                tok.getAbstractMajorVersion() + ", while I only know about "+
                "version " + ABSTRACT_TOKEN_MAJOR_VERSION);
        }

        tok.setCurrencyID(EncodeDecodeUtil.decodeByteArray(data, start, len));
        int delta = EncodeDecodeUtil.getByteArrayLength(data, start, len);
        start += delta; len -= delta;
        
        tok.setSeries(EncodeDecodeUtil.decodeByteArray(data, start, len));
        delta = EncodeDecodeUtil.getByteArrayLength(data, start, len);
        start += delta; len -= delta;
        
        tok.setValue(EncodeDecodeUtil.decodeLong(data, start, len));
        start += 8; len -= 8;

        return initlen - len;
    }
    
}