static void F_func(uint8_t *out, const uint8_t *in, const uint8_t *c, const struct kuzn_ctx *ctx) { uint8_t tmp[16]; LSX(tmp, in, c, ctx); X_func(tmp, tmp, in + 0x10); memcpy(out + 0x10, in, 0x10); memcpy(out, tmp, 0x10); }
void kuzn_encrypt(struct kuzn_ctx *ctx, const uint8_t *in, uint8_t *out) { uint8_t tmp[16]; assert(ctx != NULL && in != NULL && out != NULL); LSX(tmp, in, ctx->keys, ctx); //K1 LSX(tmp, tmp, ctx->keys + 16, ctx); //K2 LSX(tmp, tmp, ctx->keys + 16 * 2, ctx); //K3 LSX(tmp, tmp, ctx->keys + 16 * 3, ctx); //K4 LSX(tmp, tmp, ctx->keys + 16 * 4, ctx); //K5 LSX(tmp, tmp, ctx->keys + 16 * 5, ctx); //K6 LSX(tmp, tmp, ctx->keys + 16 * 6, ctx); //K7 LSX(tmp, tmp, ctx->keys + 16 * 7, ctx); //K8 LSX(tmp, tmp, ctx->keys + 16 * 8, ctx); //K9 X_func(out, tmp, ctx->keys + 16 * 9); //K10 }
// Encryption using Kuznechik algorithm void kuz_encrypt(unsigned char text[16], unsigned char keys[10][16]) { int i = 0; for(i = 0; i < 9; ++i) { LSX(keys[i], text); } _asm { mov esi, text; mov edi, keys; lea edi, [edi + 16*9]; movdqu xmm0, [esi]; movdqu xmm1, [edi]; pxor xmm0, xmm1; movdqu [esi], xmm0; } return; }