MCPcopy Create free account
hub / github.com/bailey27/cppcryptfs / derive_path_iv

Function derive_path_iv

libcppcryptfs/filename/cryptfilename.cpp:71–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69}
70
71bool
72derive_path_iv(CryptContext *con, const WCHAR *path, unsigned char *iv, const char *type)
73{
74
75 //DbgPrint(L"derive_path_iv path = %s, type = %S\n", path, type);
76
77 wstring wpath;
78
79 const WCHAR *pathstr = path;
80
81 if (*pathstr == '\\' || *pathstr == '/')
82 pathstr++;
83
84 wpath = pathstr;
85
86 if (wpath.length() > 0) {
87 if (wpath[wpath.length() - 1] == '\\' || wpath[wpath.length()] - 1 == '/')
88 wpath.erase(wpath.length() - 1);
89 }
90
91 int i;
92 int len = (int)wpath.length();
93 for (i = 0; i < len; i++) {
94 if (wpath[i] == '\\')
95 wpath[i] = '/';
96 }
97
98 string utf8path;
99
100 if (!unicode_to_utf8(&wpath[0], utf8path))
101 return false;
102
103 bool bRet = true;
104
105 TempBuffer<BYTE, 4096> buffer;
106
107 BYTE *pbuf = NULL;
108
109 try {
110 int typelen = (int)strlen(type);
111 int bufsize = (int)(utf8path.length() + 1 + typelen);
112 pbuf = buffer.get(bufsize);
113 if (!pbuf)
114 throw(-1);
115 memcpy(pbuf, &utf8path[0], utf8path.length() + 1);
116 memcpy(pbuf + utf8path.length() + 1, type, typelen);
117 BYTE hash[SHA256_LEN];
118 if (!sha256(pbuf, bufsize, hash))
119 throw(-1);
120
121 memcpy(iv, hash, DIR_IV_LEN); // all iv's are 16 bytes (DIR_IV_LEN)
122
123 } catch (...) {
124 bRet = false;
125 }
126
127 return bRet;
128}

Callers 9

AssociateMethod · 0.85
find_filesFunction · 0.85
read_virtual_fileFunction · 0.85
convert_find_stream_dataFunction · 0.85
decrypt_pathFunction · 0.85
unencrypt_pathFunction · 0.85
encrypt_pathFunction · 0.85
get_actual_encryptedFunction · 0.85

Calls 4

unicode_to_utf8Function · 0.85
sha256Function · 0.85
eraseMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected