Contenido principal

BLAKE Hash extension for PHP

Enero 27, 2011

"The BLAKE Hash is one of the five finalist algorithms that participates in the NIST SHA-3 competition. This hash functions is based on the HAIFA structure and the ChaCha core function.
The algorithm was designed by Jean-Philippe Aumasson, Luca Henzen, Willi Meier and Raphael C.-W. Phan, official website is http://131002.net/blake/.

There are four instances of the function, the first two, BLAKE224 and BLAKE256 work with 32-bit words and they have an output of 28 and 32 bytes respectively. The other two, BLAKE384 and BLAKE512 work with 64-bit words and they have an output of 48 and 64 bytes respectively.

The algorithm has been designed to be secure and to have a high performance (Even better than SHA-2)."

I was looking for an implementation on PHP but I found nothing, so I had to do it from scratch. My first attempt was to port the code from C to PHP using gmp library, but the script was incredibly slow, it calculates BLAKE512 in 0.07 seconds (I think the slow speed is because the gmp library creates a lot of resources), I wanted to make it faster and the best option was to make a native code in C that was able to work together with PHP.

The code is based on the final round package sent.

The extension

This PHP extension is composed by five functions: blake, blake_file, blake_init, blake_update and blake_final.

Both, blake and blake_file are used to parse strings and files, the other functions are used for incremental hashing.

The functions and its parameters are:
blake()
Description
string blake ( string $data , int $type [, string $salt [, bool $raw_output = false ]] )
Parameters
data: Message to be hashed.
type: Type of instace to use. It must be: BLAKE_224, BLAKE_256, BLAKE_384 or BLAKE_512.
salt: Salt to use. When use BLAKE_224 or BLAKE_256, salt must be 16 bytes, Otherwise, it must be 32 bytes, or a null string for use with raw_output.
raw_output: When set to true, outputs raw binary data.
Return values
Returns a string containing the calculated message digest as lowercase hexits unless raw_output is set to true in which case the raw binary representation of the message digest is returned.

blake_file()
Description
string blake_file ( string $filename , int $type [, string $salt[, bool $raw_output = false ]] )
Parameters
filename: URL describing location of file to be hashed; Supports fopen wrappers.
type: Type of instace to use. It must be: BLAKE_224, BLAKE_256, BLAKE_384 or BLAKE_512.
salt: Salt to use. When use BLAKE_224 or BLAKE_256, salt must be 16 bytes, Otherwise, it must be 32 bytes, or a null string for use with raw_output.
raw_output: When set to true, outputs raw binary data.
Return values
Returns a string containing the calculated message digest as lowercase hexits unless raw_output is set to true in which case the raw binary representation of the message digest is returned.

blake_init
Description
resource blake_init ( int $type [, string $salt ] )
Parameters
type: Type of instace to use. It must be: BLAKE_224, BLAKE_256, BLAKE_384 or BLAKE_512.
salt: Salt to use. When use BLAKE_224 or BLAKE_256, salt must be 16 bytes, Otherwise, it must be 32 bytes, or a null string for use with raw_output.
Return values
Returns a Blake state resource for use with blake_update() and blake_final().

blake_update
Description
bool blake_update ( resource $state, string $data )
Parameters
state: Blake state returned by blake_init()
data: Message to be updated in the incremental hashing.
Return values
Returns TRUE.

blake_final
Description
string blake_final ( resource $state [, bool $raw_output = false ] )
Parameters
state: Blake state returned by blake_init()
raw_output: When set to true, outputs raw binary data.
Return values
Returns a string containing the calculated message digest as lowercase hexits unless raw_output is set to true in which case the raw binary representation of the message digest is returned.

Resources

The package of BLAKE hash extension for PHP contains:
Source code of extension, Windows libraries for VC6 and VC9 (Both with thread safe and non thread safe) and Linux shared library (Compiled with archlinux i686).

Compilation

Compilation in Windows is a bit hard and requires:
:arrow: Microsoft Visual C++ (6.0 or 9)
:arrow: Windows SDK
:arrow: Some binary tools
The wiki site of PHP describes perfectly how to build PHP and PECL extensions step by step.

Compilation in Linux is easier.
Download the package and extract its contents in a folder, then:

cd src
phpize
./configure
make

(If you want to test whether the extension is working properly you should execute "make test" command after compile the extension.)

Then, with administrator privileges copy the shared library contained in modules folder to PHP extension folder.

At the end, add "extension=php_blake.dll" (Windows) or "extension=blake.so" (Linux) to your php.ini file, and that's all.

Examples

<?php
echo blake('sinfocol', BLAKE_224) . PHP_EOL;
echo blake('sinfocol', BLAKE_256) . PHP_EOL;
echo blake('sinfocol', BLAKE_384) . PHP_EOL;
echo blake('sinfocol', BLAKE_512) . PHP_EOL;

//Using incremental hashing and 0123456789abcdef as the salt
$blake = blake_init(BLAKE_256, '0123456789abcdef');
blake_update($blake, 'sinfocol');
echo blake_final($blake);

/* Expected output
1427375d4a16cc70ab4155a7c721f975f92867aa53703ccd1c8f5a4b
be2f4e21cf62f1e98ba6800a73a8b887e8c69e9fbe914d64c769299b111c8974
f41a32404f454bf925b16f7b38bfd8e1910cbd31100a4e7a4ec6cbb54115ea2c0289133953a4a28b04f6ddf14a1884cb
3ec1d1ba3dfbc3ac553f5d8ad5e6c34de7b449cc9ed04b0453f9fa859f80f47e994b6f84f859a86b66b203b0d335867b4cece8c7a0dfa5092e17b1271a5a7e70
a7cae55a3d0f5235ae2d0e2c74ce469d855d11561a5326e46e6d7c9c4d319681
*/
?>

Screenshot

BLAKE hash extension for PHP

Project can be found at https://code.google.com/p/blakehash-php/

Archivado en: Criptografía | Comentarios (9)

Padocon WriteUps 2011 (Spanish)

Enero 20, 2011

Hello everyone, les presento las resoluciones de algunos de los problemas que logramos resolver con éxito en PAraDOx COnference CTF. En total eran veinticuatro problemas de los cuales solo pudimos resolver diez y poder así entrar al top 20.

Las resoluciones acá presentadas son
Reversing, idx = 1
Reversing, idx = 2
Forensic, idx = 4
Binary, idx =5
Binary, idx = 7
Trivial, idx = 18
Trivial, idx = 19
Web, idx = 23
Wtf400, idx = 26
Wtf500, idx = 27

El archivo Padocon.7z contiene el PDF con la resolución, los enunciados y ganadores de cada prueba y alguno de los recursos utilizados para el desarrollo de los problemas.

El resultado final fue el siguiente, mucho mejor a lo esperado!

Archivado en: Criptografía, Esteganografía, Hacking, Ingeniería Inversa, Programación, Retos informáticos, Seguridad, Sistemas operativos | Comentarios (14)

Resoluciones para el WarCamp del BarCampSE

Diciembre 13, 2010

El pasado sábado cuatro de diciembre se realizó un evento llamado BarCamp en cinco ciudades de Colombia (Bogotá, Cali, Medellín, Pereira y Pasto).
El evento contenía un wargame llamado WarCamp, el cual tenía cinco niveles diseñados por Jhonatan Silva Orrego, Lechona17, Duma y con la colaboración de Migty-D y fixxxer.
El premio era patrocinado por la empresa DSTEAM.

Me enorgullece anunciar por este medio que Sinfocol ha sido el ganador de tal evento y que no hubiera podido ser sin la ayuda de todos los usuarios que constantemente me apoyan.

Un agradecimiento especial a la empresa DSTEAM quién aportó el grandioso premio con el cual puedo ampliar mis estudios. A los organizadores del evento BarCampSE, a Fernando Muñoz quien se animó a participar conjuntamente conmigo, y a Edwin y Phicar de RIC.

El premio

Un increible Acer Aspire One.


Y con un escritorio genial

Resoluciones

En el archivo WarCamp.7z pueden encontrar cuatro directorios y un archivo PDF.

Los cuatro directorios contienen los recursos necesarios para desarrollar el nivel como su respectivo script en PHP que implementa cada uno un algoritmo para su resolución.

El archivo PDF es la resolución en sí, contiene información general acerca del evento, el paso a paso de cada nivel para llegar a la respuesta, los intentos fallidos, referencias y herramientas utilizadas en la resolución de cada nivel.

Archivado en: Criptografía, Esteganografía, Hacking, Miscelaneo, Programación, Retos informáticos, Seguridad, Sistemas operativos | Comentarios (29)

BarCamp Security Edition Colombia

Noviembre 24, 2010

Este sábado cuatro de diciembre de 9:00 a.m. a 7:00 p.m. se estará realizando en cuatro ciudades de Colombia el evento BarCamp Security Edition.

BarCamp SE

"BarCamp es una red internacional de conferencias generadas por los usuarios (desconferencias). Nacen del deseo de las personas de compartir y aprender en un entorno abierto. Es un evento intenso con discusiones, demos e interacciones de los asistentes.
Cualquier persona con algo para contribuir o con el deseo de aprender está bienvenido e invitado a unirse.

Cuando llegue, esté preparado para compartir con los barcampers.
Cuando salga, esté preparado para compartirlo con el mundo."

El evento se llevará a cabo en las ciudades de Cali, Bogotá, Medellín y Pereira, tendrá un enfoque hacia la seguridad de la información y será totalmente gratuito. Algunas de las desconferencias propuestas que podemos encontrar son: Uso de GPU para descifrar contraseñas, Cazando un pedófilo a través de internet, Defensa en Profundidad con software Libre, Los problemas de usar el navegador de siempre. Conozca el último Zero Day de IE, Seguridad en Voz IP, Legislación en Colombia, Aspectos Juridicos de la Seguridad Informatica, entre otras.

Si desea conocer más acerca del BarCamp puede ingresar a la página oficial del evento.

Enlaces de interés

:arrow: Artículo en la BarCamp Wiki
:arrow: Reglas del BarCamp
:arrow: BarCamp en la Wikipedia

Archivado en: Retos informáticos, Seguridad | Comentarios (5)

Resolución reto la caja fuerte de hackplayers.blogspot.com

Noviembre 19, 2010

Casualmente dí con este interesante reto donde se reunen varios temas en general de la informática, entre ellos podemos encontrar la ingeniería inversa a animaciones flash, bruteforcing de archivos ZIP y estegranografía sobre imágenes JPEG.

Me decidí realizar un documento donde se explicara paso a paso el procedimiento que se debía seguir para encontrar la frase oculta con el fin de ir publicando algunos artículos que tengo pendientes.

PDF Resolución Reto la caja fuerte
Comprimido con los diferentes archivos del reto, Contiene:
:arrow: desconocido.mp3
:arrow: dyn003...aa7.jpg
:arrow: hpyslogin20.swf
:arrow: hpyslogin20.flr
:arrow: hpyslogin20.html
:arrow: salida.png
:arrow: solucion.jpg

Archivado en: Ingeniería Inversa, Programación, Retos informáticos | Comentarios (6)