A framework for worst-case and stochastic safety verification using barrier certificates