⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cryptfs.fist

📁 Solaris操作系统下的过滤驱动程序, C源码程序.
💻 FIST
字号:
%{extern unsigned char global_iv[8];#include <blowfish.h>%}debug on;filter data;filter name;// we are using the Blowfish block cipher in the cfb64 stream emulation modeencoding_blocksize 1;encoding_type stream;mod_src bf_cfb64.c bf_enc.c bf_skey.c;mod_hdr bf_locl.h bf_pi.h blowfish.h;user_src fist_setkey.c fist_getiv.c;ioctl:fromuser SETKEY {  char ukey[16];};ioctl:touser GETIV {  char outiv[8];};pervfs {  BF_KEY key;};%%%op:ioctl:SETKEY {  char temp_buf[16];  if (fistGetIoctlData(SETKEY, ukey, temp_buf) < 0)    fistSetErr(EFAULT);  else    BF_set_key(&$vfs.key, 16, temp_buf);}%op:ioctl:GETIV {  if (fistSetIoctlData(GETIV, outiv, global_iv) < 0)    fistSetErr(EFAULT);}%%unsigned char global_iv[8] = {  0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};intcryptfs_encode_block(const char *from, char *to, int len, const vnode_t *this_vnode, const vfs_t *this_vfs, u_long pagenum){  int n = 0;			/* internal blowfish variables */  unsigned char iv[8];  fistMemCpy(iv, global_iv, 8);	/* initialize from global IV */  BF_cfb64_encrypt((char *)from, to, len,                   &($vfs.key), iv, &n,                   BF_ENCRYPT);  return len;}intcryptfs_decode_block(const char *from, char *to, int len, const vnode_t *this_vnode, const vfs_t *this_vfs, u_long pagenum){  int n = 0;			/* internal blowfish variables */  unsigned char iv[8];  fistMemCpy(iv, global_iv, 8);	/* initialize from global IV */  BF_cfb64_encrypt((char *) from, to, len,		   &($vfs.key), iv, &n,		   BF_DECRYPT);  return len;}intcryptfs_encode_filename(const char *name,			int length,			char **encoded_name,			int skip_dots,			const vnode_t *this_vnode,			const vfs_t *this_vfs){    char *crypted_name = NULL;    const char *ptr;    int rounded_length = 0, encoded_length, n, i, j;    unsigned char iv[8];    short csum;    void *key = &($vfs.key);    fist_dprint(8, "ENCODEFILENAME: cleartext filename \"%s\"\n", name);    if ((skip_dots && (name[0] == '.' &&		       (length == 1 ||			(name[1] == '.' && length == 2))))) {	encoded_length = length + 1;	if (encoded_length > MAXPATHLEN) { /* check for corruption */	  encoded_length = -ENAMETOOLONG;	  goto out;	}	*encoded_name = fistMalloc(encoded_length);	if (!*encoded_name) {	  encoded_length = -ENOMEM;	  goto out;	}	fistMemCpy(*encoded_name, name, length);	(*encoded_name)[length] = '\0';	goto out;    }    for (csum = 0, i = 0, ptr = name; i < length; ptr++, i++)	csum += *ptr;    /*     * rounded_length is an multiple of 3 rounded-up length     * the encode algorithm processes 3 source bytes at a time     * so we have to make sure we don't read past the memory     * we have allocated     *     * it uses length + 3 to provide 2 bytes for the checksum     * and one byte for the length     */    rounded_length = (((length + 3) + 2) / 3) * 3;    if (rounded_length > MAXPATHLEN) { /* check for corruption */      encoded_length = -ENAMETOOLONG;      goto out;    }    crypted_name = fistMalloc(rounded_length);    if (!crypted_name) {      encoded_length = -ENOMEM;      goto out;    }    fistMemCpy(iv, global_iv, 8);    n = 0;    *(short *) crypted_name = csum;    crypted_name[2] = length;    BF_cfb64_encrypt((char *) name, crypted_name + 3,		     length, (BF_KEY *) key, iv, &n,		     BF_ENCRYPT);    /*     * clear the last few unused bytes     * so that we get consistent results from encode     */    for (i = length + 3; i < rounded_length; i++)	crypted_name[i] = 0;    encoded_length = (((length + 3) + 2) / 3) * 4 + 1;    if (encoded_length > MAXPATHLEN) { /* check for corruption */      encoded_length = -ENAMETOOLONG;      goto out;    }    *encoded_name = fistMalloc(encoded_length);    if (!*encoded_name) {      encoded_length = -ENOMEM;      goto out;    }    for (i = 0, j = 0; i < rounded_length; i += 3, j += 4) {	(*encoded_name)[j] = 48 + ((crypted_name[i] >> 2) & 63);	(*encoded_name)[j + 1] = 48 + (((crypted_name[i] << 4) & 48) | ((crypted_name[i + 1] >> 4) & 15));	(*encoded_name)[j + 2] = 48 + (((crypted_name[i + 1] << 2) & 60) | ((crypted_name[i + 2] >> 6) & 3));	(*encoded_name)[j + 3] = 48 + (crypted_name[i + 2] & 63);    }    (*encoded_name)[j] = '\0'; out:    if (crypted_name)      fistFree(crypted_name, rounded_length);    fist_dprint(8, "ENCODEFILENAME: encoded filename \"%s\"\n", *encoded_name);    return encoded_length;}intcryptfs_decode_filename(const char *name,			int length,			char **decrypted_name,			int skip_dots,			const vnode_t *this_vnode,			const vfs_t *this_vfs){    int n, i, j, saved_length, saved_csum, csum;    int uudecoded_length, error = 0;    unsigned char iv[8];    char *uudecoded_name;    void *key = &($vfs.key);    if ((skip_dots && (name[0] == '.' &&		       (length == 1 ||			(name[1] == '.' && length == 2))))) {	if (length > MAXPATHLEN) { /* check for corruption */	  error = -ENAMETOOLONG;	  goto out;	}	*decrypted_name = fistMalloc(length);	if (!*decrypted_name) {	  error = -ENOMEM;	  goto out;	}	for (i = 0; i < length; i++)	    (*decrypted_name)[i] = name[i];	error = length;	goto out;    }    if (key == NULL) {	error = -EACCES;	goto out;    }    uudecoded_length = ((length + 3) / 4) * 3;    if (uudecoded_length > MAXPATHLEN) { /* check for corruption */      error = -ENAMETOOLONG;      goto out;    }    uudecoded_name = fistMalloc(uudecoded_length);    if (!uudecoded_name) {      error = -ENOMEM;      goto out;    }    for (i = 0, j = 0; i < length; i += 4, j += 3) {	uudecoded_name[j] = ((name[i] - 48) <<2) | ((name[i + 1] - 48) >>4);	uudecoded_name[j + 1] = (((name[i + 1] - 48) <<4) & 240) | ((name[i + 2] - 48) >>2);	uudecoded_name[j + 2] = (((name[i + 2] - 48) <<6) & 192) | ((name[i + 3] - 48) &63);    }    saved_csum = *(short *) uudecoded_name;    saved_length = uudecoded_name[2];    if (saved_length > uudecoded_length) {	fist_dprint(7, "Problems with the length - too big: %d", saved_length);	error = -EACCES;	goto out_free;    }    if (saved_length+1 > MAXPATHLEN) { /* check for corruption */      error = -ENAMETOOLONG;      goto out_free;    }    *decrypted_name = (char *) fistMalloc(saved_length+1); /* +1 for null */    if (!*decrypted_name) {      error = -ENOMEM;      goto out_free;    }    (*decrypted_name)[saved_length] = '\0'; /* null terminate */    fistMemCpy(iv, global_iv, 8);    n = 0;    BF_cfb64_encrypt(uudecoded_name + 3, *decrypted_name,		     saved_length, (BF_KEY *) key, iv, &n,		     BF_DECRYPT);    for (csum = 0, i = 0; i < saved_length; i++)	csum += (*decrypted_name)[i];    if (csum != saved_csum) {	fist_dprint(7, "Checksum error\n");	fistFree(*decrypted_name, saved_length);	error = -EACCES;	goto out_free;    }    error = saved_length + 1; out_free:    fistFree(uudecoded_name, uudecoded_length); out:    return error;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -