blob: 4b9b9c5d5ea9ad2754922e0572bae4510dc8faec [file] [log] [blame]
a39552696ff55ce2013-01-08 16:14:56 +00001/*
2 * Copyright (c) 2013 a3955269 all rights reversed, no rights reserved.
3 */
4
5//////////////////////////////////////////////////////////////////////////////
6
7#include <string.h>
8#include <stdio.h>
9#include <dlfcn.h>
10
11#include "include/libcrypt_samsung.h"
12
13//////////////////////////////////////////////////////////////////////////////
14void xconvert_key_to_hex_ascii(unsigned char *master_key, unsigned int keysize,
15 char *master_key_ascii)
16{
17 unsigned int i, a;
18 unsigned char nibble;
19
20 for (i=0, a=0; i<keysize; i++, a+=2) {
21 /* For each byte, write out two ascii hex digits */
22 nibble = (master_key[i] >> 4) & 0xf;
23 master_key_ascii[a] = nibble + (nibble > 9 ? 0x37 : 0x30);
24
25 nibble = master_key[i] & 0xf;
26 master_key_ascii[a+1] = nibble + (nibble > 9 ? 0x37 : 0x30);
27 }
28
29 /* Add the null termination */
30 master_key_ascii[a] = '\0';
31
32}
33
34int decrypt_EDK(
35 dek_t *dek, const edk_payload_t *edk, /*const*/ char *passwd)
36{
37 void *lib = dlopen("libsec_km.so", RTLD_LAZY);
38
39 if(!lib)
40 return -100;
41
42 int r = -101;
43 decrypt_EDK_t sym = (decrypt_EDK_t)dlsym(lib, "decrypt_EDK");
44 if(sym)
45 r = sym(dek, edk, passwd);
46
47 dlclose(lib);
48
49 return r;
50}
51
52int mount_ecryptfs_drive(
53 const char *passwd, const char *source, const char *target, int filter)
54{
55 void *lib = dlopen("libsec_ecryptfs.so", RTLD_LAZY);
56 if(!lib)
57 return -100;
58
59 int r = -101;
60 mount_ecryptfs_drive_t sym = (mount_ecryptfs_drive_t)dlsym(lib, "mount_ecryptfs_drive");
61 if(sym)
62 r = sym(passwd, source, target, filter);
63
64 dlclose(lib);
65
66 return r;
67}
68