示例#1
0
        private static void SodiumHash(HashType type, byte[] buffer, byte[] hash)
        {
            switch (type)
            {
            case HashType.Blake2B:
            {
                Blake2B.TryComputeHash(buffer, hash, out _);
                break;
            }

            case HashType.SipHash24:
            {
                SodiumLibrary.crypto_shorthash(hash, buffer, buffer.LongLength, SipHash24Key);
                break;
            }

            case HashType.Sha256:
            {
                SodiumLibrary.crypto_hash_sha256(hash, buffer, buffer.LongLength);
                break;
            }

            case HashType.Sha512:
            {
                SodiumLibrary.crypto_hash_sha512(hash, buffer, buffer.LongLength);
                break;
            }

            case HashType.Md5:
            case HashType.Sha1:
            case HashType.Sha384:
            default:
                throw new NotSupportedException();
            }
        }
示例#2
0
        public static byte[] Generate(int Size)
        {
            var Buffer = new byte[Size];

            SodiumLibrary.randombytes_buf(Buffer, Size);

            return(Buffer);
        }
示例#3
0
        public void WhenInitialisationIsPerformed()
        {
            const CipherSuiteName  cipherSuiteName = CipherSuiteName.Ristretto255_SHA512;
            PrimeOrderGroupFactory pogFactory      = new();
            HashFunctionFactory    hfFactory       = new();
            CipherSuite            cipherSuite     = new CipherSuite(cipherSuiteName, ProtocolMode.Base, pogFactory, hfFactory);

            SodiumLibrary.InitialiseCryptography();
            LogAssert.AreEqual("Sodium library version", "1.0.18", SodiumLibrary.GetSodiumLibraryVersion());

            BaseModeClientContext clientContext = new(cipherSuite);
            BaseModeServerContext serverContext = new(cipherSuite);
        }
        public void BeforeScenario()
        {
            SodiumLibrary.InitialiseCryptography();

            _cipherSuiteName = CipherSuiteName.Ristretto255_SHA512;
            PrimeOrderGroupFactory pogFactory = new();
            HashFunctionFactory    hfFactory  = new();

            _cipherSuite = new CipherSuite(_cipherSuiteName, ProtocolMode.Base, pogFactory, hfFactory);

            _pog = _cipherSuite.PrimeOrderGroup;

            _clientContext = new(_cipherSuite);
            _serverContext = new(_cipherSuite);
        }
示例#5
0
 public static bool Verify(byte[] Signature, byte[] Message, byte[] Key)
 {
     return(SodiumLibrary.crypto_sign_verify_detached(Signature, Message, Message.Length, Key) == 0);
 }