public static void C_VerifyInit(CK_SESSION_HANDLE session, CK_MECHANISM mech, CK_OBJECT_HANDLE key)
 {
     CK_MECHANISM.Native m = new CK_MECHANISM.Native(mech);
     try { CKR_Exception.check(isWindows ?
                               LibraryWindows.fl.C_VerifyInit(session.Handle, m.windows, key.Handle):
                               LibraryUnix.fl.C_VerifyInit(session.Handle, ref m.unix, key.Handle)
                               , "C_VerifyInit"); }
     finally { m.Free(); }
 }
 public static void C_DigestInit(CK_SESSION_HANDLE session, CK_MECHANISM mech)
 {
     CK_MECHANISM.Native m = new CK_MECHANISM.Native(mech);
     try { CKR_Exception.check(isWindows ?
                               LibraryWindows.fl.C_DigestInit(session.Handle, m.windows):
                               LibraryUnix.fl.C_DigestInit(session.Handle, ref m.unix)
                               , "C_DigestInit"); }
     finally { m.Free(); }
 }
        public static int C_WrapKey(CK_SESSION_HANDLE session, CK_MECHANISM mech, CK_OBJECT_HANDLE key, CK_OBJECT_HANDLE wrappedKey, byte[] output)
        {
            CK_MECHANISM.Native m = new CK_MECHANISM.Native(mech);
            int outSize           = output == null ? 0 : output.Length;

            try { CKR_Exception.check(fl.C_WrapKey(session.Handle, m, key.Handle, wrappedKey.Handle, output, ref outSize), "C_WrapKey"); }
            finally { m.Free(); }
            return(outSize);
        }
        public static CK_OBJECT_HANDLE C_GenerateKey(CK_SESSION_HANDLE session, CK_MECHANISM mech, CK_ATTRIBUTE[] pTemplate)
        {
            CK_MECHANISM.Native   m = new CK_MECHANISM.Native(mech);
            CK_ATTRIBUTE.Native[] t = CK_ATTRIBUTE.ToNative(pTemplate);
            uint keyHandle          = 0;

            try { CKR_Exception.check(fl.C_GenerateKey(session.Handle, m, t, t.Length, out keyHandle), "C_GenerateKey"); }
            finally { m.Free(); CK_ATTRIBUTE.Free(t); }
            return(new CK_OBJECT_HANDLE(keyHandle));
        }
        public static CK_OBJECT_HANDLE C_UnwrapKey(CK_SESSION_HANDLE session, CK_MECHANISM mech, CK_OBJECT_HANDLE key, byte[] input, CK_ATTRIBUTE[] pTemplate)
        {
            CK_MECHANISM.Native   m = new CK_MECHANISM.Native(mech);
            CK_ATTRIBUTE.Native[] t = CK_ATTRIBUTE.ToNative(pTemplate);
            int  inSize             = input == null ? 0 : input.Length;
            uint unwrappedKeyHandle = 0;

            try { CKR_Exception.check(fl.C_UnwrapKey(session.Handle, m, key.Handle, input, inSize, t, t.Length, out unwrappedKeyHandle), "C_UnwrapKey"); }
            finally { m.Free(); CK_ATTRIBUTE.Free(t); }
            return(new CK_OBJECT_HANDLE(unwrappedKeyHandle));
        }
        public static int C_WrapKey(CK_SESSION_HANDLE session, CK_MECHANISM mech, CK_OBJECT_HANDLE key, CK_OBJECT_HANDLE wrappedKey, byte[] output)
        {
            CK_MECHANISM.Native m = new CK_MECHANISM.Native(mech);
            int  outSize          = output == null ? 0 : output.Length;
            long outSizeUnix      = output == null ? 0 : output.Length;

            try { CKR_Exception.check(isWindows ?
                                      LibraryWindows.fl.C_WrapKey(session.Handle, m.windows, key.Handle, wrappedKey.Handle, output, ref outSize):
                                      LibraryUnix.fl.C_WrapKey(session.Handle, ref m.unix, key.Handle, wrappedKey.Handle, output, ref outSizeUnix)
                                      , "C_WrapKey"); }
            finally { m.Free(); }
            return(isWindows ? outSize : (int)outSizeUnix);
        }
        public static CK_OBJECT_HANDLE C_GenerateKey(CK_SESSION_HANDLE session, CK_MECHANISM mech, CK_ATTRIBUTE[] pTemplate)
        {
            CK_MECHANISM.Native m = new CK_MECHANISM.Native(mech);
            CK_ATTRIBUTE.Native t = CK_ATTRIBUTE.ToNative(pTemplate);
            uint  keyHandle       = 0;
            ulong keyHandleUnix   = 0;

            try { CKR_Exception.check(isWindows ?
                                      LibraryWindows.fl.C_GenerateKey(session.Handle, m.windows, t.windows, t.Length, out keyHandle):
                                      LibraryUnix.fl.C_GenerateKey(session.Handle, ref m.unix, t.unix, t.Length, out keyHandleUnix)
                                      , "C_GenerateKey"); }
            finally { m.Free(); CK_ATTRIBUTE.Free(t); }
            return(new CK_OBJECT_HANDLE(isWindows ? keyHandle : (uint)keyHandleUnix));
        }
        public static CK_OBJECT_HANDLE C_UnwrapKey(CK_SESSION_HANDLE session, CK_MECHANISM mech, CK_OBJECT_HANDLE key, byte[] input, CK_ATTRIBUTE[] pTemplate)
        {
            CK_MECHANISM.Native m        = new CK_MECHANISM.Native(mech);
            CK_ATTRIBUTE.Native t        = CK_ATTRIBUTE.ToNative(pTemplate);
            int   inSize                 = input == null ? 0 : input.Length;
            uint  unwrappedKeyHandle     = 0;
            ulong unwrappedKeyHandleUnix = 0;

            try { CKR_Exception.check(isWindows ?
                                      LibraryWindows.fl.C_UnwrapKey(session.Handle, m.windows, key.Handle, input, inSize, t.windows, t.Length, out unwrappedKeyHandle):
                                      LibraryUnix.fl.C_UnwrapKey(session.Handle, ref m.unix, key.Handle, input, inSize, t.unix, t.Length, out unwrappedKeyHandleUnix)
                                      , "C_UnwrapKey"); }
            finally { m.Free(); CK_ATTRIBUTE.Free(t); }
            return(new CK_OBJECT_HANDLE(isWindows ? unwrappedKeyHandle : (uint)unwrappedKeyHandleUnix));
        }
        public static void C_GenerateKeyPair(CK_SESSION_HANDLE session, CK_MECHANISM mech,
                                             CK_ATTRIBUTE[] tPub,
                                             CK_ATTRIBUTE[] tPrv,
                                             out CK_OBJECT_HANDLE pubKey,
                                             out CK_OBJECT_HANDLE prvKey)
        {
            CK_ATTRIBUTE.Native[] tPubRaw = CK_ATTRIBUTE.ToNative(tPub);
            CK_ATTRIBUTE.Native[] tPrvRaw = CK_ATTRIBUTE.ToNative(tPrv);
            CK_MECHANISM.Native   m       = new CK_MECHANISM.Native(mech);
            uint pubKeyHandle             = 0;
            uint prvKeyHandle             = 0;

            try { CKR_Exception.check(fl.C_GenerateKeyPair(session.Handle, m, tPubRaw, tPub.Length, tPrvRaw, tPrv.Length, out pubKeyHandle, out prvKeyHandle), "C_GenerateKeyPair"); }
            finally { CK_ATTRIBUTE.Free(tPubRaw); CK_ATTRIBUTE.Free(tPrvRaw); m.Free(); }
            pubKey = new CK_OBJECT_HANDLE(pubKeyHandle);
            prvKey = new CK_OBJECT_HANDLE(prvKeyHandle);
        }
Exemplo n.º 10
0
        public static void C_GenerateKeyPair(CK_SESSION_HANDLE session, CK_MECHANISM mech,
                                             CK_ATTRIBUTE[] tPub,
                                             CK_ATTRIBUTE[] tPrv,
                                             out CK_OBJECT_HANDLE pubKey,
                                             out CK_OBJECT_HANDLE prvKey)
        {
            CK_ATTRIBUTE.Native tPubRaw = CK_ATTRIBUTE.ToNative(tPub);
            CK_ATTRIBUTE.Native tPrvRaw = CK_ATTRIBUTE.ToNative(tPrv);
            CK_MECHANISM.Native m       = new CK_MECHANISM.Native(mech);
            uint  pubKeyHandle          = 0;
            uint  prvKeyHandle          = 0;
            ulong pubKeyHandleUnix      = 0;
            ulong prvKeyHandleUnix      = 0;

            try { CKR_Exception.check(isWindows ?
                                      LibraryWindows.fl.C_GenerateKeyPair(session.Handle, m.windows, tPubRaw.windows, tPub.Length, tPrvRaw.windows, tPrv.Length, out pubKeyHandle, out prvKeyHandle):
                                      LibraryUnix.fl.C_GenerateKeyPair(session.Handle, ref m.unix, tPubRaw.unix, tPub.Length, tPrvRaw.unix, tPrv.Length, out pubKeyHandleUnix, out prvKeyHandleUnix)
                                      , "C_GenerateKeyPair"); }
            finally { CK_ATTRIBUTE.Free(tPubRaw); CK_ATTRIBUTE.Free(tPrvRaw); m.Free(); }
            pubKey = new CK_OBJECT_HANDLE(isWindows ? pubKeyHandle : (uint)pubKeyHandleUnix);
            prvKey = new CK_OBJECT_HANDLE(isWindows ? prvKeyHandle : (uint)prvKeyHandleUnix);
        }
Exemplo n.º 11
0
 public static void C_DigestInit(CK_SESSION_HANDLE session, CK_MECHANISM mech)
 {
     CK_MECHANISM.Native m = new CK_MECHANISM.Native(mech);
     try { CKR_Exception.check(fl.C_DigestInit(session.Handle, m), "C_DigestInit"); }
     finally { m.Free(); }
 }
Exemplo n.º 12
0
 public static void C_VerifyInit(CK_SESSION_HANDLE session, CK_MECHANISM mech, CK_OBJECT_HANDLE key)
 {
     CK_MECHANISM.Native m = new CK_MECHANISM.Native(mech);
     try { CKR_Exception.check(fl.C_VerifyInit(session.Handle, m, key.Handle), "C_VerifyInit"); }
     finally { m.Free(); }
 }