Skip to main content
Removed the **edit**, since that link to GitHub results in a “404 Not Found”.
Source Link
e-sushi
  • 18.1k
  • 12
  • 85
  • 235

I have constructed a stream cipher from a secure hash algorithm and a HMAC. Here is a brief description of the algorithm:

Let: (Actually Objective-C styled pseudo code)

  • [data SHA512Hash]: SHA-512 hash of data,
  • [data SHA512HMAC:key]: SHA-512 HMAC of data with key,
  • [data xor:another]: bitwise XOR of two data and another which have the same length,
  • [data bytesTo:index]: first index bytes of data,
  • [data removeFirstBytes:count]: remove first count bytes from data,
  • [data length]: length of data.
  • [data concat:other]: Concatenate other after data.
  • [Data new]: allocate an empty buffer.

Pseudocode: (Or actual Objective-C code?)

Data hkey = [key SHA512]; // Hash to make lengths match.
Data segKey = [IV SHA512];

Data dest = [Data new]; // This will be the output
Data last = (Some constant)

do {
    // Cut off hash-sized chunks of source data
    Data segment = [data bytesTo:[hkey length]];
    [data removeFirstBytes:[hkey length]];

    // Derive a new segment key
    segKey = [segKey SHA512HMAC:hkey]; // or [segKey SHA512HMAC:[hkey concat:last]]? If so, how to decrypt?

    // XOR
    last = [segment xor:[segKey bytesTo:[segment length]]] // Truncates to make length match
    dest = [dest concat:last];
} while ([data length] > 0)

From some other questions I am suggested that this is SHA-512 HMAC running in OFB mode but what about the change in the code comment?

This code seem to decipher itself when given the same key.

EDIT Here is this cipher implemented in Objective-C: https://github.com/xcvista/CGIKit/blob/master/MSBooster/MSBooster/NSData%2BMSTrivialCryptography.m (Free software, 2-clause BSD license.)

I have constructed a stream cipher from a secure hash algorithm and a HMAC. Here is a brief description of the algorithm:

Let: (Actually Objective-C styled pseudo code)

  • [data SHA512Hash]: SHA-512 hash of data,
  • [data SHA512HMAC:key]: SHA-512 HMAC of data with key,
  • [data xor:another]: bitwise XOR of two data and another which have the same length,
  • [data bytesTo:index]: first index bytes of data,
  • [data removeFirstBytes:count]: remove first count bytes from data,
  • [data length]: length of data.
  • [data concat:other]: Concatenate other after data.
  • [Data new]: allocate an empty buffer.

Pseudocode: (Or actual Objective-C code?)

Data hkey = [key SHA512]; // Hash to make lengths match.
Data segKey = [IV SHA512];

Data dest = [Data new]; // This will be the output
Data last = (Some constant)

do {
    // Cut off hash-sized chunks of source data
    Data segment = [data bytesTo:[hkey length]];
    [data removeFirstBytes:[hkey length]];

    // Derive a new segment key
    segKey = [segKey SHA512HMAC:hkey]; // or [segKey SHA512HMAC:[hkey concat:last]]? If so, how to decrypt?

    // XOR
    last = [segment xor:[segKey bytesTo:[segment length]]] // Truncates to make length match
    dest = [dest concat:last];
} while ([data length] > 0)

From some other questions I am suggested that this is SHA-512 HMAC running in OFB mode but what about the change in the code comment?

This code seem to decipher itself when given the same key.

EDIT Here is this cipher implemented in Objective-C: https://github.com/xcvista/CGIKit/blob/master/MSBooster/MSBooster/NSData%2BMSTrivialCryptography.m (Free software, 2-clause BSD license.)

I have constructed a stream cipher from a secure hash algorithm and a HMAC. Here is a brief description of the algorithm:

Let: (Actually Objective-C styled pseudo code)

  • [data SHA512Hash]: SHA-512 hash of data,
  • [data SHA512HMAC:key]: SHA-512 HMAC of data with key,
  • [data xor:another]: bitwise XOR of two data and another which have the same length,
  • [data bytesTo:index]: first index bytes of data,
  • [data removeFirstBytes:count]: remove first count bytes from data,
  • [data length]: length of data.
  • [data concat:other]: Concatenate other after data.
  • [Data new]: allocate an empty buffer.

Pseudocode: (Or actual Objective-C code?)

Data hkey = [key SHA512]; // Hash to make lengths match.
Data segKey = [IV SHA512];

Data dest = [Data new]; // This will be the output
Data last = (Some constant)

do {
    // Cut off hash-sized chunks of source data
    Data segment = [data bytesTo:[hkey length]];
    [data removeFirstBytes:[hkey length]];

    // Derive a new segment key
    segKey = [segKey SHA512HMAC:hkey]; // or [segKey SHA512HMAC:[hkey concat:last]]? If so, how to decrypt?

    // XOR
    last = [segment xor:[segKey bytesTo:[segment length]]] // Truncates to make length match
    dest = [dest concat:last];
} while ([data length] > 0)

From some other questions I am suggested that this is SHA-512 HMAC running in OFB mode but what about the change in the code comment?

This code seem to decipher itself when given the same key.

Tweeted twitter.com/#!/StackCrypto/status/381618164104437760
added 200 characters in body
Source Link

I have constructed a stream cipher from a secure hash algorithm and a HMAC. Here is a brief description of the algorithm:

Let: (Actually Objective-C styled pseudo code)

  • [data SHA512Hash]: SHA-512 hash of data,
  • [data SHA512HMAC:key]: SHA-512 HMAC of data with key,
  • [data xor:another]: bitwise XOR of two data and another which have the same length,
  • [data bytesTo:index]: first index bytes of data,
  • [data removeFirstBytes:count]: remove first count bytes from data,
  • [data length]: length of data.
  • [data concat:other]: Concatenate other after data.
  • [Data new]: allocate an empty buffer.

Pseudocode: (Or actual Objective-C code?)

Data hkey = [key SHA512]; // Hash to make lengths match.
Data segKey = [IV SHA512];

Data dest = [Data new]; // This will be the output
Data last = (Some constant)

do {
    // Cut off hash-sized chunks of source data
    Data segment = [data bytesTo:[hkey length]];
    [data removeFirstBytes:[hkey length]];

    // Derive a new segment key
    segKey = [segKey SHA512HMAC:hkey]; // or [segKey SHA512HMAC:[hkey concat:last]]? If so, how to decrypt?

    // XOR
    last = [segment xor:[segKey bytesTo:[segment length]]] // Truncates to make length match
    dest = [dest concat:last];
} while ([data length] > 0)

From some other questions I am suggested that this is SHA-512 HMAC running in OFB mode but what about the change in the code comment?

This code seem to decipher itself when given the same key.

EDIT Here is this cipher implemented in Objective-C: https://github.com/xcvista/CGIKit/blob/master/MSBooster/MSBooster/NSData%2BMSTrivialCryptography.m (Free software, 2-clause BSD license.)

I have constructed a stream cipher from a secure hash algorithm and a HMAC. Here is a brief description of the algorithm:

Let: (Actually Objective-C styled pseudo code)

  • [data SHA512Hash]: SHA-512 hash of data,
  • [data SHA512HMAC:key]: SHA-512 HMAC of data with key,
  • [data xor:another]: bitwise XOR of two data and another which have the same length,
  • [data bytesTo:index]: first index bytes of data,
  • [data removeFirstBytes:count]: remove first count bytes from data,
  • [data length]: length of data.
  • [data concat:other]: Concatenate other after data.
  • [Data new]: allocate an empty buffer.

Pseudocode: (Or actual Objective-C code?)

Data hkey = [key SHA512]; // Hash to make lengths match.
Data segKey = [IV SHA512];

Data dest = [Data new]; // This will be the output
Data last = (Some constant)

do {
    // Cut off hash-sized chunks of source data
    Data segment = [data bytesTo:[hkey length]];
    [data removeFirstBytes:[hkey length]];

    // Derive a new segment key
    segKey = [segKey SHA512HMAC:hkey]; // or [segKey SHA512HMAC:[hkey concat:last]]? If so, how to decrypt?

    // XOR
    last = [segment xor:[segKey bytesTo:[segment length]]] // Truncates to make length match
    dest = [dest concat:last];
} while ([data length] > 0)

From some other questions I am suggested that this is SHA-512 HMAC running in OFB mode but what about the change in the code comment?

This code seem to decipher itself when given the same key.

I have constructed a stream cipher from a secure hash algorithm and a HMAC. Here is a brief description of the algorithm:

Let: (Actually Objective-C styled pseudo code)

  • [data SHA512Hash]: SHA-512 hash of data,
  • [data SHA512HMAC:key]: SHA-512 HMAC of data with key,
  • [data xor:another]: bitwise XOR of two data and another which have the same length,
  • [data bytesTo:index]: first index bytes of data,
  • [data removeFirstBytes:count]: remove first count bytes from data,
  • [data length]: length of data.
  • [data concat:other]: Concatenate other after data.
  • [Data new]: allocate an empty buffer.

Pseudocode: (Or actual Objective-C code?)

Data hkey = [key SHA512]; // Hash to make lengths match.
Data segKey = [IV SHA512];

Data dest = [Data new]; // This will be the output
Data last = (Some constant)

do {
    // Cut off hash-sized chunks of source data
    Data segment = [data bytesTo:[hkey length]];
    [data removeFirstBytes:[hkey length]];

    // Derive a new segment key
    segKey = [segKey SHA512HMAC:hkey]; // or [segKey SHA512HMAC:[hkey concat:last]]? If so, how to decrypt?

    // XOR
    last = [segment xor:[segKey bytesTo:[segment length]]] // Truncates to make length match
    dest = [dest concat:last];
} while ([data length] > 0)

From some other questions I am suggested that this is SHA-512 HMAC running in OFB mode but what about the change in the code comment?

This code seem to decipher itself when given the same key.

EDIT Here is this cipher implemented in Objective-C: https://github.com/xcvista/CGIKit/blob/master/MSBooster/MSBooster/NSData%2BMSTrivialCryptography.m (Free software, 2-clause BSD license.)

Renamed vars
Source Link

I have constructed a stream cipher from a secure hash algorithm and a HMAC. Here is a brief description of the algorithm:

Let: (Actually Objective-C styled pseudo code)

  • [data SHA512Hash]: SHA-512 hash of data,
  • [data SHA512HMAC:key]: SHA-512 HMAC of data with key,
  • [data xor:another]: bitwise XOR of two data and another which have the same length,
  • [data bytesTo:index]: first index bytes of data,
  • [data removeFirstBytes:count]: remove first count bytes from data,
  • [data length]: length of data.
  • [data concat:other]: Concatenate other after data.
  • [Data new]: allocate an empty buffer.

Pseudocode: (Or actual Objective-C code?)

Data IVhkey = [key SHA512]; // Should I derive this?Hash Ifto not,make thenlengths how?match.
Data segKey = IV;[IV SHA512];

Data dest = [Data new]; // This will be the output
Data last = (Some constant)

do {
    // Cut off hash-sized chunks of source data
    Data segment = [data bytesTo:[IV[hkey length]];
    [data removeFirstBytes:[IV[hkey length]];

    // Derive a new segment key
    segKey = [segKey SHA512HMAC:IV];hkey]; // or [segKey SHA512HMAC:[IV[hkey concat:last]]? If so, how to decrypt?

    // XOR
    last = [segment xor:segKey][segKey bytesTo:[segment length]]] // Truncates to make length match
    dest = [dest concat:last];
} while ([data length] > 0)

From some other questions I am suggested that this is SHA-512 HMAC running in OFB mode but what about the change in the code comment?

This code seem to decipher itself when given the same key.

I have constructed a stream cipher from a secure hash algorithm and a HMAC. Here is a brief description of the algorithm:

Let: (Actually Objective-C styled pseudo code)

  • [data SHA512Hash]: SHA-512 hash of data,
  • [data SHA512HMAC:key]: SHA-512 HMAC of data with key,
  • [data xor:another]: bitwise XOR of two data and another which have the same length,
  • [data bytesTo:index]: first index bytes of data,
  • [data removeFirstBytes:count]: remove first count bytes from data,
  • [data length]: length of data.
  • [data concat:other]: Concatenate other after data.
  • [Data new]: allocate an empty buffer.

Pseudocode: (Or actual Objective-C code?)

Data IV = [key SHA512]; // Should I derive this? If not, then how?
Data segKey = IV;

Data dest = [Data new]; // This will be the output
Data last = (Some constant)

do {
    // Cut off hash-sized chunks of source data
    Data segment = [data bytesTo:[IV length]];
    [data removeFirstBytes:[IV length]];

    // Derive a new segment key
    segKey = [segKey SHA512HMAC:IV]; // or [segKey SHA512HMAC:[IV concat:last]]? If so, how to decrypt?

    // XOR
    last = [segment xor:segKey]
    dest = [dest concat:last];
} while ([data length] > 0)

From some other questions I am suggested that this is SHA-512 HMAC running in OFB mode but what about the change in the code comment?

This code seem to decipher itself when given the same key.

I have constructed a stream cipher from a secure hash algorithm and a HMAC. Here is a brief description of the algorithm:

Let: (Actually Objective-C styled pseudo code)

  • [data SHA512Hash]: SHA-512 hash of data,
  • [data SHA512HMAC:key]: SHA-512 HMAC of data with key,
  • [data xor:another]: bitwise XOR of two data and another which have the same length,
  • [data bytesTo:index]: first index bytes of data,
  • [data removeFirstBytes:count]: remove first count bytes from data,
  • [data length]: length of data.
  • [data concat:other]: Concatenate other after data.
  • [Data new]: allocate an empty buffer.

Pseudocode: (Or actual Objective-C code?)

Data hkey = [key SHA512]; // Hash to make lengths match.
Data segKey = [IV SHA512];

Data dest = [Data new]; // This will be the output
Data last = (Some constant)

do {
    // Cut off hash-sized chunks of source data
    Data segment = [data bytesTo:[hkey length]];
    [data removeFirstBytes:[hkey length]];

    // Derive a new segment key
    segKey = [segKey SHA512HMAC:hkey]; // or [segKey SHA512HMAC:[hkey concat:last]]? If so, how to decrypt?

    // XOR
    last = [segment xor:[segKey bytesTo:[segment length]]] // Truncates to make length match
    dest = [dest concat:last];
} while ([data length] > 0)

From some other questions I am suggested that this is SHA-512 HMAC running in OFB mode but what about the change in the code comment?

This code seem to decipher itself when given the same key.

added 203 characters in body
Source Link
Loading
added 105 characters in body
Source Link
Loading
Source Link
Loading