<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>It should work... &#187; C++</title>
	<atom:link href="http://vierito.es/wordpress/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://vierito.es/wordpress</link>
	<description>Cuando cualquier trasto es útil</description>
	<lastBuildDate>Sat, 09 Jul 2011 02:34:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Crackeador de hashes MD5 en C y OpenSSL</title>
		<link>http://vierito.es/wordpress/2009/08/28/crackeador-de-hashes-md5-en-c-y-openssl/</link>
		<comments>http://vierito.es/wordpress/2009/08/28/crackeador-de-hashes-md5-en-c-y-openssl/#comments</comments>
		<pubDate>Fri, 28 Aug 2009 11:43:03 +0000</pubDate>
		<dc:creator>vierito5</dc:creator>
				<category><![CDATA[hacking]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[crackeador]]></category>
		<category><![CDATA[cracker]]></category>
		<category><![CDATA[cracking]]></category>
		<category><![CDATA[criptografía]]></category>
		<category><![CDATA[diccionario]]></category>
		<category><![CDATA[EVP_DigestInit]]></category>
		<category><![CDATA[hash]]></category>
		<category><![CDATA[MD5]]></category>
		<category><![CDATA[OpenSSL]]></category>
		<category><![CDATA[password cracking]]></category>

		<guid isPermaLink="false">http://vierito.es/wordpress/?p=642</guid>
		<description><![CDATA[Un hash es una función criptográfica de tipo resumen cuyo objetivo es identificar casi unívocamente un conjunto de datos. Pretende ser una función inyectiva, es decir, que para una salida (valor imagen) solo exista una entrada (valor origen) pero debido a que su salida está limitada en tamaño es posible que para entradas diferentes existan [...]]]></description>
			<content:encoded><![CDATA[<p>Un hash es una función criptográfica de tipo resumen cuyo objetivo es identificar <em>casi unívocamente</em> un conjunto de datos. Pretende ser una función inyectiva, es decir, que para una salida (valor imagen) solo exista una entrada (valor origen) pero debido a que su salida está limitada en tamaño es posible que para entradas diferentes existan claves resultantes iguales. Eso sería una colisión y una función hash deberá tener una salida pequeña equilibrada con su resistencia a colisiones. MD5 tiene una salida fija de 128 bits, lo que vienen siendo 32 dígitos en hexadecimal.</p>
<p>Primero de todo vamos a hacer un programa que nos permita calcular el hash md5 de un string que se le pase y luego ya pasaremos al crackeador.</p>
<p>Sería más fácil hacer un script en bash o perl gracias a la utilidad CLI de OpenSSL, a la hora de calcular un solo hash no importa mucho la velocidad pero si luego queremos hacer un pequeño crackeador no podemos partir de algo que ya sabemos que va a ser mucho más lento. Así que lo que vamos a usar es C y la librería de OpenSSL.</p>
<p>Si no sabemos por donde empezar un extracto del man:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">$ man md5
...
<span style="color: #202020;">SYNOPSIS</span>
&nbsp;
<span style="color: #339933;">#include &lt;openssl/md2.h&gt;</span>
&nbsp;
        <span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>MD5<span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>d<span style="color: #339933;">,</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> n<span style="color: #339933;">,</span>
                         <span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>md<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #993333;">int</span> MD5_Init<span style="color: #009900;">&#40;</span>MD5_CTX <span style="color: #339933;">*</span>c<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #993333;">int</span> MD5_Update<span style="color: #009900;">&#40;</span>MD5_CTX <span style="color: #339933;">*</span>c<span style="color: #339933;">,</span> <span style="color: #993333;">const</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*</span>data<span style="color: #339933;">,</span>
                         <span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> len<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #993333;">int</span> MD5_Final<span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>md<span style="color: #339933;">,</span> MD5_CTX <span style="color: #339933;">*</span>c<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
...
<span style="color: #202020;">DESCRIPTION</span>
...
<span style="color: #202020;">Applications</span> should use the higher level functions EVP_DigestInit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span> etc. <span style="color: #202020;">instead</span> of calling the hash functions directly.
...</pre></div></div>

<p><span id="more-642"></span><br />
Vemos que podríamos añadir esa librería y usar las funciones MD5_Init(), MD5_Update y MD5_Final pero ya nos avisan que deberíamos usar unas funciones de más alto nivel así que: <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5vcGVuc3NsLm9yZy9kb2NzL2NyeXB0by9FVlBfRGlnZXN0SW5pdC5odG1s">EVP_DigestInit</a></p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">$ man EVP_DigestInit
...
<span style="color: #202020;">SYNOPSIS</span>
        <span style="color: #339933;">#include &lt;openssl/evp.h&gt;</span>
&nbsp;
        <span style="color: #993333;">void</span> EVP_MD_CTX_init<span style="color: #009900;">&#40;</span>EVP_MD_CTX <span style="color: #339933;">*</span>ctx<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        EVP_MD_CTX <span style="color: #339933;">*</span>EVP_MD_CTX_create<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #993333;">int</span> EVP_DigestInit_ex<span style="color: #009900;">&#40;</span>EVP_MD_CTX <span style="color: #339933;">*</span>ctx<span style="color: #339933;">,</span> <span style="color: #993333;">const</span> EVP_MD <span style="color: #339933;">*</span>type<span style="color: #339933;">,</span> ENGINE <span style="color: #339933;">*</span>impl<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #993333;">int</span> EVP_DigestUpdate<span style="color: #009900;">&#40;</span>EVP_MD_CTX <span style="color: #339933;">*</span>ctx<span style="color: #339933;">,</span> <span style="color: #993333;">const</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*</span>d<span style="color: #339933;">,</span> size_t cnt<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #993333;">int</span> EVP_DigestFinal_ex<span style="color: #009900;">&#40;</span>EVP_MD_CTX <span style="color: #339933;">*</span>ctx<span style="color: #339933;">,</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>md<span style="color: #339933;">,</span>
               <span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> <span style="color: #339933;">*</span>s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>De paso, aprovecho para desaconsejar el uso de MD5 a día de hoy y como mínimo usar SHA1 o incluso dejarte de monsergas y pasar a SHA256, SHA512.</p>
<p>He intentado que el programa sea bastante fácil de entender y seguir, ahí va:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;stdio.h&gt;</span>
<span style="color: #339933;">#include &lt;string.h&gt;</span>
&nbsp;
<span style="color: #339933;">#include &lt;openssl/evp.h&gt;</span>
&nbsp;
<span style="color: #339933;">#ifdef DEBUG</span>
<span style="color: #339933;">#define DBG 1</span>
<span style="color: #339933;">#else</span>
<span style="color: #339933;">#define DBG 0</span>
<span style="color: #339933;">#endif</span>
&nbsp;
<span style="color: #339933;">#define MAX_SIZE_WORD 200</span>
&nbsp;
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>simple_digest<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span>algth<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>buffer<span style="color: #339933;">,</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> len<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> <span style="color: #339933;">*</span>olen<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	EVP_MD <span style="color: #339933;">*</span>m<span style="color: #339933;">;</span>
	EVP_MD_CTX ctx<span style="color: #339933;">;</span>
	<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>ret<span style="color: #339933;">;</span>
&nbsp;
	OpenSSL_add_all_digests <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span>m <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>EVP_MD<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> EVP_get_digestbyname<span style="color: #009900;">&#40;</span>algth<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span> NULL<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span>ret <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> malloc<span style="color: #009900;">&#40;</span>EVP_MAX_MD_SIZE<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span> NULL<span style="color: #339933;">;</span>
&nbsp;
	EVP_DigestInit<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>ctx<span style="color: #339933;">,</span> m<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	EVP_DigestUpdate<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>ctx<span style="color: #339933;">,</span> buffer<span style="color: #339933;">,</span> len<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	EVP_DigestFinal<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>ctx<span style="color: #339933;">,</span> ret<span style="color: #339933;">,</span> olen<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> ret<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> hex_print<span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>buff<span style="color: #339933;">,</span><span style="color: #993333;">int</span> len<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>len<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%02x&quot;</span><span style="color: #339933;">,</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>buff<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">&amp;</span><span style="color: #208080;">0xFF</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">**</span>argv<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> buff<span style="color: #009900;">&#91;</span>MAX_SIZE_WORD<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> olen<span style="color: #339933;">;</span>
	<span style="color: #993333;">char</span> <span style="color: #339933;">*</span>out<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Usage: mymd5 word<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        	exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// copy arg string into a buffer</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>strlen<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> MAX_SIZE_WORD <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
		strncpy<span style="color: #009900;">&#40;</span>buff<span style="color: #339933;">,</span> argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> strlen<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// calculate string's md5 hash</span>
		out <span style="color: #339933;">=</span> simple_digest<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;md5&quot;</span><span style="color: #339933;">,</span>buff<span style="color: #339933;">,</span>strlen<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,&amp;</span>olen<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// print results	</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>DBG<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Word: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Hash: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		hex_print<span style="color: #009900;">&#40;</span>out<span style="color: #339933;">,</span>olen<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Not computing hash<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>I can feel your dark side... ;)<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Compilamos y probamos:</p>
<pre>$ gcc mymd5.c -o mymd5 -l ssl
$ ./mymd5 passworddeelite
5b4f50aa173b977e4cd0850cf7c52bd0</pre>
<p>Podemos comprobar su correcto funcionamiento comparando con webs online que ofrecen utilidades para calcular hashes MD5 [<a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5taXJhY2xlc2FsYWQuY29tL3dlYnRvb2xzL21kNS5waHA=">1</a>], [<a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL21kNS1oYXNoLW9ubGluZS53YXJheGUudXMv">2</a>].</p>
<p>Y ahora a por el crackeador. No vamos a intentar buscar colisiones sino a partir de un diccionario sacar la clave. Le pasaremos como parámetros un fichero con el hash y un diccionario con una palabra por línea.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;stdio.h&gt;</span>
<span style="color: #339933;">#include &lt;string.h&gt;</span>
&nbsp;
<span style="color: #339933;">#include &lt;openssl/evp.h&gt;</span>
&nbsp;
<span style="color: #339933;">#ifdef DEBUG</span>
<span style="color: #339933;">#define DBG 1</span>
<span style="color: #339933;">#else</span>
<span style="color: #339933;">#define DBG 0</span>
<span style="color: #339933;">#endif</span>
&nbsp;
<span style="color: #339933;">#define MAX_SIZE_BUFF 200</span>
&nbsp;
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>simple_digest<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span>algth<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>buffer<span style="color: #339933;">,</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> len<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> <span style="color: #339933;">*</span>olen<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	EVP_MD <span style="color: #339933;">*</span>m<span style="color: #339933;">;</span>
	EVP_MD_CTX ctx<span style="color: #339933;">;</span>
	<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>ret<span style="color: #339933;">;</span>
&nbsp;
	OpenSSL_add_all_digests <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span>m <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>EVP_MD<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> EVP_get_digestbyname<span style="color: #009900;">&#40;</span>algth<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span> NULL<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span>ret <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> malloc<span style="color: #009900;">&#40;</span>EVP_MAX_MD_SIZE<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span> NULL<span style="color: #339933;">;</span>
&nbsp;
	EVP_DigestInit<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>ctx<span style="color: #339933;">,</span> m<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	EVP_DigestUpdate<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>ctx<span style="color: #339933;">,</span> buffer<span style="color: #339933;">,</span> len<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	EVP_DigestFinal<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>ctx<span style="color: #339933;">,</span> ret<span style="color: #339933;">,</span> olen<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> ret<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> hex_print<span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>buff<span style="color: #339933;">,</span><span style="color: #993333;">int</span> len<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>len<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%02x&quot;</span><span style="color: #339933;">,</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>buff<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">&amp;</span><span style="color: #208080;">0xFF</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> strtohex<span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>in<span style="color: #339933;">,</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>out<span style="color: #339933;">,</span><span style="color: #993333;">int</span> len<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>
	<span style="color: #993333;">char</span> tmp<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	tmp<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>len<span style="color: #339933;">/</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		tmp<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>in<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #339933;">*</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		tmp<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>in<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #339933;">*</span>i<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		out<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>strtol<span style="color: #009900;">&#40;</span>tmp<span style="color: #339933;">,</span>NULL<span style="color: #339933;">,</span><span style="color: #0000dd;">16</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">**</span>argv<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #993333;">int</span> tries<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> buff_words<span style="color: #009900;">&#91;</span>MAX_SIZE_BUFF<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> hash<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">16</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>line<span style="color: #339933;">=</span>NULL<span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> len<span style="color: #339933;">=</span><span style="color: #0000dd;">100</span><span style="color: #339933;">,</span>read<span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> olen<span style="color: #339933;">;</span>
	<span style="color: #993333;">char</span> <span style="color: #339933;">*</span>out<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>argc<span style="color: #339933;">&lt;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Usage: mymd5crack /path/to/hashfile /path/to/dictfile<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        	exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	FILE <span style="color: #339933;">*</span>hashfile<span style="color: #339933;">;</span>
	hashfile <span style="color: #339933;">=</span> fopen<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;r&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>hashfile<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		perror<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	FILE <span style="color: #339933;">*</span>dictfile<span style="color: #339933;">;</span>
	dictfile <span style="color: #339933;">=</span> fopen<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;r&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>dictfile<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		perror<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	read <span style="color: #339933;">=</span> getline<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>line<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>len<span style="color: #339933;">,</span> hashfile<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>strlen<span style="color: #009900;">&#40;</span>line<span style="color: #009900;">&#41;</span><span style="color: #339933;">!=</span><span style="color: #0000dd;">33</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		fprintf<span style="color: #009900;">&#40;</span>stderr<span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;ERROR: Invalid hash length %d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>strlen<span style="color: #009900;">&#40;</span>line<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>	
&nbsp;
	strtohex<span style="color: #009900;">&#40;</span>line<span style="color: #339933;">,</span>hash<span style="color: #339933;">,</span><span style="color: #0000dd;">32</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>DBG<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Input hash: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> line<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Input buffer from hash: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			hex_print<span style="color: #009900;">&#40;</span>hash<span style="color: #339933;">,</span><span style="color: #0000dd;">16</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Read words in a loop</span>
	<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>read <span style="color: #339933;">=</span> getline<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>line<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>len<span style="color: #339933;">,</span> dictfile<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> strlen<span style="color: #009900;">&#40;</span>line<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			tries<span style="color: #339933;">++;</span>	
&nbsp;
			<span style="color: #666666; font-style: italic;">//Copy word into buffer</span>
			strcpy<span style="color: #009900;">&#40;</span>buff_words<span style="color: #339933;">,</span>line<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>DBG<span style="color: #009900;">&#41;</span>
				<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Input buffer from dict: %s <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>buff_words<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #666666; font-style: italic;">// compute md5</span>
			out <span style="color: #339933;">=</span> simple_digest<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;md5&quot;</span><span style="color: #339933;">,</span>buff_words<span style="color: #339933;">,</span>strlen<span style="color: #009900;">&#40;</span>line<span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">,&amp;</span>olen<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>DBG<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>	
				<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;For password %s MD5 is: &quot;</span><span style="color: #339933;">,</span>line<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				hex_print<span style="color: #009900;">&#40;</span>out<span style="color: #339933;">,</span>olen<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">//Compare computed md5 with hash</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>memcmp<span style="color: #009900;">&#40;</span>out<span style="color: #339933;">,</span>hash<span style="color: #339933;">,</span><span style="color: #0000dd;">16</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
				<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;PASSWORD FOUND!! in %d tries: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>tries<span style="color: #339933;">,</span>line<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				fclose<span style="color: #009900;">&#40;</span>hashfile<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				fclose<span style="color: #009900;">&#40;</span>dictfile<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				free<span style="color: #009900;">&#40;</span>out<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>line<span style="color: #009900;">&#41;</span>
					free<span style="color: #009900;">&#40;</span>line<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>	
			<span style="color: #009900;">&#125;</span>
			free<span style="color: #009900;">&#40;</span>out<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Words from dict too long... cough*, cough*...<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Password not found in %d tries!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>tries<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>line<span style="color: #009900;">&#41;</span>
		free<span style="color: #009900;">&#40;</span>line<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	fclose<span style="color: #009900;">&#40;</span>hashfile<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	fclose<span style="color: #009900;">&#40;</span>dictfile<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Y comprobamos su funcionamiento metiendo en /tmp/hash el hash obtenido anteriormente:</p>
<pre>$ gcc mymd5cracker.c -o mymd5cracker -l ssl
$ ./mymd5cracker /tmp/hash /tmp/dict
PASSWORD FOUND!! in 6 tries: passworddeelite</pre>
<p>Premio! Podéis ir en paz.</p>
<p>Para descargar <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDA5LzA4L215bWQ1LmM=">mymd5.c</a> y <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDA5LzA4L215bWQ1Y3JhY2tlci5j">mymd5cracker.c</a></p>
<p>Gracias a <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3R1eGVkLnNlcnZlYmxvZy5uZXQ=">TuXeD</a> que siempre está ahí para echar una mano.<br/><br/><i>&#8211;<br/>Fuente original en <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNz">http://vierito.es/wordpress</a></i><br/><br/><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMDkvMDQvMTgvZGVzY2lmcmFuZG8tdW4tcmV0by1kZWwtZmJpLw==" rel=\"bookmark\" title=\"April 18, 2009\">Descifrando un reto del FBI</a></li>
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMDkvMDUvMjIvc29sdWNpb25lcy1kZWwtcmV0by1kZS1jcmlwdG9ncmFmaWEtcGFydGUtMi8=" rel=\"bookmark\" title=\"May 22, 2009\">Soluciones del reto de criptografía &#8211; Parte 2</a></li>
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMDkvMDkvMjUvcG9ydC1rbm9ja2luZy15LWNyeXB0LXBvcnQta25vY2tpbmcv" rel=\"bookmark\" title=\"September 25, 2009\">Port-Knocking y Crypt-Port-Knocking</a></li>
</ul>
<p><!-- Similar Posts took 6.680 ms --></p>
 <img src="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=642" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://vierito.es/wordpress/2009/08/28/crackeador-de-hashes-md5-en-c-y-openssl/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>[Fprint] La implemetación del driver</title>
		<link>http://vierito.es/wordpress/2008/10/30/fprint-la-implemetacion-del-driver/</link>
		<comments>http://vierito.es/wordpress/2008/10/30/fprint-la-implemetacion-del-driver/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 13:41:37 +0000</pubDate>
		<dc:creator>vierito5</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[driver]]></category>
		<category><![CDATA[fingerprint]]></category>
		<category><![CDATA[fprint]]></category>
		<category><![CDATA[glib]]></category>
		<category><![CDATA[huellas dactilares]]></category>
		<category><![CDATA[libusb]]></category>

		<guid isPermaLink="false">http://vierito.es/wordpress/?p=140</guid>
		<description><![CDATA[Ya sabemos, por los posts anteriores, que funciones necesitaremos tener disponibles o no dependiendo del dispositivo que estemos usando. El driver está desarrollado en C, como no, ¿por qué? pues porque: es adecuado para programar drivers porque nos proporciona funcionalidad a &#8216;bajo nivel&#8217; siendo un lenguaje de &#8216;alto nivel&#8217;. facilmente podremos crear bindings en c++, [...]]]></description>
			<content:encoded><![CDATA[<p>Ya sabemos, <a title=\"[Fprint] Procesado de la imagen - Huellas dactilares\" href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMDgvMTAvMjQvZnByaW50LXByb2Nlc2Fkby1kZS1sYS1pbWFnZW4taHVlbGxhcy1kYWN0aWxhcmVzLw==">por los posts anteriores</a>, que funciones necesitaremos tener disponibles o no dependiendo del <a title=\"[Fprint] Los dispositivos\" href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMDgvMTAvMDkvZnByaW50LWxvcy1kaXNwb3NpdGl2b3Mv">dispositivo</a> que estemos usando.</p>
<p>El driver está desarrollado en C, como no, ¿por qué? pues porque:</p>
<ul>
<li>es adecuado para programar drivers porque nos proporciona funcionalidad a &#8216;bajo nivel&#8217; siendo un lenguaje de &#8216;alto nivel&#8217;.</li>
<li>facilmente podremos crear bindings en c++, java, python, ruby, &#8230;</li>
<li>será fácil luego adaptarlo a sistema embebidos (empotrados, embedded o como se les quieran llamar)</li>
</ul>
<p>Está implementado en forma de librería y recibe el nombre de libfprint y depende de otras librerías como:</p>
<ul>
<li>libusb: nos proporciona I/O al bus USB y además es portable a FreeBSD, Mac OSX, Windows y más.</li>
<li>glib: un gran librería de rutinas en C de las cuales usaremos unas poquitas (listas enlazadas, operaciones sobre strings, para reservar memoria, etc)</li>
</ul>
<p>A continuación os pongo un esquema de como está estructurado:</p>
<p style="text-align: center;"><a title=\"Fprint driver abstraction model\" href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDA4LzEwL2RyaXZlci1hYnN0cmFjdGlvbi1tb2RlbA=="><img class="aligncenter" src="http://vierito.es/wordpress/wp-content/uploads/2008/10/driver-abstraction-model" alt="Fprint driver abstraction model" /></a></p>
<p>Como se puede ver, tendremos una API de alto nivel donde se nos proporcionan funciones para registrar huellas de dedos (enrollment), verificar (comprobar que la huella escaneada coincide con la almacenada contra la que se ha pedido confirmación) y identificar (encontrar entre las huellas almacenadas una que coincida con la escaneada). La diferencia entre verificar y identificar sería la misma que entre elegir tu nombre de usuario y escanear tu dedo y en lugar de eso escanear tu huella y que el sistema reconozca tu usuario y te confirme.</p>
<p>De estas funciones tendríamos 2 variantes, la que nos devuelve la imagen por si además si quisiéramos hacer alguna cosa con ella y que simplemente realiza su función:</p>
<p>- fp_enroll_finger( )<br />
- fp_verify_finger( )<br />
- fp_identify_finger( )<br />
- fp_enroll_finger<strong>_img(</strong> )<br />
- &#8230;</p>
<p>luego podríamos usar un trozo de código similar a esto:</p>
<p>if (is_imaging_device(dev))<br />
fp_enroll_finger_img(&amp;data, &amp;img);<br />
else<br />
fp_enroll_finger(&amp;data);</p>
<p>Para empezar a usar los dispositivos tendremos disponibles las siguiente funciones que son bastante autoexplicativas:</p>
<p>- fp_discover_devices()<br />
- fp_dev_open() / fp_dev_close()</p>
<p>Para detectar qué dispositivo tenemos es fácil ya que el descriptor del dispositivo incluye un código con el Vendor (fabricante) y el Product ID (identificación de producto) que lo identifica inequívocamente. Por ejemplo, podremos obtener ese código con un simple  &#8216;lsusb&#8217;.</p>
<p>Por debajo de la capa &#8220;Imaging layer&#8221; para escanear necesitaremos las funciones para detectar la presencia del dedo, escanear y detectar la ausencia de dedo.</p>
<p>Como ya hemos contado en otros posts, el dispositivo upek al ser autónomo no requerirá de estas funciones.</p>
<p>Igualmente dispondremos de una serie de funciones para el almacenamiento.</p>
<p>Para el que quiera entretenerse un rato aquí hay más información sobre la API disponible: <a title=\"Fprint API libfprint\" href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5yZWFjdGl2YXRlZC5uZXQvZnByaW50L2FwaS8=">http://www.reactivated.net/fprint/api/</a><br/><br/><i>&#8211;<br/>Fuente original en <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNz">http://vierito.es/wordpress</a></i><br/><br/><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMDgvMTEvMDYvZnByaW50LW1lam9yYXMtZW4tZWwtZHJpdmVycy15LWFsZ3Vub3MtZXh0cmFzLw==" rel=\"bookmark\" title=\"November 6, 2008\">[Fprint] Mejoras en el driver y algunos extras</a></li>
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMDgvMTAvMDkvZnByaW50LWxvcy1kaXNwb3NpdGl2b3Mv" rel=\"bookmark\" title=\"October 9, 2008\">[Fprint] Los dispositivos</a></li>
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMDgvMTAvMjQvZnByaW50LXByb2Nlc2Fkby1kZS1sYS1pbWFnZW4taHVlbGxhcy1kYWN0aWxhcmVzLw==" rel=\"bookmark\" title=\"October 24, 2008\">[Fprint] Procesado de la imagen &#8211; Huellas dactilares</a></li>
</ul>
<p><!-- Similar Posts took 6.496 ms --></p>
 <img src="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=140" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://vierito.es/wordpress/2008/10/30/fprint-la-implemetacion-del-driver/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mis primeros pasos con OpenGL</title>
		<link>http://vierito.es/wordpress/2008/05/19/mis-primeros-pasos-con-opengl/</link>
		<comments>http://vierito.es/wordpress/2008/05/19/mis-primeros-pasos-con-opengl/#comments</comments>
		<pubDate>Sun, 18 May 2008 22:13:27 +0000</pubDate>
		<dc:creator>vierito5</dc:creator>
				<category><![CDATA[ieee]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ati]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[nvidia]]></category>
		<category><![CDATA[opengl]]></category>
		<category><![CDATA[sdl]]></category>

		<guid isPermaLink="false">http://vierito.es/wordpress/2008/05/19/mis-primeros-pasos-con-opengl/</guid>
		<description><![CDATA[Hace unas semanas me apunté al curso introductorio a OpenGL que daba Egon directo desde la rama de IEEE de Valencia. Este curso pretendía ser algo básico, partiendo desde cero, aunque bastante condensado para que puedas sacarle jugo más adelante a lo visto. La verdad es que me gustó mucho y me ha dejado un [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDA4LzA1L29wZW5nbF9sb2dvLmpwZw==" title=\"Logo OpenGL\"></a></p>
<p style="text-align: center"><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDA4LzA1L29wZW5nbF9sb2dvLmpwZw==" title=\"Logo OpenGL\"><img src="http://vierito.es/wordpress/wp-content/uploads/2008/05/opengl_logo.jpg" alt="Logo OpenGL" /></a></p>
<p>Hace unas semanas me apunté al curso introductorio a <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5vcGVuZ2wub3JnLw==" title=\"OpenGL\">OpenGL</a> que daba <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2Jvb2xlcmlhLndvcmRwcmVzcy5jb20v" title=\"Cantando en binario\">Egon</a> directo desde la rama de <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy51cHYuZXMvaWVlZQ==" title=\"IEEEsb-UPV - Rama IEEE de Valencia\">IEEE</a> de Valencia. Este curso pretendía ser algo básico, partiendo desde cero, aunque bastante condensado para que puedas sacarle jugo más adelante a lo visto. La verdad es que me gustó mucho y me ha dejado un buen sabor de boca, con ganas de más.</p>
<p>Desde un principio estuvimos probando todas las cosas que se iban comentando en clase y se dejó un ejercicio propuesto para que nos entretuviéramos un poquito más. Era una escena de un planeta tierra y demás cositas dando vueltas que teníamos que copiar así que me he decidido a publicar mi solución para generar esa escena. Aunque la idea era la misma, he cambiado objetos, modelos, órbitas, rotaciones, etc, así me ha resultado más entretenido.</p>
<p>Para no aburrir con un rollo largo sobre <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2VzLndpa2lwZWRpYS5vcmcvd2lraS9PcGVuZ2w=" title=\"OpenGL Wikipedia\">OpenGL</a> a continuación os pondré el código con bastantes comentarios de modo que quede bastante claro. Está programado en C++ usando librerías de <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5saWJzZGwub3JnLw==" title=\"LibSDL\">SDL</a> y alguna más para otras funcionalidades.</p>
<p>Alguna parte del código es un poco cerda pero para que sirva de ejemplo ya os sobra!! <img src='http://vierito.es/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Como creo que debe ser bastante incómodo leer el código en un post <strong>aquí tenéis el <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDA4LzA1L21haW4uY3Bw" title=\"main.cpp\">main.cpp</a></strong> <strong>comentado</strong> y si queréis ver el resultado <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2VudGUudGxjLnVwdi5lcy9+amF2aS9FamVtcGxvJTIwT3BlbkdMJTIwTWlwbWFwcy5yYXI=" title=\"Ejemplo OpenGL sobre nVIDIA/ATI\">aquí tenéis un .rar para ejecutarlo sobre tarjetas nVIDIA y ATI</a> y <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2VudGUudGxjLnVwdi5lcy9+amF2aS9FamVtcGxvJTIwT3BlbkdMLnJhcg==" title=\"Ejemplo OpenGL sobre Intel\">aquí sobre Intel</a>. Se podía poner una función que detectara que hacer en cada caso pero soy un perro. Os dejo por ahí dentro también las librerías por si queréis echarles un vistazo.</p>
<p>Espero que os guste!<br/><br/><i>&#8211;<br/>Fuente original en <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNz">http://vierito.es/wordpress</a></i><br/><br/><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMDgvMTAvMzAvZnByaW50LWxhLWltcGxlbWV0YWNpb24tZGVsLWRyaXZlci8=" rel=\"bookmark\" title=\"October 30, 2008\">[Fprint] La implemetación del driver</a></li>
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMDkvMDUvMjIvc29sdWNpb25lcy1kZWwtcmV0by1kZS1jcmlwdG9ncmFmaWEtcGFydGUtMi8=" rel=\"bookmark\" title=\"May 22, 2009\">Soluciones del reto de criptografía &#8211; Parte 2</a></li>
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMDkvMDgvMjgvY3JhY2tlYWRvci1kZS1oYXNoZXMtbWQ1LWVuLWMteS1vcGVuc3NsLw==" rel=\"bookmark\" title=\"August 28, 2009\">Crackeador de hashes MD5 en C y OpenSSL</a></li>
</ul>
<p><!-- Similar Posts took 5.773 ms --></p>
 <img src="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=64" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://vierito.es/wordpress/2008/05/19/mis-primeros-pasos-con-opengl/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

