|
x_ser
|
 |
« : 11 Апрель 2009, 11:23:40 » |
|
#include <linux/init.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <errno.h> #include <stdio.h> #include <string.h>
#typedef unsigned int u32; #typedef unsigned char u8;
struct gost_ctx { u32 k[8]; char k87[256],k65[256],k43[256],k21[256]; }; static unsigned char const k8[16] = { 0x1, 0xF, 0xD, 0x0, 0x5, 0x7, 0xA, 0x4, 0x9, 0x2, 0x3, 0xE, 0x6, 0xB, 0x8, 0xC }; static unsigned char const k7[16] = { 0xD, 0xB, 0x4, 0x1, 0x3, 0xF, 0x5, 0x9, 0x0, 0xA, 0xE, 0x7, 0x6, 0x8, 0x2, 0xC }; static unsigned char const k6[16] = { 0x4, 0xB, 0xA, 0x0, 0x7, 0x2, 0x1, 0xD, 0x3, 0x6, 0x8, 0x5, 0x9, 0xC, 0xF, 0xE }; static unsigned char const k5[16] = { 0x6, 0xC, 0x7, 0x1, 0x5, 0xF, 0xD, 0x8, 0x4, 0xA, 0x9, 0xE, 0x0, 0x3, 0xB, 0x2 }; static unsigned char const k4[16] = { 0x7, 0xD, 0xA, 0x1, 0x0, 0x8, 0x9, 0xF, 0xE, 0x4, 0x6, 0xC, 0xB, 0x2, 0x5, 0x3 }; static unsigned char const k3[16] = { 0x5, 0x8, 0x1, 0xD, 0xA, 0x3, 0x4, 0x2, 0xE, 0xF, 0xC, 0x7, 0x6, 0x0, 0x9, 0xB }; static unsigned char const k2[16] = { 0xE, 0xB, 0x4, 0xC, 0x6, 0xD, 0xF, 0xA, 0x2, 0x3, 0x8, 0x1, 0x0, 0x7, 0x5, 0x9 }; static unsigned char const k1[16] = { 0x4, 0xA, 0x9, 0x2, 0xD, 0x8, 0x0, 0xE, 0x6, 0xB, 0x1, 0xC, 0x7, 0xF, 0x5, 0x3 };
static int gost_setkey(struct gost_ctx *ctx, const u8 *key, unsigned int keylen){ unsigned int *K = ctx->k; short i, j; unsigned int temp;
for (i = 0; i < 256; i++) { ctx->k87 = k8[i >> 4] << 4 | k7[i & 15]; ctx->k65 = k6[i >> 4] << 4 | k5[i & 15]; ctx->k43 = k4[i >> 4] << 4 | k3[i & 15]; ctx->k21 = k2[i >> 4] << 4 | k1[i & 15]; } for (j = 0, i = 0; i < 8; i++) { temp = (((u32 )key[j] << 24) | ((u32 )key[(j + 1) % keylen] << 16) |((u32 )key[(j + 2) % keylen] << 8) |((u32 )key[(j + 3) % keylen])); K = temp; j = (j + 4) % keylen; } return 0; }
int main(void) {
struct gost_ctx *ctx; // здесь key1 - буфер gost_setkey(ctx,key1,keylength);
return 0; } ------------------------------- gcc gost.c ./a.out ------------------------------- дает ошибка Seqmentation fault Помогите люди !!!
|