예제 #1
0
파일: HmacSha256.cs 프로젝트: relaxar/nsec
 internal override void CreateKey(
     ReadOnlySpan <byte> seed,
     out SecureMemoryHandle keyHandle,
     out PublicKey?publicKey)
 {
     publicKey = null;
     keyHandle = SecureMemoryHandle.CreateFrom(seed);
 }
예제 #2
0
        internal override void CreateKey(
            ReadOnlySpan <byte> seed,
            out SecureMemoryHandle keyHandle,
            out PublicKey?publicKey)
        {
            Debug.Assert(seed.Length == crypto_aead_chacha20poly1305_ietf_KEYBYTES);

            publicKey = null;
            keyHandle = SecureMemoryHandle.CreateFrom(seed);
        }
예제 #3
0
파일: Blake2bMac.cs 프로젝트: relaxar/nsec
        internal override void CreateKey(
            ReadOnlySpan <byte> seed,
            out SecureMemoryHandle keyHandle,
            out PublicKey?publicKey)
        {
            Debug.Assert(seed.Length >= crypto_generichash_blake2b_KEYBYTES_MIN);
            Debug.Assert(seed.Length <= crypto_generichash_blake2b_KEYBYTES_MAX);

            publicKey = null;
            keyHandle = SecureMemoryHandle.CreateFrom(seed);
        }
예제 #4
0
        public static bool TryImport(
            int keySize,
            ReadOnlySpan <byte> blob,
            out SecureMemoryHandle?keyHandle)
        {
            if (blob.Length != keySize)
            {
                keyHandle = default;
                return(false);
            }

            keyHandle = SecureMemoryHandle.CreateFrom(blob);
            return(true);
        }
예제 #5
0
        public static bool TryImport(
            uint blobHeader,
            int keySize,
            int outputSize,
            ReadOnlySpan <byte> blob,
            out SecureMemoryHandle?keyHandle)
        {
            if (blob.Length != sizeof(uint) + sizeof(short) + sizeof(short) + keySize ||
                BinaryPrimitives.ReadUInt32BigEndian(blob) != blobHeader ||
                BinaryPrimitives.ReadInt16LittleEndian(blob.Slice(sizeof(uint))) != keySize ||
                BinaryPrimitives.ReadInt16LittleEndian(blob.Slice(sizeof(uint) + sizeof(short))) != outputSize)
            {
                keyHandle = default;
                return(false);
            }

            keyHandle = SecureMemoryHandle.CreateFrom(blob.Slice(sizeof(uint) + sizeof(short) + sizeof(short), keySize));
            return(true);
        }
예제 #6
0
        protected override unsafe void Deserialize(
            ReadOnlySpan <byte> span,
            out SecureMemoryHandle?keyHandle,
            out PublicKeyBytes publicKeyBytes)
        {
            if (Unsafe.SizeOf <PublicKeyBytes>() != crypto_scalarmult_curve25519_SCALARBYTES)
            {
                throw Error.InvalidOperation_InternalError();
            }

            Debug.Assert(span.Length == crypto_scalarmult_curve25519_SCALARBYTES);

            keyHandle = SecureMemoryHandle.CreateFrom(span);

            fixed(PublicKeyBytes *q = &publicKeyBytes)
            {
                int error = crypto_scalarmult_curve25519_base(q, keyHandle);

                Debug.Assert(error == 0);
                Debug.Assert((((byte *)q)[crypto_scalarmult_curve25519_SCALARBYTES - 1] & 0x80) == 0);
            }
        }
예제 #7
0
        internal override unsafe void CreateKey(
            ReadOnlySpan <byte> seed,
            out SecureMemoryHandle keyHandle,
            out PublicKey?publicKey)
        {
            if (Unsafe.SizeOf <PublicKeyBytes>() != crypto_scalarmult_curve25519_SCALARBYTES)
            {
                throw Error.InvalidOperation_InternalError();
            }

            Debug.Assert(seed.Length == crypto_scalarmult_curve25519_SCALARBYTES);

            publicKey = new PublicKey(this);
            keyHandle = SecureMemoryHandle.CreateFrom(seed);

            fixed(PublicKeyBytes *q = publicKey)
            {
                int error = crypto_scalarmult_curve25519_base(q, keyHandle);

                Debug.Assert(error == 0);
                Debug.Assert((((byte *)q)[crypto_scalarmult_curve25519_SCALARBYTES - 1] & 0x80) == 0);
            }
        }