M2_SETI/A1/tp-spa/img/passwdcheck.c.html

371 lines
17 KiB
HTML
Raw Permalink Normal View History

2022-10-26 10:01:19 +02:00
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<!-- Created by htmlize-1.57 in css mode. -->
<html>
<head>
<title>passwdcheck.c</title>
<style type="text/css">
<!--
body {
color: #655370;
background-color: #fbf8ef;
}
.comment {
/* font-lock-comment-face */
color: #2aa1ae;
background-color: #ecf3ec;
}
.comment-delimiter {
/* font-lock-comment-delimiter-face */
color: #2aa1ae;
background-color: #ecf3ec;
}
.function-name {
/* font-lock-function-name-face */
color: #6c3163;
font-weight: bold;
}
.highlight-numbers-number {
/* highlight-numbers-number */
color: #4e3163;
}
.hl-line {
/* hl-line */
background-color: #efeae9;
}
.keyword {
/* font-lock-keyword-face */
color: #3a81c3;
font-weight: bold;
}
.link {
/* link */
color: #2aa1ae;
text-decoration: underline;
}
.preprocessor {
/* font-lock-preprocessor-face */
color: #6c3163;
}
.rainbow-delimiters-depth-1 {
/* rainbow-delimiters-depth-1-face */
color: #3a81c3;
}
.rainbow-delimiters-depth-2 {
/* rainbow-delimiters-depth-2-face */
color: #6c3163;
}
.rainbow-delimiters-depth-3 {
/* rainbow-delimiters-depth-3-face */
color: #2d9574;
}
.rainbow-delimiters-depth-4 {
/* rainbow-delimiters-depth-4-face */
color: #67b11d;
}
.rainbow-delimiters-depth-5 {
/* rainbow-delimiters-depth-5-face */
color: #b1951d;
}
.sp-show-pair-match {
/* sp-show-pair-match-face */
color: #ba2f59;
font-weight: bold;
text-decoration: underline;
}
.sp-show-pair-match-content {
}
.string {
/* font-lock-string-face */
color: #2d9574;
}
.type {
/* font-lock-type-face */
color: #ba2f59;
font-weight: bold;
}
.variable-name {
/* font-lock-variable-name-face */
color: #715ab1;
}
a {
color: inherit;
background-color: inherit;
font: inherit;
text-decoration: inherit;
}
a:hover {
text-decoration: underline;
}
-->
</style>
</head>
<body>
<pre>
<span class="comment-delimiter"><span class="sp-show-pair-match"><span class="hl-line"> /*</span></span></span><span class="comment"><span class="sp-show-pair-match-content"><span class="hl-line">
</span></span></span><span class="comment"><span class="sp-show-pair-match-content"> This file is part of the ChipWhisperer Example Targets
Copyright (C) 2012-2015 NewAE Technology Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <a href="http://www.gnu.org/licenses/&gt;.
*/
#include &quot;hal.h&quot;
#include &lt;stdint.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h">&lt;</a></span></span><span class="comment"><span class="sp-show-pair-match-content"><span class="link"><a href="http://www.gnu.org/licenses/&gt;.
*/
#include &quot;hal.h&quot;
#include &lt;stdint.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h">http://www.gnu.org/licenses/</a></span></span></span><span class="comment"><span class="sp-show-pair-match-content"><a href="http://www.gnu.org/licenses/&gt;.
*/
#include &quot;hal.h&quot;
#include &lt;stdint.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h">&gt;.
</a></span></span><span class="comment-delimiter"><span class="sp-show-pair-match"> <a href="http://www.gnu.org/licenses/&gt;.
*/
#include &quot;hal.h&quot;
#include &lt;stdint.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h">*/</a></span></span><a href="http://www.gnu.org/licenses/&gt;.
*/
#include &quot;hal.h&quot;
#include &lt;stdint.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h">
</a> <a href="http://www.gnu.org/licenses/&gt;.
*/
#include &quot;hal.h&quot;
#include &lt;stdint.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h">
</a><span class="preprocessor"> <a href="http://www.gnu.org/licenses/&gt;.
*/
#include &quot;hal.h&quot;
#include &lt;stdint.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h">#include</a></span><a href="http://www.gnu.org/licenses/&gt;.
*/
#include &quot;hal.h&quot;
#include &lt;stdint.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h"> </a><span class="string"><a href="http://www.gnu.org/licenses/&gt;.
*/
#include &quot;hal.h&quot;
#include &lt;stdint.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h">"hal.h"</a></span><a href="http://www.gnu.org/licenses/&gt;.
*/
#include &quot;hal.h&quot;
#include &lt;stdint.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h">
</a><span class="preprocessor"> <a href="http://www.gnu.org/licenses/&gt;.
*/
#include &quot;hal.h&quot;
#include &lt;stdint.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h">#include</a></span><a href="http://www.gnu.org/licenses/&gt;.
*/
#include &quot;hal.h&quot;
#include &lt;stdint.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h"> </a><span class="string"><span class="rainbow-delimiters-depth-1"><a href="http://www.gnu.org/licenses/&gt;.
*/
#include &quot;hal.h&quot;
#include &lt;stdint.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h">&lt;</a></span></span><span class="string"><a href="http://www.gnu.org/licenses/&gt;.
*/
#include &quot;hal.h&quot;
#include &lt;stdint.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h">stdint.h</a></span><span class="string"><span class="rainbow-delimiters-depth-1"><a href="http://www.gnu.org/licenses/&gt;.
*/
#include &quot;hal.h&quot;
#include &lt;stdint.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h">&gt;</a></span></span><a href="http://www.gnu.org/licenses/&gt;.
*/
#include &quot;hal.h&quot;
#include &lt;stdint.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h">
</a><span class="preprocessor"> <a href="http://www.gnu.org/licenses/&gt;.
*/
#include &quot;hal.h&quot;
#include &lt;stdint.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h">#include</a></span><a href="http://www.gnu.org/licenses/&gt;.
*/
#include &quot;hal.h&quot;
#include &lt;stdint.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h"> </a><span class="string"><span class="rainbow-delimiters-depth-1"><a href="http://www.gnu.org/licenses/&gt;.
*/
#include &quot;hal.h&quot;
#include &lt;stdint.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h">&lt;</a></span></span><span class="string"><a href="http://www.gnu.org/licenses/&gt;.
*/
#include &quot;hal.h&quot;
#include &lt;stdint.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h">stdlib.h</a></span><span class="string"><span class="rainbow-delimiters-depth-1"><a href="http://www.gnu.org/licenses/&gt;.
*/
#include &quot;hal.h&quot;
#include &lt;stdint.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h">&gt;</a></span></span><a href="http://www.gnu.org/licenses/&gt;.
*/
#include &quot;hal.h&quot;
#include &lt;stdint.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h">
</a><span class="preprocessor"> <a href="http://www.gnu.org/licenses/&gt;.
*/
#include &quot;hal.h&quot;
#include &lt;stdint.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h">#include</a></span><a href="http://www.gnu.org/licenses/&gt;.
*/
#include &quot;hal.h&quot;
#include &lt;stdint.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h"> </a><span class="string"><span class="rainbow-delimiters-depth-1"><a href="http://www.gnu.org/licenses/&gt;.
*/
#include &quot;hal.h&quot;
#include &lt;stdint.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h">&lt;</a></span></span><span class="string"><a href="http://www.gnu.org/licenses/&gt;.
*/
#include &quot;hal.h&quot;
#include &lt;stdint.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h">stdio.h</a></span><span class="string"><span class="rainbow-delimiters-depth-1"><a href="http://www.gnu.org/licenses/&gt;.
*/
#include &quot;hal.h&quot;
#include &lt;stdint.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h">&gt;</a></span></span>
<span class="preprocessor"> #define</span> <span class="variable-name">BUFLEN</span> <span class="highlight-numbers-number">64</span>
<span class="keyword"> static</span> <span class="type">void</span> <span class="function-name">delay_2_ms</span><span class="rainbow-delimiters-depth-1">(</span><span class="type">void</span><span class="rainbow-delimiters-depth-1">)</span>;
<span class="type"> void</span> <span class="function-name">my_puts</span><span class="rainbow-delimiters-depth-1">(</span><span class="type">char</span> *<span class="variable-name">c</span><span class="rainbow-delimiters-depth-1">)</span>
<span class="rainbow-delimiters-depth-1"> {</span>
<span class="keyword">do</span> <span class="rainbow-delimiters-depth-2">{</span>
putch<span class="rainbow-delimiters-depth-3">(</span>*c<span class="rainbow-delimiters-depth-3">)</span>;
<span class="rainbow-delimiters-depth-2">}</span> <span class="keyword">while</span> <span class="rainbow-delimiters-depth-2">(</span>*++c<span class="rainbow-delimiters-depth-2">)</span>;
<span class="rainbow-delimiters-depth-1"> }</span>
<span class="keyword">static</span> <span class="type">void</span> <span class="function-name">delay_2_ms</span><span class="rainbow-delimiters-depth-1">()</span>
<span class="rainbow-delimiters-depth-1">{</span>
<span class="keyword">for</span> <span class="rainbow-delimiters-depth-2">(</span><span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span> <span class="variable-name">i</span>=<span class="highlight-numbers-number">0</span>; i &lt; <span class="highlight-numbers-number">0xfff</span>; i++ <span class="rainbow-delimiters-depth-2">){</span>
;
<span class="rainbow-delimiters-depth-2">}</span>
<span class="rainbow-delimiters-depth-1">}</span>
<span class="type">void</span> <span class="function-name">my_read</span><span class="rainbow-delimiters-depth-1">(</span><span class="type">char</span> *<span class="variable-name">buf</span>, <span class="type">int</span> <span class="variable-name">len</span><span class="rainbow-delimiters-depth-1">)</span>
<span class="rainbow-delimiters-depth-1">{</span>
<span class="keyword">for</span><span class="rainbow-delimiters-depth-2">(</span><span class="type">int</span> <span class="variable-name">i</span> = <span class="highlight-numbers-number">0</span>; i &lt; len; i++<span class="rainbow-delimiters-depth-2">)</span> <span class="rainbow-delimiters-depth-2">{</span>
<span class="keyword">while</span> <span class="rainbow-delimiters-depth-3">(</span>buf<span class="rainbow-delimiters-depth-4">[</span>i<span class="rainbow-delimiters-depth-4">]</span> = getch<span class="rainbow-delimiters-depth-4">()</span>, buf<span class="rainbow-delimiters-depth-4">[</span>i<span class="rainbow-delimiters-depth-4">]</span> == <span class="string">'\0'</span><span class="rainbow-delimiters-depth-3">)</span>;
<span class="keyword">if</span> <span class="rainbow-delimiters-depth-3">(</span>buf<span class="rainbow-delimiters-depth-4">[</span>i<span class="rainbow-delimiters-depth-4">]</span> == <span class="string">'\n'</span><span class="rainbow-delimiters-depth-3">)</span> <span class="rainbow-delimiters-depth-3">{</span>
buf<span class="rainbow-delimiters-depth-4">[</span>i<span class="rainbow-delimiters-depth-4">]</span> = <span class="string">'\0'</span>;
<span class="keyword">return</span>;
<span class="rainbow-delimiters-depth-3">}</span>
<span class="rainbow-delimiters-depth-2">}</span>
buf<span class="rainbow-delimiters-depth-2">[</span>len - <span class="highlight-numbers-number">1</span><span class="rainbow-delimiters-depth-2">]</span> = <span class="string">'\0'</span>;
<span class="rainbow-delimiters-depth-1">}</span>
<span class="type">int</span> <span class="function-name">main</span><span class="rainbow-delimiters-depth-1">(</span><span class="type">void</span><span class="rainbow-delimiters-depth-1">)</span>
<span class="rainbow-delimiters-depth-1">{</span>
platform_init<span class="rainbow-delimiters-depth-2">()</span>;
init_uart<span class="rainbow-delimiters-depth-2">()</span>;
<span class="type">char</span> <span class="variable-name">passwd</span><span class="rainbow-delimiters-depth-2">[</span><span class="highlight-numbers-number">32</span><span class="rainbow-delimiters-depth-2">]</span>;
<span class="type">char</span> <span class="variable-name">correct_passwd</span><span class="rainbow-delimiters-depth-2">[]</span> = <span class="string">"xxxxx"</span>;
<span class="keyword">while</span><span class="rainbow-delimiters-depth-2">(</span><span class="highlight-numbers-number">1</span><span class="rainbow-delimiters-depth-2">){</span>
my_puts<span class="rainbow-delimiters-depth-3">(</span><span class="string">"*****Safe-o-matic 3000 Booting...\n"</span><span class="rainbow-delimiters-depth-3">)</span>;
<span class="comment-delimiter">//</span><span class="comment">Give them one last warning
</span> my_puts<span class="rainbow-delimiters-depth-3">(</span><span class="string">"WARNING: UNAUTHORIZED ACCESS WILL BE PUNISHED\n"</span><span class="rainbow-delimiters-depth-3">)</span>;
<span class="comment-delimiter">//</span><span class="comment">Get password
</span> my_puts<span class="rainbow-delimiters-depth-3">(</span><span class="string">"Please enter password to continue: "</span><span class="rainbow-delimiters-depth-3">)</span>;
my_read<span class="rainbow-delimiters-depth-3">(</span>passwd, <span class="highlight-numbers-number">32</span><span class="rainbow-delimiters-depth-3">)</span>;
<span class="type">uint8_t</span> <span class="variable-name">passbad</span> = <span class="highlight-numbers-number">0</span>;
<span class="keyword">for</span><span class="rainbow-delimiters-depth-3">(</span><span class="type">uint8_t</span> <span class="variable-name">i</span> = <span class="highlight-numbers-number">0</span>; i &lt; <span class="keyword">sizeof</span><span class="rainbow-delimiters-depth-4">(</span>correct_passwd<span class="rainbow-delimiters-depth-4">)</span>; i++<span class="rainbow-delimiters-depth-3">){</span>
<span class="keyword">if</span> <span class="rainbow-delimiters-depth-4">(</span>correct_passwd<span class="rainbow-delimiters-depth-5">[</span>i<span class="rainbow-delimiters-depth-5">]</span> != passwd<span class="rainbow-delimiters-depth-5">[</span>i<span class="rainbow-delimiters-depth-5">]</span><span class="rainbow-delimiters-depth-4">){</span>
passbad = <span class="highlight-numbers-number">1</span>;
<span class="keyword">break</span>;
<span class="rainbow-delimiters-depth-4">}</span>
<span class="rainbow-delimiters-depth-3">}</span>
<span class="keyword">if</span> <span class="rainbow-delimiters-depth-3">(</span>passbad<span class="rainbow-delimiters-depth-3">){</span>
delay_2_ms<span class="rainbow-delimiters-depth-4">()</span>;
delay_2_ms<span class="rainbow-delimiters-depth-4">()</span>;
my_puts<span class="rainbow-delimiters-depth-4">(</span><span class="string">"Wrong password. Access denied!\n"</span><span class="rainbow-delimiters-depth-4">)</span>;
my_puts<span class="rainbow-delimiters-depth-4">(</span><span class="string">"\n"</span><span class="rainbow-delimiters-depth-4">)</span>;
led_error<span class="rainbow-delimiters-depth-4">(</span><span class="highlight-numbers-number">1</span><span class="rainbow-delimiters-depth-4">)</span>;
<span class="rainbow-delimiters-depth-3">}</span> <span class="keyword">else</span> <span class="rainbow-delimiters-depth-3">{</span>
my_puts<span class="rainbow-delimiters-depth-4">(</span><span class="string">"Access granted, welcome!\n"</span><span class="rainbow-delimiters-depth-4">)</span>;
led_ok<span class="rainbow-delimiters-depth-4">(</span><span class="highlight-numbers-number">1</span><span class="rainbow-delimiters-depth-4">)</span>;
<span class="rainbow-delimiters-depth-3">}</span>
<span class="comment-delimiter">//</span><span class="comment">All done;
</span> <span class="keyword">while</span><span class="rainbow-delimiters-depth-3">(</span><span class="highlight-numbers-number">1</span><span class="rainbow-delimiters-depth-3">)</span>;
<span class="rainbow-delimiters-depth-2">}</span>
<span class="keyword">return</span> <span class="highlight-numbers-number">1</span>;
<span class="rainbow-delimiters-depth-1">}</span>
</pre>
</body>
</html>