Dependencies:   net 1-wire lpc1768 crypto clock web fram log

/media/uploads/andrewboyson/heating.sch

/media/uploads/andrewboyson/heating.brd

/media/uploads/andrewboyson/eagle.epf

Committer:
andrewboyson
Date:
Wed Jul 31 15:13:56 2019 +0000
Revision:
68:19c5efffc900
Parent:
67:2d379b0c5f05
Child:
69:ca9010196c6e
Updated libraries

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewboyson 49:9491c966dc60 1 #include <stdio.h>
andrewboyson 67:2d379b0c5f05 2 #include <string.h>
andrewboyson 49:9491c966dc60 3
andrewboyson 49:9491c966dc60 4 #include "http.h"
andrewboyson 53:c1bf7d9db507 5 #include "web-nav-this.h"
andrewboyson 51:c7c6ce0d57ad 6 #include "web-add.h"
andrewboyson 67:2d379b0c5f05 7 #include "log.h"
andrewboyson 63:ae264156d655 8 #include "bignum.h"
andrewboyson 67:2d379b0c5f05 9 #include "sha-256.h"
andrewboyson 67:2d379b0c5f05 10 #include "hmac-sha-256.h"
andrewboyson 49:9491c966dc60 11
andrewboyson 49:9491c966dc60 12 void WebSystemHtml()
andrewboyson 49:9491c966dc60 13 {
andrewboyson 49:9491c966dc60 14 HttpOk("text/html; charset=UTF-8", "no-cache", NULL, NULL);
andrewboyson 51:c7c6ce0d57ad 15 WebAddHeader("System", "settings.css", "system.js");
andrewboyson 51:c7c6ce0d57ad 16 WebAddNav(SYSTEM_PAGE);
andrewboyson 51:c7c6ce0d57ad 17 WebAddH1("System");
andrewboyson 49:9491c966dc60 18
andrewboyson 51:c7c6ce0d57ad 19 WebAddH2("TFTP");
andrewboyson 51:c7c6ce0d57ad 20 WebAddAjaxInput ("Server url", 5, "ajax-server-name", "tftpserver" );
andrewboyson 51:c7c6ce0d57ad 21 WebAddAjaxInput ("File (strftime)", 11, "ajax-file-name", "tftpfilename" );
andrewboyson 51:c7c6ce0d57ad 22 WebAddAjaxInput ("Interval (secs) 0=no", 5, "ajax-read-interval", "tftpreadint" );
andrewboyson 51:c7c6ce0d57ad 23 WebAddAjaxInput ("Records per backup 0=no", 5, "ajax-write-size", "tftpwriteint" );
andrewboyson 51:c7c6ce0d57ad 24 WebAddAjaxLabelled("Count", "ajax-count" );
andrewboyson 51:c7c6ce0d57ad 25 WebAddAjaxLabelled("Started", "ajax-start-time" );
andrewboyson 49:9491c966dc60 26
andrewboyson 51:c7c6ce0d57ad 27 WebAddH2("FRAM");
andrewboyson 51:c7c6ce0d57ad 28 WebAddAjaxLabelled("Used", "ajax-fram-used" );
andrewboyson 49:9491c966dc60 29
andrewboyson 51:c7c6ce0d57ad 30 WebAddH2("Compiler");
andrewboyson 51:c7c6ce0d57ad 31 WebAddLabelledInt("Version Vvvbbbb", __ARMCC_VERSION);
andrewboyson 49:9491c966dc60 32
andrewboyson 67:2d379b0c5f05 33 WebAddH2("SHA 256 test");
andrewboyson 67:2d379b0c5f05 34 char hash[32];
andrewboyson 67:2d379b0c5f05 35 char* input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
andrewboyson 67:2d379b0c5f05 36 Sha256(input, strlen(input), hash);
andrewboyson 67:2d379b0c5f05 37 HttpAddText("<code>");
andrewboyson 67:2d379b0c5f05 38 HttpAddBytesAsHex(hash, sizeof(hash));
andrewboyson 67:2d379b0c5f05 39 HttpAddText("</code>");
andrewboyson 67:2d379b0c5f05 40
andrewboyson 67:2d379b0c5f05 41 WebAddH2("HMAC SHA 256 test");
andrewboyson 67:2d379b0c5f05 42 char* key = "Jefe";
andrewboyson 67:2d379b0c5f05 43 char* msg = "what do ya want for nothing?";
andrewboyson 67:2d379b0c5f05 44 char mac[32];
andrewboyson 67:2d379b0c5f05 45 HmacSha256(key, strlen(key), msg, strlen(msg), mac);
andrewboyson 67:2d379b0c5f05 46 HttpAddText("<code>");
andrewboyson 67:2d379b0c5f05 47 HttpAddBytesAsHex(mac, sizeof(mac));
andrewboyson 67:2d379b0c5f05 48 HttpAddText("</code>");
andrewboyson 67:2d379b0c5f05 49
andrewboyson 63:ae264156d655 50 WebAddH2("Big num test");
andrewboyson 63:ae264156d655 51
andrewboyson 63:ae264156d655 52 char* n =
andrewboyson 63:ae264156d655 53 "E08973398DD8F5F5E88776397F4EB005BB5383DE0FB7ABDC7DC775290D052E6D"
andrewboyson 63:ae264156d655 54 "12DFA68626D4D26FAA5829FC97ECFA82510F3080BEB1509E4644F12CBBD832CF"
andrewboyson 63:ae264156d655 55 "C6686F07D9B060ACBEEE34096A13F5F7050593DF5EBA3556D961FF197FC981E6"
andrewboyson 63:ae264156d655 56 "F86CEA874070EFAC6D2C749F2DFA553AB9997702A648528C4EF357385774575F";
andrewboyson 63:ae264156d655 57
andrewboyson 63:ae264156d655 58 char* d =
andrewboyson 63:ae264156d655 59 "00A403C327477634346CA686B57949014B2E8AD2C862B2C7D748096A8B91F736"
andrewboyson 63:ae264156d655 60 "F275D6E8CD15906027314735644D95CD6763CEB49F56AC2F376E1CEE0EBF282D"
andrewboyson 63:ae264156d655 61 "F439906F34D86E085BD5656AD841F313D72D395EFE33CBFF29E4030B3D05A28F"
andrewboyson 63:ae264156d655 62 "B7F18EA27637B07957D32F2BDE8706227D04665EC91BAF8B1AC3EC9144AB7F21";
andrewboyson 64:c736b8924574 63
andrewboyson 63:ae264156d655 64 char* m =
andrewboyson 63:ae264156d655 65 "0001FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
andrewboyson 63:ae264156d655 66 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
andrewboyson 63:ae264156d655 67 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00302130"
andrewboyson 63:ae264156d655 68 "0906052B0E03021A05000414A9993E364706816ABA3E25717850C26C9CD0D89D";
andrewboyson 49:9491c966dc60 69
andrewboyson 64:c736b8924574 70 uint32_t message [32];
andrewboyson 64:c736b8924574 71 uint32_t exponent[32];
andrewboyson 64:c736b8924574 72 uint32_t modulus [32];
andrewboyson 63:ae264156d655 73
andrewboyson 64:c736b8924574 74 BnParseHex1024(message, m);
andrewboyson 64:c736b8924574 75 BnParseHex1024(exponent, d);
andrewboyson 64:c736b8924574 76 BnParseHex1024(modulus, n);
andrewboyson 63:ae264156d655 77
andrewboyson 68:19c5efffc900 78 static int ticket = 0;
andrewboyson 63:ae264156d655 79
andrewboyson 63:ae264156d655 80 static bool started = false;
andrewboyson 63:ae264156d655 81 if (!started)
andrewboyson 63:ae264156d655 82 {
andrewboyson 68:19c5efffc900 83 ticket = BnExpModStart(message, exponent, modulus);
andrewboyson 63:ae264156d655 84 started = true;
andrewboyson 63:ae264156d655 85 }
andrewboyson 63:ae264156d655 86
andrewboyson 63:ae264156d655 87 HttpAddText("<code>");
andrewboyson 63:ae264156d655 88 HttpAddText("Message\r\n");
andrewboyson 64:c736b8924574 89 BnAsHttp1024(message);
andrewboyson 63:ae264156d655 90 HttpAddText("\r\nExponent\r\n");
andrewboyson 64:c736b8924574 91 BnAsHttp1024(exponent);
andrewboyson 63:ae264156d655 92 HttpAddText("\r\nModulus\r\n");
andrewboyson 64:c736b8924574 93 BnAsHttp1024(modulus);
andrewboyson 63:ae264156d655 94 HttpAddText("\r\nResult\r\n");
andrewboyson 68:19c5efffc900 95 if (ticket >= 0)
andrewboyson 63:ae264156d655 96 {
andrewboyson 68:19c5efffc900 97 switch(BnExpModStatus[ticket])
andrewboyson 68:19c5efffc900 98 {
andrewboyson 68:19c5efffc900 99 case BIGNUM_CALC_NONE:
andrewboyson 68:19c5efffc900 100 HttpAddText("Not started\r\n");
andrewboyson 68:19c5efffc900 101 break;
andrewboyson 68:19c5efffc900 102 case BIGNUM_CALC_STARTED:
andrewboyson 68:19c5efffc900 103 HttpAddF("Progress %d\r\n", BnExpModProgress[ticket]);
andrewboyson 68:19c5efffc900 104 BnAsHttp1024(BnExpModGetResult(ticket));
andrewboyson 68:19c5efffc900 105 break;
andrewboyson 68:19c5efffc900 106 case BIGNUM_CALC_FINISHED:
andrewboyson 68:19c5efffc900 107 HttpAddText("Finished\r\n");
andrewboyson 68:19c5efffc900 108 BnAsHttp1024(BnExpModGetResult(ticket));
andrewboyson 68:19c5efffc900 109 HttpAddF("Time to multiply %llu ms\r\n", BnMulHr[ticket] / 96000);
andrewboyson 68:19c5efffc900 110 HttpAddF("Time to modulus %llu ms\r\n", BnModHr[ticket] / 96000);
andrewboyson 68:19c5efffc900 111 break;
andrewboyson 68:19c5efffc900 112 }
andrewboyson 68:19c5efffc900 113 }
andrewboyson 68:19c5efffc900 114 else
andrewboyson 68:19c5efffc900 115 {
andrewboyson 68:19c5efffc900 116 HttpAddText("No ticket available to calculate result\r\n");
andrewboyson 63:ae264156d655 117 }
andrewboyson 63:ae264156d655 118 HttpAddText("</code>");
andrewboyson 63:ae264156d655 119
andrewboyson 63:ae264156d655 120 WebAddEnd();
andrewboyson 49:9491c966dc60 121 }