All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bouncycastle.pqc.crypto.xmss.OTSHashAddress Maven / Gradle / Ivy

Go to download

The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.5 to JDK 1.8 with debug enabled.

There is a newer version: 1.70
Show newest version
package org.bouncycastle.pqc.crypto.xmss;

import org.bouncycastle.util.Pack;

/**
 * OTS hash address.
 */
final class OTSHashAddress
    extends XMSSAddress
{

    private static final int TYPE = 0x00;

    private final int otsAddress;
    private final int chainAddress;
    private final int hashAddress;

    private OTSHashAddress(Builder builder)
    {
        super(builder);
        otsAddress = builder.otsAddress;
        chainAddress = builder.chainAddress;
        hashAddress = builder.hashAddress;
    }

    protected static class Builder
        extends XMSSAddress.Builder
    {

        /* optional */
        private int otsAddress = 0;
        private int chainAddress = 0;
        private int hashAddress = 0;

        protected Builder()
        {
            super(TYPE);
        }

        protected Builder withOTSAddress(int val)
        {
            otsAddress = val;
            return this;
        }

        protected Builder withChainAddress(int val)
        {
            chainAddress = val;
            return this;
        }

        protected Builder withHashAddress(int val)
        {
            hashAddress = val;
            return this;
        }

        @Override
        protected XMSSAddress build()
        {
            return new OTSHashAddress(this);
        }

        @Override
        protected Builder getThis()
        {
            return this;
        }
    }

    @Override
    protected byte[] toByteArray()
    {
        byte[] byteRepresentation = super.toByteArray();
        Pack.intToBigEndian(otsAddress, byteRepresentation,16);
        Pack.intToBigEndian(chainAddress, byteRepresentation, 20);
        Pack.intToBigEndian(hashAddress, byteRepresentation, 24);
        return byteRepresentation;
    }

    protected int getOTSAddress()
    {
        return otsAddress;
    }

    protected int getChainAddress()
    {
        return chainAddress;
    }

    protected int getHashAddress()
    {
        return hashAddress;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy