News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Encryption procedure

Started by Farabi, August 16, 2010, 02:37:53 PM

Previous topic - Next topic

Farabi

Im planning to create an encryption procedure.
I wonder, if the file size become twice as before is it acceptable by the users?
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

oex

I think with many encryption types there is little change in file size.... If the files are very small to start with and of a fixed structure there may be little point in using encryption at all depending on the algorithm you decide upon....

If the file data is very large and has to be transfered over networks such as the internet then there may be issues however if the data rarely/never leaves the computer there shouldnt be any user complaints....
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

Farabi

Well, mine must be double the size since I guess that is the hardest method to deencrypted.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

dedndave

from what i have seen, encryption and compression seem to go hand-in-hand
you might want to combine the 2 into one program   :P
only super-secret spy type people will be happy with doubled file-sizes
....unless, you can employ some kind of error correction that makes the file self-redundant

Farabi

I've created the decryptor end the encryptor. I wonder if somebody here able to crack it. Mind to take challenge?
I wont release the source code, I will supply the .lib file.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

dedndave

i wouldn't try cracking an encryption unless i had to - lol
but - they'd want several files to work with
and, any hints would be appreciated   :bg

Farabi

Here is the exe file, if on a week no one able to crack the method, I will release the dll and I will create a folder lock.
The encrypted file is on the program directory named "Test.fef".
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

clive

Quote from: dedndave
from what i have seen, encryption and compression seem to go hand-in-hand

Indeed, you typically compress it first to remove redundancy and repetitive patterns (Like character frequency in English text), and then encrypt it.

If you try to compress it after you encrypt it then you can expect it to expand as it should look like random data.
It could be a random act of randomness. Those happen a lot as well.

Twister

Farabi,

Your program creates a 16-bit program. ::)

Antariy

Farabi, if you use not asymmetric encrypting (also known as "open key" encryption), then any algo using "secret key" encryption scheme may be cracked in short time. Especially, you let us the encryption app.

"Secret keys" ecryption might have some (small) reliability only if you compress data before encryption (as clive says already), and if nobody have your encryption program (i.e. - algorithm).

All modern encryptors, used for hard world, such as program protectors, using asymmetric encryption.



Alex

Magnum

It would also be good idea to use an exe packer with your program BEFORE you post it.

Have a great day,
                         Andy

cork

Quote from: Farabi on August 17, 2010, 03:47:05 PM
Here is the exe file, if on a week no one able to crack the method, I will release the dll and I will create a folder lock.
The encrypted file is on the program directory named "Test.fef".

My favorite kind of encryption uses a "one-time book". I provide the person, with whom I'm going carry on a series of communications, a one-time book. A one-time book is nothing but an 8 GB file containing nothing but "true random" numbers. Naturally, pseudo-random numbers will not suffice.

When you send the person a message, it is in the form of a binary file. The first 4 bytes contain an unsigned integer stating the position in the one-time book you are starting at. The remaining bytes are the message XOR'ed with the one-time book starting at the specified point.

Once you've used up the one-time book, you are done with it, it is thrown away.

donkey

That pretty much amounts to an 8 GB addendum to the file or conversation which is a huge amount of information to be transmitted over a network and a far too large amount to be transferred via the internet. Without a generated file it must be transferred in its entirety and since it is discarded after use it simply adds massive overhead to the conversation. Also since the numbers are truly random the file probably has to be generated by a human, imagine typing in 8 billion numbers. In my opinion it is not practical for an encryption method. For myself I am quite satisfied with AES, a stable and so far (?) an uncrackable nut, and by the way it is a symmetric algorithm but uses large integer factorization which is the best way to fight off brute force attacks (cracking a 256 bit key is not feasible using today's computers).
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

Magnum

This shouldn't be hard to convert to a Win32 app.



; idea3b.asm
; Last updated: Mon Sep 16 1996  See idea3c.asm for a version which
;                                doesn't show the password being typed
;
; Tiny IDEA Encryption Program
; Copyright (C) Fauzan Mirza 1995-96
;
; Version 3B (Optimised version)
;
; Optimized for smaller CODE size by Mark Andreas <voyageur@sky.net>

        .model  tiny
        .code

        org     100h

BuffLen equ     32768                   ; File buffer size
PassLen equ     128                     ; Passphrase length

Start:
        call    Burn

        mov     dx,offset Usage
        mov     si,80h
        lodsb
        or      al,al                   ; Check if parameters specified
        jz      PrintUsage

        lodsb
        lodsb                           ; Get mode switch
        cmp     al,'-'
        jz      DeMode
        cmp     al,'+'
        jz      EnMode
PrintUsage:
        jmp     Exit

DeMode:
        inc     byte ptr [Mode]
EnMode:
        lodsw

AddZero:
        lodsb
        cmp     al,20h
        ja      AddZero
        mov     byte ptr [si-1],cl      ; null-terminate string

        mov     dx,offset Enterkey
        mov     ah,9
        int     21h                     ; Print message requesting key

        mov     dx,offset Password
        mov     ah,0ah
        int     21h                     ; Get passphrase from user

        mov     cx,PassLen/8            ; Hash passphrase down to 128 bits
        mov     si,offset Passphrase

h       equ     Key
g       equ     Key+8

TandemDM:
        push    cx              ; push block counter    <0
        push    si              ; push data             <1

        mov     cl,4
        mov     si,offset g     ; -- Let first half of key = second half of hash (G)
        mov     di,offset hashKey
        rep     movsw           ; after: di->key+8

        pop     si              ; si->data              1>
        push    si              ; push data             <1
        call    Convert         ; -- Let second half of key = data

        mov     si,offset hashKey
        push    si              ; push key              <2
        mov     di,si
        call    Expandkey       ; -- Expand key : Key = {G, data}

        mov     cl,4
        mov     si,offset h
        mov     di,offset w_val
        push    di              ; push w                <3
        rep     movsw           ; -- Let W = first half of hash (H)

        pop     di              ; di->w                 3>
        pop     si              ; si->key               2>
        push    si              ; push key              <2

        call    IDEA            ; -- W = IDEA encrypt (W, {G,data})

        mov     si,di           ; si->w
        mov     di,offset h
        call    doGHsub         ; -- Update H with (H xor W)

        pop     di              ; di->key               2>
        pop     si              ; si->data              1>
        push    si              ; push data             <1
        push    di              ; push key              <2
        call    Convert         ; -- Let first half of key = data

        mov     cl,4
        mov     si,offset w_val ; di->key+8
        rep     movsw           ; -- Let second half of key = W

        pop     si              ; si->key               2>
        mov     di,si
        call    Expandkey       ; -- Expand key : Key = {data, W}

        mov     cl,4
        mov     si,offset g
        mov     di,offset g0
        push    si              ; push g                <2
        push    di              ; push g0               <3
        rep     movsw           ; -- Let G0 = G

        pop     di              ; di->g0                3>
        push    di              ; push g0               <3
        mov     si,offset hashKey
        call    IDEA            ; -- G0 = IDEA encrypt (G0, {data, W})

        pop     si              ; si->g0                3>
        pop     di              ; di->g                 2>

        call    doGHsub         ; -- Update G with (G xor G0)

        pop     si              ; si->data              1>
        add     si,8            ; data+=8
        pop     cx              ; cx=block counter      0>
        loop    TandemDM        ; -- Continue hashing until no more blocks

        mov     di,offset Key   ; Expand hashed passphrase to IDEA key
        call    Expandkey

        mov     dx,0084h
        mov     ax,3d02h
        int     21h                     ; Open file with R/W access
        jc      Errstop
        xchg    bx,ax

Again:
        mov     cx,BuffLen
        mov     dx,offset Buffer
        mov     ah,3fh
        int     21h                     ; Read upto 32k into buffer
Errstop:
        jc      Error

        or      ax,ax                   ; Check if we reached EOF
        jz      Done

        push    dx                      ; offset Buffer
        push    ax                      ; bytes read
        push    bx                      ; file handle

; Encrypt Buffer

        mov     di,dx                   ; DI -> data (start)

        add     ax,7
        mov     cl,3
        shr     ax,cl
        xchg    cx,ax                   ; CX = number of blocks to encrypt
Block:
        mov     si,offset Key
        push    cx
        push    di                      ; Save current position

        mov     di,offset CFBBuffer     ; Encrypt 8 byte CFB buffer (DI)
        call    IDEA
        mov     cx,4                    ; Process 4 words
        pop     si                      ; SI -> data, DI -> CFB buffer

        cmp     byte ptr [Mode],0       ; Check mode switch
        jnz     Decrypt

; Cipher Feedback

Encrypt:
        lodsw                           ; Get a word from file buffer
        xchg    ah,al                   ;   and convert it to little-endian
        xor     ax,word ptr [di]        ; XOR data with CFB buffer
        stosw                           ; Replace ciphertext in CFB buffer
        xchg    ah,al                   ; Convert back to big-endian
        mov     word ptr [si-2],ax      ;   and store in file buffer
        loop    Encrypt

        jmp     short DoNextBlock       ; Skip over Decrypt routine

Decrypt:
        mov     bx,word ptr [di]        ; Get word from CFB buffer
        lodsw                           ; Get word from file buffer
        xchg    ah,al                   ;   convert it to little-endian
        stosw                           ; Update CFB buffer
        xor     bx,ax                   ; XOR data with CFB buffer
        xchg    bh,bl                   ; Convert back to big-endian
        mov     word ptr [si-2],bx      ;   and store in file buffer
        loop    Decrypt

DoNextBlock:
        mov     di,si                   ; Update block counter
        pop     cx
        loop    Block                   ; Continue until all blocks processed

; Buffer Encrypted

        pop     bx                      ; file handle

        pop     dx
        push    dx                      ; bytes read

        neg     dx
        dec     cx                      ; CX = FFFF
        mov     ax,4201h
        int     21h                     ; Seek backwards

        pop     cx                      ; bytes read
        pop     dx                      ; offset Buffer
        mov     ah,40h
        int     21h                     ; Write encrypted buffer
        jnc     Again                   ; Continue until no more data

Error:
        mov     dx,offset Message
Exit:
        mov     ah,09
        int     21h                     ; Display message

Done:
        call    Burn                    ; Burn evidence
        int     20h                     ; Exit

Burn:
        xor     ax,ax
        mov     di,offset Passphrase-1
        mov     cx,Buffer-Passphrase+BuffLen+1
        rep     stosb                   ; Overwrite data area
        ret

; Convert string to little-endian words
; (called by Tandem DM hashing routine)

Convert:
        mov     cl,4
CopyLoop:
        lodsw
        xchg    ah,al
        stosw
        loop    CopyLoop
        ret

; XOR update 64-bit buffer
; (called by Tandem DM hashing routine)

doGHsub:
        mov     cx,4
doGHloop:
        lodsw
        xor     ax,[di]
        stosw
        loop    doGHloop
        ret

; Expand user key to IDEA encryption key
; Entry:  si -> userkey, di -> buffer for IDEA key (can equal si)
; Exit:   di -> IDEA key

Expandkey:
        add     di,16
        mov     bl,8
Rotate:
        mov     ax,bx                   ; Determine which two of the previous
        and     al,7                    ;  eight words are needed for this
        cmp     al,6                    ;  key expansion round

        mov     ax,word ptr [di-14]
        mov     dx,word ptr [di-12]
        jb      Update
        mov     dx,word ptr [di-28]
        jz      Update
        mov     ax,word ptr [di-30]
Update:
        mov     cl,9
        shl     ax,cl
        mov     cl,7
        shr     dx,cl                   ; Calculate the rotated value
        or      ax,dx
        stosw                           ;   and save it
        inc     bx
        cmp     bl,52
        jnz     Rotate                  ; Continue until 52 words updated
        ret

; IDEA subroutine
; Entry:  si -> key, di -> input data
; Exit:   di -> output data, all other registers trashed

; Refer to the PGP IDEA source for a better explanation
; of the algorithm and the optimisations

; Thanks to Bill Couture <bcouture@cris.com> for speed optimisations

x0      equ     bx
x1      equ     cx
x2      equ     bp
x3      equ     di

IDEA:
        mov     byte ptr [Rounds],8     ; Eight rounds
        push    di
        mov     dx,word ptr [di]
        mov     x1,word ptr [di+2]
        mov     x2,word ptr [di+4]
        mov     x3,word ptr [di+6]      ; note that DI is over-written last
Round:
        call    MulMod
        xchg    x0,ax                   ; x0 *= *key++

        lodsw
        add     x1,ax                   ; x1 += *key++
        lodsw
        add     x2,ax                   ; x2 += *key++
        mov     dx,x3
        call    MulMod
        xchg    x3,ax                   ; x3 *= *key++

        push    x1                      ; s0 = x1
        push    x2                      ; s1 = x2
        xor     x2,x0                   ; x2 ^= x0
        xor     x1,x3                   ; x1 ^= x3

        mov     dx,x2
        call    MulMod
        add     x1,ax                   ; x2 *= *key++
        xchg    x2,ax                   ; x1 += x2
        mov     dx,x1
        call    MulMod
        add     x2,ax                   ; x1 *= *key++
        xchg    x1,ax                   ; x2 += x1

        xor     x0,x1                   ; x0 ^= x1
        xor     x3,x2                   ; x3 ^= x2
        pop     dx
        pop     ax
        xor     x1,dx                   ; x1 ^= s1
        xor     x2,ax                   ; x2 ^= s0

        mov     dx,x0
        dec     byte ptr [Rounds]       ; Continue until no more rounds
        jnz     Round

        call    MulMod
        xchg    x0,ax                   ; x0 *= *key++
        lodsw
        add     x2,ax                   ; x2 += *key++
        lodsw
        add     x1,ax                   ; x1 += *key++
        mov     dx,x3
        call    MulMod                  ; x3 *= *key++

        pop     di
        push    di

        xchg    x0,ax
        stosw
        xchg    x2,ax                   ; unswap x1, x2
        stosw
        xchg    x1,ax
        stosw
        xchg    x0,ax
        stosw

        pop     di
        ret

; Multiplication modulo 65537
; ax = [si] * dx

MulMod:
        push    dx
        lodsw
        mul     dx
        sub     ax,dx
        pop     dx
        jnz     NotZero
        inc     ax
        sub     ax,word ptr [si-2]
        sub     ax,dx
        ret
NotZero:
        adc     ax,0
        ret

; Data used by main program

Usage:
        db      "IDEA +/- <File>",36

EnterKey:
        db      "Enter key: ",36

Message:
        db      "File Error",36

Password:
        db      PassLen,?

Passphrase:
        db      PassLen dup (?)

Mode:
        db      ?

; Data used by IDEA routine

Rounds:
        db      ?

        db      ?                       ; Comment out if assembly inserts NOP
        even

; Data used by Tandem DM hashing routine

Key:
        dw      8 dup (?)
w_val:
        dw      4 dup (?)
g0:
        dw      4 dup (?)
hashKey:
        dw      52 dup (?)

; Data used by CFB routine

CFBBuffer:
        db      8 dup (?)

; Data buffer

Buffer:
        db      BuffLen dup (?)

        end     Start

Have a great day,
                         Andy

Ghandi

Quote
All modern encryptors, used for hard world, such as program protectors, using asymmetric encryption.

Don't forget that a lot of them use symmetric key encryption but secure the keys with asymetric key encryption & signing. Symmetric key encryption means smaller keys with the same level of security and then the asymetric key encryption & signing offer the symmetric key some security.

HR,
Ghandi