summaryrefslogtreecommitdiffstats
path: root/movement/lib
diff options
context:
space:
mode:
authorJoey Castillo <joeycastillo@utexas.edu>2021-11-24 12:14:17 -0500
committerJoey Castillo <joeycastillo@utexas.edu>2021-11-24 12:14:17 -0500
commit3a420d5c6cfded6a04f4c78aa98c5d4ae7de8ca1 (patch)
tree1364472d05920d9bda9d8905201cf3e95cef148a /movement/lib
parent4a0ff5577363a1bd315693b41f448e3774de9e34 (diff)
downloadSensor-Watch-3a420d5c6cfded6a04f4c78aa98c5d4ae7de8ca1.tar.gz
Sensor-Watch-3a420d5c6cfded6a04f4c78aa98c5d4ae7de8ca1.tar.bz2
Sensor-Watch-3a420d5c6cfded6a04f4c78aa98c5d4ae7de8ca1.zip
add header guards, move declarations to source file
Diffstat (limited to 'movement/lib')
-rw-r--r--movement/lib/TOTP-MCU/TOTP.h5
-rw-r--r--movement/lib/TOTP-MCU/sha1.c16
-rw-r--r--movement/lib/TOTP-MCU/sha1.h19
3 files changed, 25 insertions, 15 deletions
diff --git a/movement/lib/TOTP-MCU/TOTP.h b/movement/lib/TOTP-MCU/TOTP.h
index 13715f4d..cfef38b1 100644
--- a/movement/lib/TOTP-MCU/TOTP.h
+++ b/movement/lib/TOTP-MCU/TOTP.h
@@ -1,3 +1,6 @@
+#ifndef TOTP_H_
+#define TOTP_H_
+
#include <inttypes.h>
#include "time.h"
@@ -6,3 +9,5 @@ void setTimezone(uint8_t timezone);
uint32_t getCodeFromTimestamp(uint32_t timeStamp);
uint32_t getCodeFromTimeStruct(struct tm time);
uint32_t getCodeFromSteps(uint32_t steps);
+
+#endif // TOTP_H_
diff --git a/movement/lib/TOTP-MCU/sha1.c b/movement/lib/TOTP-MCU/sha1.c
index 07ad697b..8e918e64 100644
--- a/movement/lib/TOTP-MCU/sha1.c
+++ b/movement/lib/TOTP-MCU/sha1.c
@@ -14,6 +14,20 @@ uint8_t sha1InitState[] = {
0xf0,0xe1,0xd2,0xc3 // H4
};
+union _buffer {
+ uint8_t b[BLOCK_LENGTH];
+ uint32_t w[BLOCK_LENGTH/4];
+} buffer;
+union _state {
+ uint8_t b[HASH_LENGTH];
+ uint32_t w[HASH_LENGTH/4];
+} state;
+
+uint8_t bufferOffset;
+uint32_t byteCount;
+uint8_t keyBuffer[BLOCK_LENGTH];
+uint8_t innerHash[HASH_LENGTH];
+
void init(void) {
memcpy(state.b,sha1InitState,HASH_LENGTH);
byteCount = 0;
@@ -84,7 +98,7 @@ void writeArray(uint8_t *buffer, uint8_t size){
}
void pad() {
- // Implement SHA-1 padding (fips180-2 5.1.1)
+ // Implement SHA-1 padding (fips180-2 ��5.1.1)
// Pad with 0x80 followed by 0x00 until the end of the block
addUncounted(0x80);
diff --git a/movement/lib/TOTP-MCU/sha1.h b/movement/lib/TOTP-MCU/sha1.h
index 2257e367..2db8fdf8 100644
--- a/movement/lib/TOTP-MCU/sha1.h
+++ b/movement/lib/TOTP-MCU/sha1.h
@@ -1,25 +1,16 @@
+#ifndef SHA1_H_
+#define SHA1_H_
+
#include <inttypes.h>
#define HASH_LENGTH 20
#define BLOCK_LENGTH 64
-union _buffer {
- uint8_t b[BLOCK_LENGTH];
- uint32_t w[BLOCK_LENGTH/4];
-} buffer;
-union _state {
- uint8_t b[HASH_LENGTH];
- uint32_t w[HASH_LENGTH/4];
-} state;
-
-uint8_t bufferOffset;
-uint32_t byteCount;
-uint8_t keyBuffer[BLOCK_LENGTH];
-uint8_t innerHash[HASH_LENGTH];
-
void init(void);
void initHmac(const uint8_t* secret, uint8_t secretLength);
uint8_t* result(void);
uint8_t* resultHmac(void);
void write(uint8_t);
void writeArray(uint8_t *buffer, uint8_t size);
+
+#endif // SHA1_H
0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/*
 * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
 *
 * 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 <http://www.gnu.org/licenses/>.
 */

package org.sufficientlysecure.keychain.ui.linked;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Patterns;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.EditText;

import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.linked.RawLinkedIdentity;
import org.sufficientlysecure.keychain.pgp.linked.resources.DnsResource;

public class LinkedIdCreateDnsStep1Fragment extends Fragment {

    LinkedIdWizard mLinkedIdWizard;

    EditText mEditDns;

    /**
     * Creates new instance of this fragment
     */
    public static LinkedIdCreateDnsStep1Fragment newInstance() {
        LinkedIdCreateDnsStep1Fragment frag = new LinkedIdCreateDnsStep1Fragment();

        Bundle args = new Bundle();
        frag.setArguments(args);

        return frag;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        mLinkedIdWizard = (LinkedIdWizard) getActivity();

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        final View view = inflater.inflate(R.layout.linked_create_dns_fragment_step1, container, false);

        view.findViewById(R.id.next_button).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                String uri = mEditDns.getText().toString();

                if (!checkUri(uri)) {
                    mEditDns.setError("Please enter a valid domain name!");
                    return;
                }

                String proofText = DnsResource.generateText(getActivity(),
                        mLinkedIdWizard.mFingerprint);

                LinkedIdCreateDnsStep2Fragment frag =
                        LinkedIdCreateDnsStep2Fragment.newInstance(uri, proofText);

                mLinkedIdWizard.loadFragment(null, frag, LinkedIdWizard.FRAG_ACTION_TO_RIGHT);

            }
        });

        view.findViewById(R.id.back_button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mLinkedIdWizard.loadFragment(null, null, LinkedIdWizard.FRAG_ACTION_TO_LEFT);
            }
        });

        mEditDns = (EditText) view.findViewById(R.id.linked_create_dns_domain);

        mEditDns.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                String uri = editable.toString();
                if (uri.length() > 0) {
                    if (checkUri(uri)) {
                        mEditDns.setCompoundDrawablesWithIntrinsicBounds(0, 0,
                                R.drawable.uid_mail_ok, 0);
                    } else {
                        mEditDns.setCompoundDrawablesWithIntrinsicBounds(0, 0,
                                R.drawable.uid_mail_bad, 0);
                    }
                } else {
                    // remove drawable if email is empty
                    mEditDns.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
                }
            }
        });

        mEditDns.setText("test.mugenguild.com");

        return view;
    }

    private static boolean checkUri(String uri) {
        return Patterns.DOMAIN_NAME.matcher(uri).matches();
    }

}