Ejemplo n.º 1
0
        private static void EnsureCrtInitialized()
        {
            if (expensiveCrtInitialization)
            {
                return;
            }

            lock (expensiveCrtInitializationLock)
            {
                if (expensiveCrtInitialization)
                {
                    return;
                }

                nativeKeyDerivationFunction = EscapeExecutionContext(() =>
                {
                    Assembly assembly;
                    if (IntPtr.Size == 4)
                    {
                        assembly = Assembly.Load("Replicon.Cryptography.SCrypt.MMA, Version=1.1.6.13, Culture=neutral, PublicKeyToken=4e0c787cc79e77b2, processorArchitecture=x86");
                    }
                    else
                    {
                        assembly = Assembly.Load("Replicon.Cryptography.SCrypt.MMA, Version=1.1.6.13, Culture=neutral, PublicKeyToken=4e0c787cc79e77b2, processorArchitecture=amd64");
                    }
                    var type = assembly.GetType("Replicon.Cryptography.SCrypt.MMA.SCrypt");
                    return((IKeyDerivationFunction)Activator.CreateInstance(type));
                });
                expensiveCrtInitialization = true;
            }
        }
Ejemplo n.º 2
0
 public AesEncryptor(IKeyDerivationFunction keyDeriver, IFastRandom fastRandom) : base(fastRandom)
 {
     if (keyDeriver == null)
     {
         throw new ArgumentNullException(nameof(keyDeriver));
     }
     _keyDeriver = keyDeriver;
 }
Ejemplo n.º 3
0
        public CryptoStorage(IKeyDerivationFunction kdf, IEncryptor encryptor)
            : this()
        {
            kdf.ThrowIfNull(nameof(kdf));
            encryptor.ThrowIfNull(nameof(encryptor));

            this.kdf       = kdf;
            this.encryptor = encryptor;
        }
        /// <summary>
        /// Create an IKeyDerivationFunction implemented by a mixed-mode assembly.  This is a high-performance
        /// implementation using SSE2, but requires support for C++/CLI mixed-mode assemblies (ie. doesn't work on
        /// Mono), and requires that the current environment be supported (.NET 3.5 or 4.0, x86 or x64).
        /// </summary>
        /// <remarks>If the mixed-mode assembly cannot be loaded, this method will... FIXME: what?</remarks>
        public static IKeyDerivationFunction CreateNativeKeyDerivationFunction()
        {
            if (nativeKdf != null)
                return nativeKdf;

            lock (kdfCreationLock)
            {
                if (nativeKdf != null)
                    return nativeKdf;

                return nativeKdf = new MixedModeAssemblyKeyDerivationFunction();
            }
        }
Ejemplo n.º 5
0
        public DiffieHellmanRatchet(ILogger <DiffieHellmanRatchet> _logger, IDiffieHellmanHandler _DHH, IKeyDerivationFunction _kdf, ISignatureHandler _signer)
        {
            logger = _logger;
            dHH    = _DHH;
            kdf    = _kdf;
            signer = _signer;
            logger = _logger;

            // create identity key
            (x509IdentityKey, x509IdentityPrivateKey) = dHH.GenerateKeys();

            // create starting keys
            (publicKey, privateKey) = dHH.GenerateKeys();

            // sign the identity key
            SignPublicKey();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Create an IKeyDerivationFunction.
        /// </summary>
        public static IKeyDerivationFunction CreateSCryptKeyDerivationFunction()
        {
            if (Kdf != null)
            {
                return(Kdf);
            }

            lock (kdfCreationLock)
            {
                if (Kdf != null)
                {
                    return(Kdf);
                }

                return(Kdf = new KeyDerivationFunction());
            }
        }
        /// <summary>
        /// Create an IKeyDerivationFunction implemented by a mixed-mode assembly.  This is a high-performance
        /// implementation using SSE2, but requires support for C++/CLI mixed-mode assemblies (ie. doesn't work on
        /// Mono), and requires that the current environment be supported (.NET 3.5 or 4.0, x86 or x64).
        /// </summary>
        /// <remarks>If the mixed-mode assembly cannot be loaded, this method will... FIXME: what?</remarks>
        public static IKeyDerivationFunction CreateNativeKeyDerivationFunction()
        {
            if (nativeKdf != null)
            {
                return(nativeKdf);
            }

            lock (kdfCreationLock)
            {
                if (nativeKdf != null)
                {
                    return(nativeKdf);
                }

                return(nativeKdf = new MixedModeAssemblyKeyDerivationFunction());
            }
        }
Ejemplo n.º 8
0
 public AesEncryptor(IKeyDerivationFunction keyDeriver) : this(
         keyDeriver,
         SafeOrbitCore.Current.Factory.Get <IFastRandom>())
 {
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Create an IPasswordHash implementation, using the provided key-derivation function implementation.
 /// </summary>
 public static IPasswordHash CreatePasswordHash(IKeyDerivationFunction kdf)
 {
     return(new DefaultPasswordHash(kdf));
 }
 public void TestFixtureSetUp()
 {
     kdf = Create();
 }
 public void OneTimeSetUpAttribute()
 {
     kdf = Create();
 }
Ejemplo n.º 12
0
 public CryptoStorage(IKeyDerivationFunction kdf, IEncryptor encryptor, Stream dataSource)
     : this(kdf, encryptor)
 {
     DataSource = dataSource;
 }
 public DefaultPasswordHash(IKeyDerivationFunction kdf)
 {
     this.kdf = kdf;
 }
Ejemplo n.º 14
0
 internal static void Serialize(Stream destination, IKeyDerivationFunction obj)
 {
     destination.ThrowIfNull(nameof(destination));
     obj.ThrowIfNull(nameof(obj));
     GenericSerializer.Serialize(destination, obj, TypeToEnumMappings, FormatExceptionMessage);
 }
Ejemplo n.º 15
0
 public DefaultPasswordHash(IKeyDerivationFunction kdf)
 {
     this.kdf = kdf;
 }
 /// <summary>
 /// Create an IPasswordHash implementation, using the provided key-derivation function implementation.
 /// </summary>
 public static IPasswordHash CreatePasswordHash(IKeyDerivationFunction kdf)
 {
     return new DefaultPasswordHash(kdf);
 }
Ejemplo n.º 17
0
 protected ISafeEncryptor GetSut(IKeyDerivationFunction kdf = null, IFastRandom random = null)
 {
     return(new AesEncryptor(kdf ?? Stubs.Get <IKeyDerivationFunction>(), random ?? Stubs.Get <IFastRandom>()));
 }
 public void TestFixtureSetUp()
 {
     kdf = Create();
 }