-
Notifications
You must be signed in to change notification settings - Fork 0
/
decrypt_verify_update.go
45 lines (41 loc) · 1.29 KB
/
decrypt_verify_update.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package certex
/*
#include <stdlib.h>
#include <dlfcn.h>
#include <unistd.h>
#include <stdio.h>
#include "./headers/cryptoki.h"
#include "./headers/pkcs11def.h"
#include "./headers/pkcs11t.h"
#include "./headers/PKICertexHSM.h"
CK_RV decrypt_verify_update(CK_FUNCTION_LIST_PTR fl, CK_SESSION_HANDLE hSession, CK_BYTE_PTR pEncryptedPart, CK_ULONG ulEncryptedPartLen, CK_BYTE_PTR *pPart, CK_ULONG_PTR pulPartLen) {
CK_RV rv = (*fl->C_DecryptVerifyUpdate)(hSession, pEncryptedPart, ulEncryptedPartLen, NULL, pulPartLen);
if (rv != CKR_OK) {
return rv;
}
*pPart = calloc(*pulPartLen, sizeof(CK_BYTE));
if (*pPart == NULL) {
return CKR_HOST_MEMORY;
}
rv = (*fl->C_DecryptVerifyUpdate)(hSession, pEncryptedPart, ulEncryptedPartLen, *pPart, pulPartLen);
return rv;
}
*/
import "C"
import (
"fmt"
"unsafe"
)
// Continues a multiple-part decryption and verify operation.
func (o *Object) DecryptVerifyUpdate(encPart []byte) ([]byte, error) {
var (
part C.CK_BYTE_PTR
partLen C.CK_ULONG
)
if rv := C.decrypt_verify_update(o.fl, o.h, cData(encPart), C.CK_ULONG(len(encPart)), &part, &partLen); rv != C.CKR_OK {
return nil, fmt.Errorf("decrypt_verify_update: 0x%08x : %s", rv, returnValues[rv])
}
d := C.GoBytes(unsafe.Pointer(part), C.int(partLen))
C.free(unsafe.Pointer(part))
return d, nil
}