📄 bc_mgr.c
字号:
/******************************************************************* * Copyright (c) 1994-1998 Jetico, Inc., Finland * All rights reserved. * * File: driver/bc_mgr.c * * Description: algorithm manager, /proc filesystem support * * Scope: BestCrypt pseudo-device driver * * Platforms: Linux * * Author: Nail R. Kaipov * * Created: 10-Nov-1998 * * Revision: 11-Aug-1999. Bug fixed in get_bc_algo() * 21-Mar-2000. /proc/bcrypt output change (v0.4b-2) * 23-Jun-2000. /proc/bcrypt output change (v0.4b-5) * 07-Feb-2001. proc get_info->read_proc change * *******************************************************************/#include "bc_cfg.h"#include <linux/fs.h>#include <linux/mm.h>#include <linux/kernel.h>#include <linux/kmod.h>#include <linux/slab.h>#include <asm/segment.h>#include "bc_types.h"#include "bc_mgr.h"#define MODULE_NAMELEN 64struct bc_alg_mgr { struct bc_algorithm algo; struct bc_alg_mgr *next; char module_name[MODULE_NAMELEN+1]; u_int algo_flags; u_int algo_refcount;};static struct bc_alg_mgr *alg_head;int init_bc_algo(){ alg_head = NULL; return 0;}int proc_bc_conf(char *page, char **start, off_t off, int count, int *eof, void *data) { int len; char *p = page; struct bc_alg_mgr *tmp; p += sprintf(p, "# BestCrypt system v" BC_VERSION_STRING ":\n"); p += sprintf(p, "# Compiled at "__TIME__ " " __DATE__"\n"); for (tmp = alg_head; tmp; tmp = tmp->next) p += sprintf(p, "module\t%s\t0x%02x\t%d\t%s\n", tmp->module_name[0] ? tmp->module_name:"unknown", tmp->algo.id, tmp->algo.keylen, tmp->algo.name); len = p - page; if (len <= off+count) *eof = 1; *start = page + off; len -= off; if (len > count) len = count; if (len < 0) len = 0; return len;}static struct bc_alg_mgr *find_bc_algo(ALG_ID id){ struct bc_alg_mgr *tmp; for (tmp = alg_head; tmp; tmp = tmp->next) if (tmp->algo.id == id) return tmp; return NULL;}struct bc_algorithm *get_bc_algo(ALG_ID id, char *module_name){ struct bc_alg_mgr *algo; algo = find_bc_algo(id); if (algo) return &(algo->algo); if (!module_name) return NULL; request_module(module_name); /* new algos are linked to the head of list */ if ((NULL != alg_head) && (alg_head->algo.id == id)) { strncpy(alg_head->module_name, module_name, MODULE_NAMELEN); return &(alg_head->algo); } printk(KERN_ERR "bc: unsupported algorithm (id=%d).\n", id); return NULL;}/*-- these functions are called from algo modules only --------*/int register_bc_algo(struct bc_algorithm *algo){ struct bc_alg_mgr *new_algo; if (!algo || !algo->name) return -EINVAL; if (find_bc_algo(algo->id)) { printk(KERN_ERR "bc: algorithm %s (%d) is already registered.\n", algo->name, algo->id); return -EBUSY; } if ( !algo->encrypt || !algo->decrypt || !algo->make_key || !algo->test_key || !algo->free_key || !algo->lock_key ) { printk(KERN_ERR "bc: can't register algorithm functions.\n"); return -EINVAL; } new_algo = kmalloc(sizeof(struct bc_alg_mgr), GFP_KERNEL); if (!new_algo) return -ENOMEM; memset(new_algo, 0, sizeof(new_algo)); memset(new_algo->module_name, 0, sizeof(new_algo->module_name)); new_algo->algo = *algo; new_algo->algo_refcount = 0; new_algo->algo_flags = 0; new_algo->next = alg_head; alg_head = new_algo; return 0;}int unregister_bc_algo(ALG_ID id){ struct bc_alg_mgr *tmp, *todel; todel = find_bc_algo(id); if (!todel) { printk(KERN_ERR "bc: algorithm %d already unregistered.\n", id); return -EINVAL; } if (todel == alg_head) { alg_head = todel->next; } else { tmp = alg_head; while (tmp->next != todel) tmp = tmp->next; tmp->next = todel->next; } memset(todel, 0, sizeof(struct bc_alg_mgr)); kfree(todel); return 0;}char bc_mgr_c[]="$Id: bc_mgr.c,v 1.3 2002/10/29 07:11:46 crypt Rel-1.6-3 $";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -