File: sdext_crypto.c

package info (click to toggle)
reiser4progs 1.0.6-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 5,348 kB
  • ctags: 3,714
  • sloc: ansic: 33,468; sh: 8,489; makefile: 1,012
file content (97 lines) | stat: -rw-r--r-- 2,329 bytes parent folder | download | duplicates (4)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* Copyright (C) 2001-2005 by Hans Reiser, licensing governed by
   reiser4progs/COPYING.
   
   sdext_crypto.c -- crypto stat data extension plugin. */

#ifndef ENABLE_MINIMAL

#include "sdext_crypto.h"

reiser4_core_t *sdext_crypto_core = NULL;

extern reiser4_sdext_plug_t sdext_crypto_plug;

uint32_t sdext_crypto_length(stat_entity_t *stat, void *hint) {
	sdext_crypto_t e;
	uint16_t count;
	
	aal_assert("vpf-1842", stat != NULL || hint != NULL);
	
	if (hint) {
		count = ((sdhint_crypto_t *)hint)->signlen;
	} else {
		if (stat->info.digest == INVAL_PTR) {
			aal_error("Digest must be specified for \'%s\'.",
				  sdext_crypto_plug.p.label);
			return 0;
		}
		
		count = reiser4_keysign_size(stat->info.digest);
	}
	
	return sizeof(e.keylen) + count;
}

static errno_t sdext_crypto_open(stat_entity_t *stat, void *hint) {
	sdhint_crypto_t *crch;
	sdext_crypto_t *ext;
	
	aal_assert("vpf-1837", stat != NULL);
	aal_assert("vpf-1838", hint != NULL);
	
	if (stat->info.digest == INVAL_PTR) {
		aal_error("Digest must be specified for \'%s\'.",
			  sdext_crypto_plug.p.label);
		
		return -EIO;
	}
	
	crch = (sdhint_crypto_t *)hint;
	ext = (sdext_crypto_t *)stat_body(stat);
	crch->keylen = sdext_crypto_get_keylen(ext);
	crch->signlen = reiser4_keysign_size(stat->info.digest);
	aal_memcpy(crch->sign, ext->sign, crch->signlen);
	
	return 0;
}

static errno_t sdext_crypto_init(stat_entity_t *stat, void *hint) {
	sdhint_crypto_t *crch;
	sdext_crypto_t *ext;
	
	aal_assert("vpf-1839", stat != NULL);
	aal_assert("vpf-1840", hint != NULL);

	ext = (sdext_crypto_t *)stat_body(stat);
	crch = (sdhint_crypto_t *)hint;

	sdext_crypto_set_keylen(ext, crch->keylen);
	aal_memcpy(ext->sign, crch->sign, crch->signlen);
	
	return 0;
}

extern errno_t sdext_crypto_check_struct(stat_entity_t *stat, 
					 repair_hint_t *hint);

extern void sdext_crypto_print(stat_entity_t *stat, 
			       aal_stream_t *stream, 
			       uint16_t options);

reiser4_sdext_plug_t sdext_crypto_plug = {
	.p = {
		.id    = {SDEXT_CRYPTO_ID, 0, SDEXT_PLUG_TYPE},
		.label = "sdext_crypto",
		.desc  = "Crypto stat data extension plugin.",
	},

	.open	   	= sdext_crypto_open,
	.init	   	= sdext_crypto_init,
	.info		= NULL,
	.print     	= sdext_crypto_print,
	.check_struct	= NULL,
	.open	   	= NULL,
	.length	   	= sdext_crypto_length

};
#endif