Esempio n. 1
0
    public const int TRAP   = 200;   // 200 for 4 digit PIN, 2000 for 6-digit PIN  - approx 2*sqrt(MAXPIN)

/* Hash number (optional) and string to point on curve */

    public static sbyte[] hashit(int n, sbyte[] ID)
    {
        HASH H = new HASH();

        if (n != 0)
        {
            H.process_num(n);
        }
        H.process_array(ID);
        sbyte[] h = H.hash();
        return(h);
    }
Esempio n. 2
0
/* Key Derivation Functions */
/* Input octet Z */
/* Output key of length olen */
    public static sbyte[] KDF1(sbyte[] Z, int olen)
    {
/* NOTE: the parameter olen is the length of the output K in bytes */
        HASH H    = new HASH();
        int  hlen = HASH.len;

        sbyte[] K = new sbyte[olen];

        sbyte[] B;
        int     counter, cthreshold, k = 0;

        for (int i = 0; i < K.Length; i++)
        {
            K[i] = 0;
        }

        cthreshold = olen / hlen;
        if (olen % hlen != 0)
        {
            cthreshold++;
        }

        for (counter = 0; counter < cthreshold; counter++)
        {
            H.process_array(Z);
            if (counter > 0)
            {
                H.process_num(counter);
            }
            B = H.hash();
            if (k + hlen > olen)
            {
                for (int i = 0; i < olen % hlen; i++)
                {
                    K[k++] = B[i];
                }
            }
            else
            {
                for (int i = 0; i < hlen; i++)
                {
                    K[k++] = B[i];
                }
            }
        }
        return(K);
    }
Esempio n. 3
0
/* Mask Generation Function */

    public static void MGF1(sbyte[] Z, int olen, sbyte[] K)
    {
        HASH H    = new HASH();
        int  hlen = HASH.len;

        sbyte[] B = new sbyte[hlen];

        int counter, cthreshold, k = 0;

        for (int i = 0; i < K.Length; i++)
        {
            K[i] = 0;
        }

        cthreshold = olen / hlen;
        if (olen % hlen != 0)
        {
            cthreshold++;
        }
        for (counter = 0; counter < cthreshold; counter++)
        {
            H.process_array(Z);
            H.process_num(counter);
            B = H.hash();

            if (k + hlen > olen)
            {
                for (int i = 0; i < olen % hlen; i++)
                {
                    K[k++] = B[i];
                }
            }
            else
            {
                for (int i = 0; i < hlen; i++)
                {
                    K[k++] = B[i];
                }
            }
        }
    }