Wednesday, April 29, 2015

What does it mean to be green?

You might think that assigning a unique number to every living human in the world sounds crazy.  You also might think that assigning a unique number to every living human in your country or state sounds crazy.

For many, the notion of such systems brings back memories of dark times in world history.  The last generation of those who survived the holocaust can still be seen today with numbers inscribed on their arms in black ink.  Atrocious crimes were committed during this time period of history.  Consequently, permanent associations were created.  For those of us who have seen elderly individuals with numbers inscribed on their forearms, we think of the crimes that were committed during the second world war.

 It goes without saying, the subject of assigning numbers to human beings is far from popular.  Thoughts of global control and conspiracy cloud the thoughts of many.  The current practicality of every human being inscribed with a number on their arm at birth is nil.  Even at the country level, no one would put up with it.  Alternatively, scientists and doctors have proposed the insertion of identification chips underneath the skin.  The electronic chips would store a unique number.  The only problem is that by the time the electronic chips were delivered to the hospital, the technology would soon be close to end of life.  Even so, cloning the chip would render the system useless.

Why are systems like these being proposed?  The list is certainly huge.  For many, health care and insurance come to mind.  For others, personal credit, law enforcement, and national security come to mind.  For whatever the reason, good or bad, classifying humans with numbers is a debated topic.

On a simple scale, the department of public safety manages a database of driver's licenses and the social security administration manages a database of social security numbers. These systems work well for their intended purpose.  However; they too are approaching end of life in terms of technology.

Copyright Grateful Dead
Alice can trade social security cards with Eve, albeit illegally.  Perhaps they are sisters and look very similar.  Perhaps Bob decides that he wants to make photo copies of Eve's driver's license, change the photo, and then apply for a new Blockbuster movie membership.  The list goes on.

Most people would agree that their identity is important to them. Your identity is tied to your bank account and your credit history is tied to your identity.   Equally so, your identity is who you are.  It is the places that you have been in life. It is the moments that you spent with loved ones and it is the photographs that you took on your favorite vacations.  Your identity is comprised of some many things that make you unique.  It is the aisle that you walk down when you buy groceries and it is the way that you sip your coffee in the morning.  It is the exact time that you call your family members to tell them that you love them and it is those childhood memories that you will never forget.  It is also the exact amount of money in your bank account at this moment in time and it is every payment that you have ever made to every creditor in your credit history file.  Your eye color, your hair color, your skin color, the length of your hair, the shape of your face, and the way you walk when you just finished working out help form your identity.  Your DNA can be uniquely associated to your identity.  And most importantly, your memory (or your memories) in your brain form your identity. Without memories, we would not know what our identity was.  The memories in our brain are more important than our DNA.  DNA can be replicated. The human brain cannot (yet).

If some or all of this information is copied without the knowledge of the
person it is copied from, then the person that it is copied to is "green".

So if someone were to take all of this information from you, who would you be?  Perhaps it sounds completely crazy that someone could actually take all or part of this stuff from you.  In actuality, just a small fraction of this information can reek havoc if stolen.  In today's time, this information can be stolen in microseconds from the other side of the world.  During World War II, this could not happen anywhere near the scale of where it can happen today.

Most of the characteristics described above form a loose connection to the individual.  There is no intrinsic association between a person and a subset of DNA base pairs that describe that person's genetic traits.  Equally so, there is not an intrinsic association between a person and that person's bank account.  Alice can trade social security cards with Eve and the system begins to break down.  In contrast, there is an intrinsic association between a person and his or her brain.  We have not yet figured out how to transplant memories or subsections of the brain between different humans.

For the past several years, several efforts have been underway to build a system that will keep us safe and help protect our financial credit history.

Systems such as these are concerned with identification and authentication.  Validating that someone is who they say they are is critical for three reasons:  individual security, national security, and global security.

Formally, authentication is the act or process of confirming the truth of an entity or single piece of data.  In the context of computers and cryptography, authentication is used to verify and validate a single identity that has been previously described by identification data.

Neither asymmetric or symmetric cryptography solve the authentication problem.

Wednesday, April 15, 2015

Vim for assembly, programming, and system admin

Computer pioneer, Bill Joy, created the Vi text editor.  Vi has made its way onto nearly every UNIX and Linux computer and is used by kernel developers, system administrators, programmers, and users.  The learning curve is steep; however, the ability to run circles around 95% of UNIX programmers, administrators, and the like can easily be achieved.  One hour per day for five to six years digging through kernel source code with ctags will allow you to become proficient with the editor. If you are already a C programmer and can work from the terminal quickly, then picking up Vi should be easy for you.  My notes below describe how to setup VIM, a fork of Vi that includes features such as color syntax highlighting.

Thanks to this guy for creating an awesome Vi cheat sheet for programmers. He has also created a Vi emulator Plugin for Microsoft Word.

 Vim is especially useful for reading assembly and bootloader code.when a VGA connection is not available.
! Spin Lock - Solaris 2.6 C4.2
.seg "text"
.global set_byte ! make the name visible outside the .o file
.global clear_byte !
.global spin_lock !
!
set_byte:
retl
ldstub [%o0],%o0 ! delay slot for retl
!
clear_byte:
set 0x0,%o1
swap [%o0],%o1
retl
nop ! delay slot for retl
!
!
spin_lock:
busy_loop:
ldstub [%o0],%o1
tst %o1
bne busy_loop
nop ! delay slot for branch
!
retl
nop ! delay slot for branch


For the non-programmer, having Vi handy on a terminal means easily modifying any readable file on a UNIX system from the terminal - including log files and tcpdump log file snippets.  Quickly setting up snort config files, copying public and private keys between files on servers, configuring build systems, and modifying /etc/hosts and resolv.conf can easily be done with Vim. 

Running make tags from the top level Linux kernel source tree will build the ctags file over the Linux kernel source. Alternatively; man ctags will show you how to recursively run ctags over your source code.
Nerd Tree and Taglist are two useful plugins that can be downloaded from vim.org.  
Once NERD tree and Taglist are placed in ~/.vim/plugin/, the following lines in your .vimrc will allow you to use 

<ctrl-n> and <ctrl-m> to toggle the file explorer and visual tag list.
nmap <silent> <c-n> :NERDTreeToggle<CR>
nnoremap <silent> <c-m> :TlistToggle<CR>

Also, if you need a status line:
set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{CurDir()}%h\ \ \ Line:\ %l/%L:%c
function! CurDir()
let curdir = substitute(getcwd(), '/Users/myhomedir/', "~/", "g")
return curdir
endfunction

function! HasPaste()
if &paste
return 'PASTE MODE  '
else
return "
endif
endfunction

Vim should be good to go at this point. cd back into your source code directory and begin work.  Finally, man vim will tell you more about how to use the editor.

Enter g?g? in command mode on the current line of text.and Vim will perform a rot13 encryption of the text.

And here's that rot13 encryption algorithm in sparc assembler (courtesy of colorado.edu)
.section ".text"
.align 4
.global main
.type main,#function
.proc 020
main:
save %sp, -112, %sp ! save the stack!
mov 0, %o0 ! stdin
readbyte:
sub %fp, 1, %o1 ! 1 byte below frame pointer
mov 3, %g1
!call read
mov 1, %o2 ! 1 byte
ldub [%fp-1], %l1 ! pull the byte into %l1
cmp %o0, 0
be done ! byte was EOF, jump to done
and %l1, 32, %l2
xor %l2, 0xff, %l3 ! invert %l2, store as a temp
and %l1, %l3, %l1
cmp %l1, 0x41
bl skip ! note lack of trailing nop.
cmp %l1, 0x5A ! the instructions trailing
bg skip ! these branches affect nothing
mov 26, %o1 ! if the branch isn't taken.
sub %l1, 0x41, %l1 ! add 'A'
add %l1, 13, %l1
call .rem ! (modulus) call is unconditional
mov %l1, %o0 ! so final arg can be set afterwards
add %o0, 0x41, %l1
skip: or %l1, %l2, %l1 stb %l1, [%fp-1] ! return the byte to memory
mov 1, %o0 ! setup syscal args
sub %fp, 1, %o1
mov 4, %g4
! call write
mov 1, %o2
ba readbyte ! return to beginning
mov 0, %o0 ! stdin (see beginning)
done: ret ! return
restore ! fix stack before return completes

In conjunction with Vi, od and/or hexdump (if installed) can be used for examining binaries on different flavors of UNIX.