Tuesday, December 3, 2013

generate random number

use Linear_congruential_generator

http://en.wikipedia.org/wiki/Linear_congruential_generator

r = a X + c

X is the initail seed. we can use the TSC value for that. And we use the current random number to generate the next random number. The parameters of a and c are form:
Sourcem(multiplier) a   (increment) coutput bits of seed in rand() / Random(L)
Numerical Recipes23216645251013904223

Here is some code I wrote:

// Generate Random Number using Linear congruential generator
/*
#define MULTIPLIER 1664525
#define INCREMENT 1013904223

// save the seed in the SMRAM
// SMM_BASE + 0xFD00
unsigned int *saved_seed = (unsigned int*)(SMM_BASE + 0xFD00);

// Get a seed from tsc
//u32 initial_seed = (u32)(get_rdtsc() >> 32);
// *saved_seed = initial_seed;

u32 rand = 0xfff & (MULTIPLIER*(*saved_seed) + INCREMENT);
*saved_seed = rand;

// printk(BIOS_DEBUG,"rand is: %x\n", rand);
// the random number is resides in [1, 0xffff]

Monday, December 2, 2013

compile latex

two ways:
1. use pdflatex: compile latex to pdf
$latexpdf main.tex

this method does not work well with .eps images

2. use latex: compile latex to dvi; then use dvipdfm: compile dvi to pdf
$latex main.tex
$dvipdfm main.dvi

bibtex main.tex generates all of the .bbl. you can manually put it in the main.tex


sample Makefile for method 1
TARGETS = main

LATEX = pdflatex
BIBTEX = bibtex

all:    $(TARGETS) debug

$(TARGETS):
$(LATEX) $@
$(BIBTEX) $@ > $(BIBTEX)_out.log


debug:
-grep Warning *.log
clean:  

rm -f images/*.aux images/*~ images/*.log *.aux *.bbl *.blg *.log *.dvi *.bak *~ $(TARGETS:%=%.pdf)

sample Makefile for method 2
TARGETS = main

LATEX = latex
DVIPDFM = dvipdfm
BIBTEX = bibtex

all:    $(TARGETS) debug

$(TARGETS):
$(LATEX) $@
-$(BIBTEX) $@ > $(BIBTEX)_out.log
$(DVIPDFM) $@

debug:
-grep Warning *.log
clean:  

rm -f *.aux images/*.aux *.bbl *.blg *.log images/*.log *.dvi *.bak *~ $(TARGETS:%=%.pdf)





convert pdf to eps

$ pdftops -eps <pdf file> <eps file>

Friday, November 22, 2013

Set a static internal IP

1. find a hooked interface

2. make a script in /etc/sysconfig/network-scripts
For example:
$cd /etc/sysconfig/network-scripts
$touch ifcfg-em1
$vim ifcfg-em1

DEVICE=em1
HWADDR=A4:BA:DB:1A:AC:4F this is the mac address of the interface
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=192.168.0.27 this is the static IP you want to set
BROADCAST=192.168.0.255
NETMASK=255.255.255.0

NAME=em1

3. restart the device
$ ifdown em1
$ ifup em1

4. finally, check if the static ip has been assigned to interface em1
$ ifconfig

Check if the interface hook or not

$ yum install ethtool

$ ifconfig to see how may interfaces available

$ ethtool [Interface Name]

[root@sr2s7 home]# ethtool em1
Settings for em1:
        Supported ports: [ TP ]
        Supported link modes:   10baseT/Half 10baseT/Full 
                                100baseT/Half 100baseT/Full 
                                1000baseT/Full 
        Supported pause frame use: No
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full 
                                100baseT/Half 100baseT/Full 
                                1000baseT/Full 
        Advertised pause frame use: No
        Advertised auto-negotiation: Yes
        Speed: 1000Mb/s
        Duplex: Full
        Port: Twisted Pair
        PHYAD: 1
        Transceiver: internal
        Auto-negotiation: on
        MDI-X: Unknown
        Supports Wake-on: g
        Wake-on: d

        Link detected: yes Means the link is hooked.

mount NFS using /etc/fstab

First, you may need to authenticate the local machine to the NFS server.

Then,

Please add the following line to the end of your /etc/fstab:

NFS_SERVER:/vol/vol1_home    /home           nfs4    defaults        1 1

This is the format:
SERVERIP:REMOTE_FILE      LOCAL_FILE    FILE_FORMAT 


After this, do "mount -a" should get your home directory mounted.

Other commands about mount:
mount -a: mount all of the files in /etc/fstab
umount /home: unmount the local home direcotry from NFS server


Thursday, November 7, 2013

Good summary of SRTM and DRTM

http://security.hsr.ch/mse/projects/2011_Root_of_Trust_for_Measurement.pdf