Beispiel #1
0
 public static void RandSeed(byte[] seed)
 {
     using (var disposableSeed = new DisposablePtr(KEY_SIZE))
     {
         Marshal.Copy(seed, 0, disposableSeed.ptr, seed.Length);
         dh_rand_seed(disposableSeed.ptr, (uint)seed.Length);
     }
 }
Beispiel #2
0
 public static bool Update(byte[] msg, int offset, int length)
 {
     using (var disposableMsg = new DisposablePtr(length))
     {
         Marshal.Copy(msg, offset, disposableMsg.ptr, length);
         return(cmac_update(disposableMsg.ptr, length) == 1);
     }
 }
Beispiel #3
0
 public static bool Init(byte[] key)
 {
     using (var disposableKey = new DisposablePtr(KEY_SIZE))
     {
         Marshal.Copy(key, 0, disposableKey.ptr, KEY_SIZE);
         return(cmac_init(disposableKey.ptr) == 1);
     }
 }
Beispiel #4
0
 public static void ComputeKey(out byte[] key, byte[] remote_public_key
                               , int key_offset = 0, int remote_public_key_offset = 0)
 {
     key = new byte[KEY_SIZE];
     using (var disposableKey = new DisposablePtr(KEY_SIZE))
         using (var disposableRemotePublicKey = new DisposablePtr(KEY_SIZE))
         {
             Marshal.Copy(remote_public_key, remote_public_key_offset, disposableRemotePublicKey.ptr, KEY_SIZE);
             dh_compute_key(out disposableKey.ptr, disposableRemotePublicKey.ptr);
             Marshal.Copy(disposableKey.ptr, key, key_offset, KEY_SIZE);
         }
 }
Beispiel #5
0
 public static bool GenerateKey(out byte[] public_key)
 {
     public_key = new byte[KEY_SIZE];
     using (var disposablePublicKey = new DisposablePtr(KEY_SIZE))
     {
         if (dh_generate_key(out disposablePublicKey.ptr) != 0)
         {
             Marshal.Copy(disposablePublicKey.ptr, public_key, 0, KEY_SIZE);
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Beispiel #6
0
 public static bool Final(out byte[] mac)
 {
     mac = new byte[MAC_SIZE];
     using (var disposableMac = new DisposablePtr(MAC_SIZE))
     {
         if (cmac_final(out disposableMac.ptr) == 1)
         {
             Marshal.Copy(disposableMac.ptr, mac, 0, MAC_SIZE);
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }